MIDTERM
CS320, Spring 2004
Upload your bean and JSP to the cs server and make sure they work
there. Print a hard copy of your TTTBean.java and TicTacToe.jsp and
turn it in at the end of the exam. Do not forget to put your name and
your server account name on
the hard copy.
[Problem Description] Tic Tac Toe is a game played on a 3 by 3 grid by
two players, Player 1 and Player 2. Player 1 starts by placing an
O at an unoccupied
grid
postition. Then Player 2 places an X
at an unoccupied grid position. Play alternates between Player 1 and 2
until
one player's symbols occupy an entire line
(vertical, horizontal, or diagonal), in which case that player wins; or
the grid is filled, in which case the game is tied.
For this exam you are going to implement the Tic Tac Toe game using
JSP. The game will be played by two human players, so no AI code is
needed. To receive any credit at all for the exam, your implementation
must follow the following specifications:
[Bean] Your JSP must use a Java Bean called TTTBean to keep track the
progress of the
game. In particular, the bean must have the following properties:
- move -- setting this
property to n, where n is an integer value between 0 and
8, indicates a move at the grid position n (imagine the nine grid positions
are
numbered from 0 to 8 in a row-major order). Whether the move is by
Player 1 or 2 is decided internally by the bean. e.g. the first move is
by Player 1, second move by Player 2, third move by Player 1 and so on.
Invalid moves such as a move outside the board or a move to an occupied
position are simply ignored.
- new -- setting this
property will clear the current game and starts a new one.
- status -- the value of
this property shows the progress/outcome of the game. In particular
- 0: the game is underway
- 1: player 1 won
- 2: player 2 won
- 3: draw
- board -- the value of
this property is a String array of size 9. Each element of the array
corresponds to a grid postion of the board, and could be one of the
following three values:
- "<a
href=TicTacToe.jsp?move=i>_</a>" if position i is currently unoccupied.
- "<span
style='color:red'>O</span>" if the position
is occupied by Player 1's symbol.
- "<span
style='color:blue'>X</span>" if the position
is occupied by Player 2's symbol.
Note that move and new are write-only properties,
which mean your bean doesn't need to have getMove() or getNew() method,
while status and board are read-only properties,
which means your bean doesn't need to have setStatus() or setBoard()
method.
[JSP] You should have a JSP file called TicTacToe.jsp which
displays the following:
- A message of "Next move please:", "Player 1 won!! A new game?",
"Player
2 won!! A new game?", or "Tied! A new game?", based on the status of
the game.
- The game board as a 3 by 3 table.
- A link labelled as "New Game". Clicking on this link will clear
the board and start a new game.
Here's some sample display:
You should use only HTML, Java beans, JSTL tags, and Expression
Language (EL) in your JSP file. Any scripting element in the JSP
file will incur a 5pt penalty per statement with the maximum penalty
of 40pt. Directives and comments do not count as scripting
elements.
[Grading Criteria]
1. TTTBean.java
- structure (5pt)
- move (10pt)
- new (5pt)
- status (20pt)
- board (15pt)
2. TicTacToe.jsp
- structure (10pt)
- message (10pt)
- board (20pt). to receive full credit you must use
<c:forEach> to generate the board table.
- new game (5pt)
3. JSP does not work on cs.calstatela.edu (-30pt)