Re: 2D array of StringBuffer
That just gives you an array of arrays of elements that can hold a StringBuffer reference. Next you have to iterate over the elements, probably in a nested loop, and populate those array elements with StringBuffer instances.
db
Re: 2D array of StringBuffer
Quote:
Originally Posted by
DarrylBurke
That just gives you an array of arrays of elements that can hold a StringBuffer reference. Next you have to iterate over the elements, probably in a nested loop, and populate those array elements with StringBuffer instances.
db
So I think I created what you described above. Were should I declare it/write the code? I was thinking I should do it in main, but I'm not sure.
Re: 2D array of StringBuffer
Personally, since you're a beginner and doing things in an understandable way is preferable to help hone your skills, I would ditch the string buffer completely.
Make a 2D array of either Strings or chars that is the exact size of your game board, for instance 25x25.
Then you can keep track of character position just by knowing the x,y coordinate in the 2d array. Printing can be accomplished with a simple loop that goes row by row and collects all the chars or strings. In this way, moving a character from row to row only involves changing the value of two x,y coordinates. For example:
Code:
//Character is at (5,7), lets move him south 1 position
map[5][8] = map[5][7]; //Copy character to the tile directly south
map[5][7] = " "; //change the tile where the character was back to a blank space
This makes diagonal movement, collision detection, and animation MUCH simpler.