Project #4 - TurnRed Game - 13%
due by midnight, M Jun 18Please observe
good coding style.
Deduction for lateness is 10% per day for 5 days, then no credit.
Start early!
version 1.0
, last updated
06/13/2007 |
GRADING CRITERION:
- 85% correct execution
- 15% coding practices (maintainability etc.)
Using Java, please complete the TurnRed
game using this starter code as your initial project in Eclipse.
Here is a working prototype that you can play to become familiar with the
game (download the .jar file and click it to run the prototype).
NOTE: This executable, being a prototype, has not been properly stress-tested,
and I don't promise that it won't break or that it implements all features you
are asked to implement.
Please download my starter code and import it into Eclipse (for
how to import a project, go to the bottom of the
Eclipse FAQ). Before beginning this project, please make sure you
understand the starter code--we have
developed most of the starter code in class, calling it GridButton at that time. You do not have to understand
the panels or menus, except for how to enable and disable the Undo menu
(shown below).
DOCUMENTATION FOR THE STARTER CODE:
In the starter code, two methods in the Model class (gettState() and
setState()) can be used to learn the game state and change it.
Legal value for the state are Model.INGAME, Model.POSTGAME,
Model.PREGAME, and Model.REDOINGGAME. Please use these methods
and values to track state in your game. The possible game states are:

The MainForm.toggleWithNeighbors() method should be called by the GameButton
click handler when the game is in progress, or when setting up for a new
game. This method will toggle the specified button as well as its
neighbors. It calls, in turn, the getNorth(), getEast(),
getSouth() and getWest() methods to reach the neighbor buttons.
The GameButton has been enhanced with the isOn() method that returns true if
the color is "on" (blue) or false if the color is "off" (red). You can use
this when determining whether all squares are red (checking whether the game has
been won or not).
The file MainForm.java, the Undo menu can be enabled with "undoMenuItem.setEnabled(true);"
or disabled with "undoMenuItem.setEnabled(true);". A showMoves()
method has been provided to update the move count shown in the status bar.
Near the top of the MainForm.java file, a
move counter, a stack, and a random number generator have been declared for you.
Please use them. They are called movecount, myStack, and myRandom,
respectively. They are instantiated and initialized in run() before the
form is displayed.
METHODS YOU MUST COMPLETE:
- In file MainForm.java, complete the getEast(), getSouth() and
getWest() methods. getNorth() is done and you can use it as
a guide for the others.
- In file MainForm.java, complete the areAllOff() method using the
instructions shown in its comments.. This method
must return true if all squares are red (when the game has been won).
The GameButton has been enhanced with the isOn() method that returns
true if the color is "on" (blue) or false if the color is "off" (red).
You can use isOn() while looping through all the buttons to see what
color they are.
- In file MainForm.java file, complete the
Model.INGAME case within the switch
statement of the GameButtonListener using the instructions shown in its
comments.. NOTE: In all the
other game states, the GameButtonListener takes no action if a GameButton is
clicked.
- In the MainForm.java file, complete the
ButtonNewGameListener class using
the instructions shown in its comments. It's actionPerformed() method must use a random
number generator to select 17 indices from the myButtonCollection, retrieve
those buttons, and make a game move for each button.
- In the MainForm.java file, and in the MenuListener inner class, complete
the part for the Undo menu (within the "if (menuName == strUndo)" clause)
using the instructions shown in its comments.
- Please place your name in file AboutForm.java
in the indicated string so that you name is displayed in the program's About
form.
GAME SPECIFICATION :
(for your reference only--you probably won't need this, since you are not
starting from scratch but are using my starter code instead):
- The puzzle uses a 10 by 10 grid:
- Clicking a button causes that button to toggle colors, as
well as the four adjacent buttons (above, below, right and left). If the
clicked button is at the edge, there is no wrap-around. The player's
goal is to
turn all squares red.
- Each button click
increments the count of moves.
- The game should tell you when you've won and should display how many moves were used
to win. It should use the caption area below the grid to do this. After winning and
before clicking "New Game", buttons in the grid should not toggle, and the
caption background color should be yellow (or some brighter color than usual).
It's normal gray color then should be restored when a new game starts.
- STARTING A GAME: To set up for a "New Game", first set
the entire grid to red, and then simulate a number
of randomly-selected game moves. The more random game-clicks you make to
start the game, the harder the puzzle is likely to be to solve.
Please use exactly 17 clicks to start the game for the 10x10 grid.
|
NOTE:
The random game-clicks do the same thing during
game setup as during the game--they toggle the chosen button and its
neighbors. If you just toggle each button's color but not the neighbors, you
risk ending up with an unwinnable game. |
- When creating a new game configuration randomly, it is possible that the
result will be an all-red grid; please detect this and repeat the set of
random clicks until at least one square is not red.
- Please implement an Undo function that can retract moves all
the way back to move 0, if desired. Please use a Stack object
to store button presses to facilitate undoing of moves later.
Each Undo menu click should decrement the count of moves and back the
game up to where it was one move earlier. NOTE: If you click the same
button twice in a row, the second click reverses the effects of the first
click.
- Disable the Undo menu when there are no moves to undo, or when a
game has been won.
- At a single place in your code, you should be able to specify button
size, number of rows, and number of columns for both grid sizes. Your
program should adapt the form size if those values are changed. This
means you must place the buttons on the form in a loop.
- Please change the About windows to display your name instead of
mine.
- Please do not change any features of the game, including
the exact wording of menus or names of things.
GETTING HELP:
If you need help, try (in preferred order):
- posting to the Discussion Group in Blackboard
- call or find me or a TA
- send email (last resort)
TURN-IN:
The turn-in procedure for programming assignments is as follows:
- Create a folder with your emailID as its name. The folder
I would create would be pgpalmer; yours will be different.
- Copy your entire Java project folder, and all related files, into
this folder.
- Zip up the entire folder, including all files
underneath the folder. NOTE: Please do not use the "save full path info" option.
Test unarchiving the zip file to make sure it produces all your files and
directories, but in whatever folder the person unzipping chooses (such as, on
the Desktop).
If correct, log into Blackboard and turn in the
zip file (via file upload in your web browser).
Visitors:
