I have a map class, which is an Array of 100 Strings
public class map{
[...]
public void movePlayer(String entrada){
if (entrada.equalsIgnoreCase("w")){
move = -10;
}
else if (entrada.equalsIgnoreCase("s")){
move = 10;
}
else if (entrada.equalsIgnoreCase("d")){
move = 1;
}
else if (entrada.equalsIgnoreCase("a")){
move = -1;
}
for(int i = 0; i < mapa.length; i++){
if (mapa[i].equals("P")){
int moved = i+move;
mapa[moved] = "P";
}
}
}
The main looks a little like this
String[] mapa = map.getMap();
mapa[0] = "T";
mapa[99] = "P";
for (int j = 0; j<10; j++){
for(int i = 0; i < map.length; i++){
if (i == 9 || i == 19 || i == 29 || i == 39 || i == 49 || i == 59 || i == 69 || i == 79 || i == 89 || i == 99){
System.out.println(mapa[i]);
}
else{
System.out.print(mapa[i]);
}
}
System.out.print("\n");
System.out.print("Entre o movimento:");
map.movePlayer(read.nextLine());
mapa = map.getMap();
}
It runs like this: A map with random chars are printed, some are normal floors some are traps EXAMPLE
T##_______
^__@__*^@_
@#^^#_#___
_*^^^#^^@^
^^_#_^____
^#_^#___##
*@^_^_____
^@##_^__^#
#_@^##^#**
#@^^_#@_#P
Enter movement:w
T##_______
^__@__*^@_
@#^^#_#___
_*^^^#^^@^
^^_#_^____
^#_^#___##
*@^_^_____
^@##_^__^#
#_@^##^#*P
#@^^_#@_#P
Enter movement: w
T##_______
^__@__*^@_
@#^^#_#___
_*^^^#^^@^
^^_#_^____
^#_^#___##
*@^_^_____
^@##_^__^P
#_@^##^#*P
#@^^_#@_#P
How can I make the program to print the place where the Player originally was with the previous char it had, in this case a blank space in position [99] and a "*" in position [89]? Thanks for the patience!