CIT 597 Assignment 2: TurnBlue
Fall 2008, David Matuszek

"TurnBlue" is a puzzle game, based on a much older computer game whose name I have forgotten. I have chosen this game because the programming logic is simple, and should not itself be any challenge; thus, almost all of the difficulties you encounter (and they may be considerable) will be in learning to use a new programming language.

Purposes of this assignment:

• Get you started using JavaScript
• Get you started understanding the HTML/XHTML DOM
• Get you started using forms

General idea of the assignment:

"TurnBlue" is a puzzle game, based on a much older computer game whose name I have forgotten.

The player is presented with an 8x8 grid of squares, some of which are red, and the others blue. By clicking on various squares, the player tries to make all the squares blue.

The logic is simple. When the user clicks a square, up to five squares change color (red to blue, or blue to red): the square clicked on, the squares directly above and below the clicked square, and the squares directly to the left and right of the clicked square. If the clicked square is on a border or in a corner, fewer than five squares will change color.

In this version, the play proceeds in levels. At the first (dead simple) level, the player has to click one square; at the second level, two squares; and so on, up to a maximum of 32 squares. So that there is a definite end to the game, if the player clicks five times more than is required by a level, the game is over.

How to create the puzzle

To create a puzzle at level N, begin with a board that is entirely red. Then simulate N clicks on the board in randomly chosen squares, taking care never to click a given square more than once. Finally, present the board to the player.

Programming requirements

• Use JavaScript (ECMAScript), XHTML, and CSS
• Embed the game in a web page.
• Provide a brief description of the game.
• Display the board as an 8x8 array of colored squares.
• Handle clicks on the colored squares.
• Provide a continuous display of the current level number, and the number of clicks so far on this level.
• When the board becomes all blue, put up a congratulatory Alert dialog before proceeding to the next level.
• Provide a Play New Game button which can be clicked at any time to start a new game.
• When the player loses, provide a suitable pop-up message, and disable further clicks on the squares.
• [Optional] Provide a congratulatory message when the player wins level 32. (Optional because we aren't likely to test this feature!)
• Use good programming practices.
• Break your program up into well-chosen and well-named methods or functions.