Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Diametunim
Oct 26, 2010
I'm in need of a little java help for school. We're currently working on Programming Othello/Reversi whatever the gently caress you choose to call it by using recursion. Now I've gotten mine to work for the most part however the left column and bottom row aren't playable because my recursion decides to check out of bounds and eclipse returns an error. I haven't for the life of me a clue on how to fix it.

My other problem is that we're required to have some form of A.I to play against. It doesn't have to be smart but I haven't a clue on how to program any form of A.I and our teacher for the class didn't teach us how to do it either. So I'm coming to the goons for help.

Anyways, Here's my recursion for checking to the left it works for every column besides the last one.

Obuttons being the name for my game board array, everything else should be somewhat self explanatory?

code:
if(Obuttons[clicked.getColumn()-1][clicked.getRow()].getIcon()==different)
					{
						System.out.println("THERE ARE DROIDS TO THE LEFT PEWPEWPEW");
						if(cLeft(Obuttons[clicked.getColumn()-1][clicked.getRow()]))
						{
							System.out.println("You sir, have a valid move to the left");
							fLeft(Obuttons[clicked.getColumn()][clicked.getRow()]);
							Turn = 1;
							whoisturn.setText("Turn: Droid");
							whoisturn.setBorder(null);
						}
					}
Here is my recursion for checking down
code:
					if(Obuttons[clicked.getColumn()][clicked.getRow()+1].getIcon()==different)
					{
						System.out.println("DROIDS BELOW YOU! OMGOMGOMG");
						if(cDown(Obuttons[clicked.getColumn()][clicked.getRow()+1]))
						{
							fDown(Obuttons[clicked.getColumn()][clicked.getRow()]);
							System.out.println("You sir, have a valid move below you, or something like that.");
							Turn = 1;
							whoisturn.setText("Turn: Droid");
							whoisturn.setBorder(null);
						}
					}
and lastly here is the error thrown to me by eclipse if you click on the last left column or the very bottom row.
code:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
	at Othello.mouseClicked(Othello.java:166)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
If you need to see some other part of my code let me know and I'll paste it up.

Adbot
ADBOT LOVES YOU

Diametunim
Oct 26, 2010

_aaron posted:

I'm not sure what your fleft method does, but you pass the value at the actual clicked row and column to that method, but when you do if check for different, you're using the column - 1 (or the row + 1). I'm obviously not familiar with the rest of your code, but my guess is that clicking the far left column gives you a column value of 0; when you subtract 1 from this, you get -1, and that's not a valid array index, hence your exception. Same thing for the bottom row - adding 1 will put you outside the bounds of the array.

If that's not correct, I'd need to see some more code.
Sorry about that, I posed the wrong method. fleft however flips the pieces when a move is made. I actually solved the problem by throwing in this little line here before each of my check statements
code:
if(clicked.getRow/Column +1/-1 <8) 
Where Row/Column is either the Row or Column depending on what method I was editing and the same goes for the +1/-1 and the <8 just tells the program to stop at the 8th row/column.

I think? I hope I'm explaining that right. But I solved my problem.

Thanks for your help.

Diametunim
Oct 26, 2010
I was wondering if anyone could help me out here, I'm currently in a high school computer science 2 class and our current project (and final for the year)is as a class we're writing super smash brothers as a class (teacher included). The only real requirements is that every piece of code besides the engine must be written from scratch. Here lies our problem, none of my classmates (There's 7 of us) except for one guy knows jack poo poo about writing a physics engine. That one guy however also has to handle all of the networking code because he is the only one in the class that knows anything about networking as well. Most of us all feel that it's not exactly fair or going to be efficant for him to be writing the two most important parts of the code.

My question is does anyone know any opensource 2D physics engines that are relatively good and easy to understand? I've stumbled around trying to look for a decent one and came across Phys2D as well as JBullet. The problem is our teacher doesn't like the idea of using JBullet (or couldn't understand the code) so we're back at square one.

So to make this short and simple, does anyone know a decent opensource 2D physics engine that would be acceptable for writing a java version of Super Smash Brothers? keep in mind this doesn't have to be perfect we're a bunch of worthless highschool students.

Diametunim
Oct 26, 2010
Thanks for the help guys, I really appreciate it. We were looking at using an open source engine just for the purpose of saving time since we only have about 7 weeks to write everything else. However three of us just ended up getting together and writing our own. So far we have friction, gravity and jumping and all of our characters are going to inherit or be based off a basic rectangle (am I saying that right?)

On a completely unrelated note from this project, 7 years ago or so my computer science teacher had the class at the time write their own version of Legend of Zelda. The class never got very far other than creating a basic dungeon you could walk through that had a short midi sound file playing in the background. You could "attack" but you wouldn't do any damage and there was only one little enemy that didn't attack you but he also couldn't be killed.

The weird issue is and it's an issue we believe with how the sound threading was coded? (I'm trying to explain things that are over my head again) however when the midi file for the dungeon sound ends the program closes and no one can figure out why the hell this happens.

anyone have any ideas on what the problem could be? like I said it was coded by the kids who took his class 7 years ago so other than having the code I really don't know anything about how it was written.

again, thanks for the help guys.

Diametunim
Oct 26, 2010
I was wondering if anyone could recommended me some good Java books to sharpen my skills with. I find myself having to refer back to old code that I've written previously to remember how to do the easiest of things and it's really getting old, especially since I plan on majoring in computer science when I go off to college. The only book I have right now (and I can't even find it) is the standard computer science book written by Leon Schram that was given to me when I started Computer Science 1 two years ago.

Diametunim
Oct 26, 2010

MariusMcG posted:

Well, it depends on what you're looking to do with Java. I personally love Effective Java, but that's more of a general book. You might prefer to read about a specific Java technology in a recipe-style book, like Spring Recipes.

Thanks, I'm definitely looking for a more general Java book right now to refresh the skills that I already know. The most complicated thing I've ever put my head into was advanced swing menus. The most complicated thing I've ever written was a simple version of battleship and even that didn't work correctly so I'm definitely still looking for more basic (or what I consider to be basic?) books.

Internet Janitor posted:

Java Puzzlers is also a great way to learn more about the language, attacking the issue from a different angle. The book's site has some pretty intriguing samples to try out if you think you might be interested. This book might not teach you everything you want to know, but it will expose gaps in your understanding and push you to seek out more information.
Thanks, I'll definitely look into those. I've been meaning to post the pastebin links for the Zelda code I asked about I just haven't had time, but here they are.

Sound
Sound 2
Loop Sound

Adbot
ADBOT LOVES YOU

Diametunim
Oct 26, 2010
Sound...How the gently caress do I make sound work? :suicide:

Sigh, I wish that's all I had to post. To elaborate I'm a fairly beginner (or what I believe to be beginner) programmer so bare with me. I'm currently working on a Super Smash Brothers project in CS 2 class (High school) and It's my job to get sound working. Problem is, I know nothing about threading or Java's sound API's. Can anyone recommend me a good book i can go buy or a tutorial I can follow on getting sound to play?

I know it's not really a simple process but I'm trying to start simple. All I'm looking to do right now is get a simple 1 minute song to play on our splash screen and loop and continue looping until the user presses enter and moves to the mode selection screen. The clip I'm trying to use is an mp3 that I pulled from youtube, I'm not sure if java can use mp3's? if not what file format do they need to be in? midi, wav's? Feel free to call me retarded if I'm not making any sense at all.

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply