Question

In: Computer Science

Process: In this lab, you will be implementing a simple “Bop-it!”-like game. Your program will run...

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

  • Program prints a message telling the user to push a key to start the game.
  • Once in game, output tells the player which key to push. The key to press should be determined randomly.
  • Part 1:
    • Game runs continuously until the user reaches a loose condition.
      • A wrong key is pressed
  • Part 2:
    • Continuing on part 1, but instead of asking the user to push a certain key, print an ASCII table from A-z, and tell the user to press a certain ASCII value
    • For example, “push 97” **wait till a is pressed.
    • Make sure to layer the ASCII table nicely
  • Program waits for user action for less time after each iteration.
  • Program outputs how many successful actions the player executed at the end.

Questions:

  1. How did you randomize the keys that needed to be pressed?
  2. What game states, if any, did you keep track of?
  3. What mechanism did you use to make sure extraneous key presses were not registered?

Solutions

Expert Solution

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:

  • Starting of game
  • Time out
  • track of a previous time value and compare that to the newly scanned-in time
  • key presses are only registered once per press
  • successful actions the player executed at the end.
  • Ending of game

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.


Related Solutions

In this lab, you will practice the use of array by building an simple maze game,...
In this lab, you will practice the use of array by building an simple maze game, where your task is to control the prince to defeat the monster and save Snow White. You have to work based on the given skeleton code. Game Description The Snow White is detained in the maze by the monster, who needs the prince's help to rescure her out from the exit. The pre-set maze is shown below, with width 11 and height 8. The...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
** USING MATLAB TO PROGRAM The main objective of this lab is to create a game...
** USING MATLAB TO PROGRAM The main objective of this lab is to create a game that involves betting on the sum of two dice. The player will start out with some initial total amount of money. During each round, the player can bet some money that the sum of the two dice will be equal to a certain number. If the player wins the bet, that player adds the amount of the bet to his or her current total....
Lab 11 C++ Download the attached program and run it - as is. It will prompt...
Lab 11 C++ Download the attached program and run it - as is. It will prompt for a Fibonacci number then calculate the result using a recursive algorithm. Enter a number less then 40 unless you want to wait for a very long time. Find a number that takes between 10 and 20 seconds. (10,000 - 20,000 milliseconds). Modify the program to use the static array of values to "remember" previous results. Then when the function is called again with...
Create a simple dice game in Java. Add screenshots and the program here.
Create a simple dice game in Java. Add screenshots and the program here.
Write a code for simple racing game (using dots) on c program.
Write a code for simple racing game (using dots) on c program.
1. Write a program that plays a simple dice game between the computer and the user....
1. Write a program that plays a simple dice game between the computer and the user. When the program runs, it asks the user to input an even number in the interval [2..12], the number of plays. Display a prompt and read the input into a variable called ‘plays’ using input validation. Your code must ensure that the input always ends up being valid, i.e. even and in [2..12]. 2. A loop then repeats for ‘plays’ iterations. Do the following...
UNIX/LINUX LAB (1) Review the sample shell program (tryShell.c), and compile/run the program (tryShell) with the...
UNIX/LINUX LAB (1) Review the sample shell program (tryShell.c), and compile/run the program (tryShell) with the following commands, and at the end, use CTRL+C to terminate the program: ls ls -l tryShell* date whoami hostname uname -a ctrl+C    (2) Run the program (tryShell) with "time -p" with a few commands: time -p ./tryShell (3) Edit the program (tryShell.c) so that it will exit (terminate the program) when the input command string is "exit" try shell.c code at bottom //////////// #include...
Lab 1 Write a C program for a grade calculation to run on ocelot. The source...
Lab 1 Write a C program for a grade calculation to run on ocelot. The source file should have your name & PantherID included in it and it should have an affirmation of originality stating something like: “I affirm that I wrote this program myself without any help form any other people or sources from the internet.”. Code should be nicely indented using a consistent style and commented appropriately. An array should be used for each student, but it is...
Design a basic game like brick breaker, space shooter, or chess that is run on openframeworks...
Design a basic game like brick breaker, space shooter, or chess that is run on openframeworks in c or c++ language. It can be any game
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT