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...
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...
Create a program named CmdLineCalc.java that works like a simple calculator. You'll run this program from...
Create a program named CmdLineCalc.java that works like a simple calculator. You'll run this program from the command line: $ java CmdLineCalc 1 + 2 3.0 $ java CmdLineCalc 1 - 2.5 -1.5 $ java CmdLineCalc 3 + 4 - 5 2.0 $ java CmdLineCalc 6.5 - 7 + 8 7.5 To keep it simple, your program only needs to support addition (+) and subtraction (-). You may assume that, starting with the first argument, every other argument will be...
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...
. In this lab you will be making a text-based calendar program that looks like: JANUARY...
. In this lab you will be making a text-based calendar program that looks like: JANUARY 2018 S M Tu W Th F S 1 2 3 4 5 6    7 8 9 10 11 12 13 14 15 16 17 18 19 20    21 22 23 24 25 26 27 28 29 30 31 Your calendar should be able to print months in the future and in the past. Activity #1 In C++ create a calendar program...
** 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....
Create Lab project Add the following codes to your main method. Compile and run the program...
Create Lab project Add the following codes to your main method. Compile and run the program with some arguments and observe the output.       printf("You have entered %d arguments.\n", argc);       for (int i = 0; i < argc; ++i)         printf( "argument %d: %s\n",i+1,argv[i]); Create a function called simpleFileWrite() and add the following feature: Open a write only file called “myfile.txt” and write characters into it. The set of characters are read form the keyboard until cntrl-z is entered. (use...
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...
I am trying to write a simple game in Java named GuessNumber.java to run on the...
I am trying to write a simple game in Java named GuessNumber.java to run on the command line. This program asks user to pick a number and the computer guesses the number repetitively until the guess is correct and will allow the user to set the lower and upper bound as command line parameters from where the picks the number. If no command line parameters are specified then the program uses a default of 1 to 99.
Maze in C++ Simple Maze Program – Project Specifications: 1. Create a simple maze game that...
Maze in C++ Simple Maze Program – Project Specifications: 1. Create a simple maze game that a player must traverse to win. 3. The maze must be text-based and adjustable from 5x5 to 20x20. • Player gets to choose size either as: 1) any size in the range from 5-20 by 5-20. 2) selects from 4 set size options [5x5,10x10,15x15, and 20x20] • the player can choose among different mazes. • You will need to figure out how to denote...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT