In: Computer Science
Process:
In this lab, you will be implementing a simple “Bop-it!”-like game. Your program will run for a single game. Start with implementing a “start menu”, output a line asking the user to push a keyboard key to start and wait for the user to push a key.
The game will involve printing a line telling the user which key to press (chosen randomly by the program) and will wait a certain time for a response. After each successful action by the player the time the program will wait for a response will reduce. The game ends when the player does the wrong action or time runs out, (finding time passed may not be as easy as you think, hint: you may want to keep track of a previous time value and compare that to the newly scanned-in time).
Note: You should ensure that key presses are only registered once per press.
Requirements
Questions:
1. Randomizing the keys that need to be pressed.
Answer. I would just generate a random number between 33 and 126. Then every couple of char's randomly add a 32. 32 is a space. 65 - 90 are upper case, and 97-122 are lower case.
code to generate a Random number:
Random randomGenerator = new Random();
int ran = randomGenerator.nextInt(126 - 33);
ran += 33;
Then ran would be your random character. You could have a loop and do that a couple of times.
You don't even need to use KeyEvent.VK_SPACE. You will get a return of "32". That corresponds to the ASCII chart, just use that If you use:
System.out.println(KeyEvent.VK_SPACE);
2. The Game states that needs to be saved are Following:
3. mechanism used to make sure extraneous key presses were not registered is that we can simply store the extraneous keys in an array and put a condition on the key entered is that if it got the keys which belongs to this array pops a message that "extraneous key entered" if not then it can simply allow to press the key.