Don't use arrays for this stuff, use collections like List, which will let you do far more than arrays. If you need an extra dimension, use a List of Lists, and also look at things like Map while you're at it.
Arrays do have their uses, but not in a text-based game.
Actually, i think what they mean is that they want to make a text based roguelike, which usually IS made with 2d arrays (or 2d char arrays, at least). i think that the confusion is because there is also the old fashioned text based RPG games where it's just dialogue and you loosing hp. usually roguelike games have maps that look almost EXACTLY like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
| ########################## ## G ############ ######## ## ##M M## ###### ## ## ## ###### ## ## M############ ############ ## ###################### ## ## #### ## ## ###### #### #### ## ## ## M## #### ## ##C ## ## ## ## ###################### |
Okay sorry that the question is so confusing. I'm just really unsure and confused myself.
My Room object repersents whats inside the current room ie. enemies to encounter, and items to find, I'm also considering it holding events but this isn't implmented yet.
I then have another object called -_- locationObject which holds an arraylist of the rooms.
current progrssion in the game is done by adding(or subtracting) one to a variable called currentRoom and then getting the object at the index inside the arraylist in the location object.
I realize 2D arrays can be done with things like String[][] however I'm unsure how to use it to create a map that the player can move around in beyound going back and forth.
When I say lacking depth I'm refering to the fact you can only go from room 1, to room 2, to room3, and back they is no left or west and east from currentRoom.
I have atleast a basic understanding of java.
I'm unsure where the problem is in my logic. Again thank-you for your help.
you need to set 2 variables. have 1 stand for the characters y position, and 1 for the x position.
now do something like this (note that this is not an actual code, it's just an outline of what you need to do):
1 2 3 4 5 6
| if buttonup true: check if maparray[x][y+1] has something in it(should return a true or false) if false: maparray[x][y] = blank space; y++; maparray[x][y] = character symble; |
basically, you need to do that for each direction. (if down it should be y-1 and y--, if left it should be x-1 and x--, and if right it should be x +1 and x++)
there you go, you now have your character and map working together in perfect harmony. now you basically have to do the same for each mob, (basically, it's a for loop that checks if the slot is taken up by a mob, if it is, then an if statement to see if the player is near by, then if the player IS then you need to do the attack. if it's not, then either randomly move 1 (again, check if the mob can actually move).
basically, that's it. it's really easy and it's also the 'begginers programming to rpgs'. there are actually a LOT of online tutorials that will tell you how to code every single line. though not all use 2d arrays or 2d char arrays. anyway, here is one of the youtube tutorials i found in my favs, (though i have no idea if it uses arrays or not):
http://www.youtube.com/playlist?list=PLB062D4D37FECD5A6