Objectives:
- What you have so far from the pre-lab:
- two 2-dimensional arrays to model a tic-tac-toe game board
- mouse up event for each cell
- toggle between player 1 and player 2
- use of dynamic text to display whose turn it is
- What remains to do:
- make marked cells non-clickable
- reduce code duplication using function
- compact code using nested for-loops
- check winner
- announce the winner in the feedback textbox when there is a winner
- take care of things after game over
How the Completed File Works:
Pre-lab plus the following:
- The marked cells are not clickable.
- Check winner after each marking of the cell. Announce winner in the feedback textbox when there is one.
- The unmarked cells are not clickable any more after there is a winner.
- Compact the code using nested for-loops.
Note: The extra credit samples shown here have different graphics than the basic one shown above. But it does NOT mean that extra credits require any new graphics. I use different graphics for the files of extra credits so that I can easily tell which ones are examples for the extra credits.
Extra Credit #1: up to 10 points
Check tie and display in the dynamic text that it is a tie.
Extra Credit #2: up to 5 points
Make the hand cursor appear when the mouse is over an unmarked cell. It will be a regular pointer cursor if the cell has been marked.
Extra Credit #3: up to 15 points
Allow restarting the game at any time upon pressing a key, such as spacebar.
Extra Credit #4: up to 5 points
In the hasAWinner() function, use a for-loop to compact 6 (out of the 8) if-statements.
Same game play, but the difference is in the code.