Creating a grid in Java

Hard to understand what you mean there because classes don't have return types.

Usually you would have 1 class in it's own file (there are, as always, exceptions to this rule). Without trying to patronise, I think you have 1 class with several methods in? Which is certainly one way of doing things but you lose all the benefits of OO design then.

I would have a separate class for Location and one for Grid (probably one to launch the program too), but without knowing the full context of the problem it is hard to say.


yes i have 1 class with lots of methods but would prefer to use lots of classes linked together

i'm just not sure how to link the classes together, i keep getting errors when i copy whatevers in a method to a new class...:(

gah i couldnt add one one you guys to msn could i?...:(
 
Feel free to post here if you're still stuck, the more eyes on a problem the better, don't worry about asking too many questions, I find it interesting solving different problems.
 
didnt add me to msn, however, a quick pointer: you cant just copy code from a method into a class - that code will have to go into a method within the class, if this method is public then it will be visible to the other class...
 
hey guys

im really having a lot of trouble with this, i probably should have done the easier java module :(

i need to allow the user to move the position of the player on the grid (letter P) using the keyboard, i have the keyboard class and presume i need to make the class recognise an ASCII input to change the co-ordinates of the player by 1 position left for example. would it use an if else statement to do the 4 directions?
 
hey guys

im really having a lot of trouble with this, i probably should have done the easier java module :(

i need to allow the user to move the position of the player on the grid (letter P) using the keyboard, i have the keyboard class and presume i need to make the class recognise an ASCII input to change the co-ordinates of the player by 1 position left for example. would it use an if else statement to do the 4 directions?

yes... or a switch statement. Im not sure what you have been taught so use whatever you feel more comfortable with.

Once you have found the location of the player you can just change the indices accordingly (you will have to take care if the player is on the edge of your grid)
 
If you want to keep things simple then you can simply use the WASD keys as directions because you can test for those keys slightly easier by doing a equals test. You could use an Scanner to capture the keyboard input then process the keys with an if/case block.
 
i have the keyboard class which i could use and just if ascii = whatever W is then move player 1 position up

it would be better off using the readChar part of the kb class than the readString yeah?
 
Back
Top Bottom