CS 101 - MP 5: Hoppers

Due: April 11, 2002 at 11:59 pm

For this program, we will create another game. The game will consist of 25 locations that the "hopper" will hop around in. The user is to guess where the "hopper" will hop to next. The hopper moves around in a set pattern, although it may seem that it moves randomly. The real goal of the user is to determine the pattern the hopper is moving.

The layout is to show a grid of 5x5 buttons. The text displayed on the button is left up to the programmer, but the text must uniquely identify the button. As the hopper moves from button to button, the test of the button is to change to show where the hopper is.

The game is played by the user clicking on a button that the user thinks the hopper will hop to next. Once a button is clicked the hopper hops. If the user guesses the button correctly (i.e. the hopper hops to the button pressed by the user), an alert box is displayed stating the guess was correct.

The pattern by which the hopper moves consists of three things:

  1. A length of the pattern. This tells the number of different jumps the pattern contains.
  2. The distance for each jump in the pattern.
  3. An ordering of the 25 locations/buttons.
To understand how these are used, let us look at an example pattern:
  1. The pattern has length of 3.
  2. The pattern has 3 jumps of distance: 3, 17 and 6.
  3. The ordering of the 25 locations are:
    Order: 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
    Location: 1 3 5 7 9 11 13 15 17 19 21 23 25 2 4 6 8 10 12 14 16 18 20 22 24
The hopper would move as follows: Let us look at another pattern that is similar to the above pattern.
  1. The pattern has length of 3.
  2. The pattern has 3 jumps of distance: 3, 17 and 5.
  3. The ordering of the 25 locations are:
    Order: 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
    Location: 2 4 6 8 10 12 14 16 18 20 22 24 1 3 5 7 9 11 13 15 17 19 21 23 25

This game is to be player with 4 levels of difficulty. Your program is to use a selection box to allow the user to select the level of difficulty. The box must be initially selected to the second level of difficulty. When given a range of values, your program is to randomly choose a value in the range where each choice has an equal chance of being chosen.

  1. The first level of difficulty is the simpliest and will have the following restrictions on its pattern.
       The length of the pattern will be either 2 or 3.
       The distance of each jump will be from 0 to 10.
       The ordering of the locations will be in increasing numeric order.

  2. The second level of difficulty will have the following restrictions on its pattern.
       The length of the pattern will be from 2 to 6.
       The distance of each jump will be from 0 to 24.
       The ordering of the locations will be in increasing numeric order.

  3. The third level of difficulty will have the following restrictions on its pattern.
       The length of the pattern will be from 2 to 6.
       The distance of each jump will be from 0 to 24.
       The ordering of the locations will be in some pattern that is not in increasing numeric order. This ordering can be predetermined as long as there are at least 4 different orderings to choose from.

  4. The fourth level of difficulty is the hardest and will have the following restrictions on its pattern.
       The length of the pattern will be from 2 to 6.
       The distance of each jump will be from 0 to 24.
       The ordering of the locations will be in random numeric order.

When the program displays the alert box stating the player correctly guessed which location the hopper would go to next, include the number of incorrect guesses made since the last correct guess and the total number of guesses made with this pattern. This indicates the player has guessed one hop, but the player may not know the entire pattern. Once the user has made X consectutive correct guesses (where X is the length of the pattern), it can be determined that the player knows the entire pattern. The alert box should add additional text stating when X consectutive correct guesses are made.

Your program should add the following buttons:

Make sure your code is written using good programming style. This includes the use of comments, indentation, blank lines and meaningful identifier names. Each function that you write must have comments at the start explaining the purpose of the function. Also, at the top of your HTML file must have a comment explaining the purpose of the file including your name, and lab section day and time.

The program is to be submitted to the digital drop box for grading before the time the program is due.

Notes on the assignment and Academic Dishonesty

Since everyone in the class is creating the same program, each student must take reasonable steps to make sure their assignment is not copied. Recall that academic dishonesty includes supplying information as well as receiving information. Towards this end, you are not to have your assignment readable in your web directory or any subdirectory of a web directory (the WWW directory is the web directory on the CS machines, the public_html directory is the web directory on the icarus machines) until the day after the last due date for the assignment (Friday 4/12/2002). Any student who does not follow this will receive a grade of zero for the assignment.

In order to work on this assignment on a UNIX machine, you are to use the "Open File" option in the Netscape browser to view and run your assignment. Remember that this will only open a file on the physical machine that you are working with. If you are running Netscape on one of the EECS machines, you can open any file in your account (not only the ones in your WWW directory). If you are not running Netscape on one of the EECS machines, you will have to transfer the file to the machine your are working on before you can open the file in Netscape. To transfer the file, use either FTP or Fetch.

Another note on academic dishonesty, you should never show your written code for an assignment to another student. You may discuss ideas related to the project, but code must be entirely written on your own. If you and another student must discuss code, you must discuss an example other than the assignment.