| EIW Fall 2004 | HW2: JavaScript Game |
| EIW Home | Description | Demo Game | Go Crazy | Submitting | |
It is required that you write the code you submit! If you borrow ideas from JavaScript code you find on the WWW (or anywhere else) you must document this in your code (include a comment that indicates where you got the ideas, etc.).
| Assignment Description |
You are to write a game using Javascript. There is no "server" involved in this game - the browser does all the work (via the Javascript code you include in a web page).
The game is played on a 3x3 grid, each cell of the grid can be in one of two possible states. The goal of the game is to set all of the cells to the same state. Moves are made by clicking on a cell, this changes the state of the cell, and the state of all the immediate "neighbors" of the cell (vertical and horizontal neighbors only, cells on a diagonal are not "neighbors").
There are only three different kinds of moves, corresponding to the three different kinds of cells (the center, any corner, any side). The cells effected by each kind of move are shown below.
1. Center move: toggles the color on all cells next to the center. |
![]() |
2. Side move: toggles the color on all cells next to the selected side cell. |
![]() |
3. Corner move: toggles the color on all cells next to the selected corner cell. |
![]() |
You can use whatever you want to represent the two different "states", in the demo version I the state is indicated by the color of the cell, but your could also use images or whatever you want.
| Game Requirements |
Your game must include the following:
You must allow users to make a move by clicking on any cell, and the moves must follow the rules shown above.
The game must recognize when the user has won, and either display a message on the web page or pop up an alert.
There must be a button or link that the user can click on to start a new game (which must initialize the board to a random set of states).
| Demonstration Game |
There is a server-based demonstration version of the game running at http://monte.cs.rpi.edu/~hollingd/eiw/hw2/. You should play with this demo version to make sure you understand how the game works.
| Go Crazy! |
There are lots of ways you can enhance the game, some ideas are listed below. None of these is required (but may be fun to implement).
Use JavaScript to somehow highlight the cells that will be changed whenever the mouse is over a cell.
Keep an on-screen running tally of the number of moves
Have the game provide witty remarks on the screen every time the user makes a move.
Allow the user to select the images/colors used to indicate the state of each cell.
Write some code that can "solve" the game by telling the user which cells to click.
| How to Submit |
You must submit your HTML file and any other necessary files (CSS, images, etc) to the WebCT Dropbox set up for HW2 submissions. Feel free to include a text file named README that includes notes about your game, etc.
If you work with a partner, you should only submit once. Make sure you include a file named README in the submission that clearly states the names of both of the team members.