EDIT: Rewrote most of this post because I figured parts of my question(s) out.
Hello, I'm in a beginning
Java class and on my own time am trying to make a little dungeon-exploring-rpg type of game using what I've learned so far to help cement my understanding.
Basically the player moves around a 10x10 grid and different things happen as the player moves onto the various 'spaces'.
So that the player can keep track of where they currently are on the grid, I want to display a 'map' after each time the player moves. I will keep track of the player's location on the grid using height and width (of the grid) variables. Different spaces on the grid will be represented by different symbols.
For example: 'X' is where the player currently is, 'S' is where the store is, 'B' is where a boss is, '*' is an open space, etc. The spaces will be static except that where the player is currently located will be a 'X' instead of whatever else was there before (once the character moves to another space the original space will revert back to what is was before).
I started playing with the idea of just making the array chars (This example is just set up for a 3x3 grid since I'm trying to figure out what I'm doing first before diving in.
Something like this (the chars don't mean anything in particular right now):
Which prints out:
S*?
**B
**d
I would then need to replace one of those chars with a X to represent the player. I'm not really sure what would be the best way to implement that though. Store the location of the player on a coordinate grid and map each coordinate to an array element? So that if the player is on (0,2), assuming they started at (0,0) and moved right twice, that means they are at map[2] (which is a '?' in the above example) and it would temporarily be changed to a char of 'X' until the player moves again. So would it be feasible to do something along the lines of (this is just an example to how how it would work):
height=0
width=0
player moves right
width=width+1
if (height==0 && width==1)
player encounters stuff that I have set up for grid space (0,1)
and
tempSpace = map[1]
map[1] = 'X'
print out 'map'
player moved down
height=height+1
if (height==1 && width==1)
player encounters stuff that I have set up for grid space (1,1)
and
tempSpace2 = map[5]
map[1] = tempSpace
map[5] = 'X'
print out 'map'
And so on. There would have to be if statements for every possible combination of of height and width (all of the different grid spaces) each time the player moved. Would this be a decent way of doing this? Or would using an array of integers be better for some reason? Maybe set every element of the array equal to some number and have if statements while printing out the map that turn numbers into the desired symbol?
Anyway, sorry for the ramble...if you were brave enough to read all of this I would appreciate any insight or suggestions. Just trying to figure out the right/best way to do stuff. Note: Remember I'm basically a Java 101 knowledge-level. I've learned about loops, methods, classes, and am just getting into arrays. I don't know much advanced/fancy stuff yet so relatively simple is better.
Thanks much for the help.