This will set up a console that has different states based on what the user enters. For now I just have the ability to go up ("w") or go down ("s")
public static void main(String[] args) {
HashMap<Integer, HashMap<String, String>> consoleStates = CreateConsoleStates();
String input = "default";
Scanner userInput = new Scanner(System.in);
do {
//draw default state of board
if(input.equals("default") || input.equals("w") || input.equals("s"))
printConsole(input, consoleStates);
//get input from user until they exit
input = userInput.nextLine().replaceAll("\n", "");
} while (!input.equals("exit"));
}//main method
public static HashMap<Integer, HashMap<String, String>> CreateConsoleStates()
{
HashMap<Integer, HashMap<String, String>> consoleStates = new HashMap<>();
HashMap<String, String> line1, line2, line3;
line1 = new HashMap<>();
line1.put("default", "00000");
line1.put("w", "00000");
line1.put("s", "00 00");
line2 = new HashMap<>();
line2.put("default", "0 0");
line2.put("w", "00 00");
line2.put("s", "00 00");
line3 = new HashMap<>();
line3.put("default", "00000");
line3.put("w", "00 00");
line3.put("s", "00000");
consoleStates.put(1, line1);
consoleStates.put(2, line2);
consoleStates.put(3, line3);
return consoleStates;
}
public static void printConsole(String state, HashMap<Integer, HashMap<String, String>> consoleStates)
{
//adding this will make it seem like a brand new console as suggested in another answer
//System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
//each number corresponds to the line in the console
System.out.println(consoleStates.get(1).get(state));
System.out.println(consoleStates.get(2).get(state));
System.out.println(consoleStates.get(3).get(state));
}
}
Output looks like:
00000
0 0
00000
s
00 00
00 00
00000
w
00000
00 00
00 00
e
00000
0 0
00000
exit
Note: that I'm using the standard wsad controls that most games have. I recommend it. w for up, a for left, s for down and d for right. Also i display the default state whenever an incorrect key is pressed and "exit" is used to exit the game.