So I am trying to make a Simon Says game where the user would have to repeat what the console has shown back to it. So for me so far I have made it work so that the characters have been showcased to the user and that each character is stored in a StringBuilder. I want to modify this code so that each character is only shown for a certain amount of time (maybe 0.6 seconds or 1 second etc), and then removed and the next character is shown etc during the for loop. I know Thread.sleep is used for the timing part, just the backspace/removal part I have no clue how to go around.
This is the piece of code I am stuck on and struggle to move forward from, I dont know what to add to the end of the for-loop. If needed, I'm using Eclipse
public static void gameStart() {
repeat.level++;//originally set to 0, now increments each time
StringBuilder sb = new StringBuilder();
sb.ensureCapacity(100);// plan to have 100 levels
for (int i = 0; i < repeat.level;i++) {
Random rnd = new Random();
char c = (char) ('a' + rnd.nextInt(26));//determines random char
System.out.println(c);//shows char to user
sb.append(c);//add to sb
}
System.out.println(sb);//just to make sure each char is getting added to sb
Actually, you can't remove the characters from the console, but you can play a trick. You can try this way in your for loop: