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:
- A length of the pattern. This tells the number of different jumps the pattern contains.
- The distance for each jump in the pattern.
- An ordering of the 25 locations/buttons.
To understand how these are used, let us look at an example pattern:
- The pattern has length of 3.
- The pattern has 3 jumps of distance: 3, 17 and 6.
- 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:
- The hopper would start at location 1. Location 1 is the first position in the ordering.
- The hopper would then jump to location 7. Location 7 the fourth position in the ordering.
The first jump is a distance of 3 and by adding 3 to the current position in the ordering
(which is 1), we get to the fourth position in the ordering.
- The hopper would then jump to location 16. Location 16 is the twenty-first position in
the ordering. This jump uses the distance of 17. By adding 17 to the current position in
the ordering (which is 4), we get the twenty-first position in the ordering.
- The hopper whould then jump to location 3. Location 3 is the second position in the
ordering. This jump uses the distance of 6. By adding 6 to the current position in the
ordering (which is 21), we get the twenty-seventh position; however, since there are only
25 positions, we must subtract 25 from 27 to get 2. Location 3 is the second position in the
ordering.
- The pattern then repeats itself for the next jump of distance 3, then another jump of
distance 17, then another jump of distance 6, then another jump of distance 3, etc.
-
The first ten jumps using this pattern are as follows. Jump 0 is the initial location
of the hopper.
Jump:
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
|
---|
Location:
| 1 | 7 | 16 | 3 | 9 | 18 | 5 | 11 | 20 | 7 | 22
|
Let us look at another pattern that is similar to the above pattern.
- The pattern has length of 3.
- The pattern has 3 jumps of distance: 3, 17 and 5.
- 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
|
---|
-
The first ten jumps using this pattern are as follows. Jump 0 is the initial location
of the hopper.
Jump:
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
|
---|
Location:
| 2 | 8 | 17 | 2 | 8 | 17 | 2 | 8 | 17 | 2 | 8
|
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.
- 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.
- 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.
- 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.
- 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:
- An Abbout button. This button should cause information about the programmer
to be displayed.
- A Rules button. This button is to give additional information about the
game that is not included on the main page.
- A New Pattern button. This button is to create a new pattern based on the
selected level of difficulty. This button is to also reset the number of total guesses,
incorrect guesses and number of consectutive correct guesses to zero.
- A Reset Number of Guesses button. This button is rest the number of
total guesses, the number of incorrect guesses and the number of consectutuve correct
guesses to zero.
- Three hint/cheat buttons:
- A Pattern Length hint/cheat button. This button is to display the length
of the current pattern.
- A Jump Distance hint/cheat button. This button is to display the distances
for all jumps in the pattern.
- A Location Order hint/cheat button. This button is to display the ordering of the
locations in the pattern.
For 5 points extra credit: when the alert box is displayed showing a correct guess,
include a statement if the hint/cheat buttons have been used since the last time the
New Pattern or Reset Number of Guesses buttons have been clicked.
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.