CIT 597 Assignment 3: JavaScript game (Face Off)
Fall 2005, David Matuszek

Purposes of this assignment:

General idea of the assignment:

This is a little game I just made up (I'm calling it "Face Off") for the purposes of the assignment. It's probably not a very exciting game, but it will suffice to get you programming in JavaScript. The human plays against the computer.

Each player (the human and the computer) is given a hand of N cards, numbered 1 through N. (N is a fairly small number, say 10 or 13.) At each turn, each player chooses and plays one card from their hand. The player who plays the higher-numbered card takes both cards and adds them to their "captured" pile. In the event of a tie, each player retrieves their own card and places it in their captured pile. Play continues for N turns, that is, until all cards have been used.

At the end of the game, each player totals the cards that have been captured. The player with the higher point count wins. (As a betting game, the winning player collects the difference in their totals from the loser.)

Details:

You should keep two arrays for the computer, and two for the human. One array, the "hand," contains all the unplayed cards; the other, the "captured pile," contains the cards won during play.

Initially, each player's hand contains N cards, numbered 1 through N. Unlike some card games, there is no randomness involved; players always start with the same hand. If, for example, N = 10, then the hand contains the following cards:

1   2   3   4   5   6   7   8   9   10

The value of N should be set in a single place in your JavaScript, so that it's easy to change. (You can give it a better name if you like.)

There is no way to win a turn with the 1 card; at best, it will be a tie. Similarly, there is no way to lose when playing the highest card (10 in this example).

At each turn, the two players play "simultaneously," so that neither know what card the other will play. In practice, of course, the human has to choose a card, and trust the computer to be honest and choose a card without "peeking." Your program should play honestly.

The computer player can play randomly, or you can try to give it some more sophisticated strategy.

Write the program using HTML Forms and JavaScript. It's up to you to design the GUI, but...please try it out on at least one other person before you turn it in (preferably a fellow CIT597 student), to make sure that the GUI is understandable. You'll lose points if the grader and I can't figure out how to play it. (Along with this, please be willing to try out games that your fellow students have written.) It's OK to borrow GUI ideas from one another, as long as you don't actually copy code.

Since the game is part of an HTML page, you can easily include some instructions on how to play the game. This might include some hints on how to use your GUI, but remember that no amount of explanation makes up for a confusing design.

At the end of each game, display some simple statistics, such as: The number of games played, the number of games won or lost, the total number of points won or lost.

Give the user the option of playing yet another game. (On an HTML page, it's difficult to "quit" the JavaScript program, so don't try.)

Due date:

Wednesday, October 5, before midnight. Again, just send the URL to both myself and my grader.