| Date Assigned: | Thu Apr-12 |
| Date Due: | Wed Apr-18 |
(Note: This is a double assignment. It was originally due Tue Apr-17, but was modified (see below) and is now due Wed Apr-18 for double credit.)
In this assignment, we use Mark Stehlik's CMU Graphics package (see Mark's APCS home page or just download the code for Visual C++).
#1) Write a program which uses Mark Stehlik's graphics package which creates a window into which the user can repeatedly enter (from the keyboard) numbers from 2 to 9 (all other keyboard input is disregarded, except if the user enters 'Q' or 'q' to quit). Each time the user enters a number N, your program should clear the screen then draw a grid of lines to produce NxN boxes, as we began in class. The top left should be at 50,50 and the bottom right should be at 550,550. YOU MAY WORK WITH YOUR PARTNER ON THIS PROBLEM.
#2) Write a program which uses Mark Stehlik's graphics package
which creates a window in which two players can play Tic-Tac-Toe.
To do this, first draw a 3x3 grid. Next, wait for mouse clicks, which
will be in the position where the next move is (or, if off the board or
in an illegal position, are disregarded). Next, draw an X or an O
(as appropriate) in the appropriate square. Next, if there is a victory,
draw a straight line through the 3 X's or O's which form the victory,
pause for 3 seconds, clear the board, display the score, pause for
3 more seconds, and start over. Finally, if there is a tie (the board
is full and nobody has won), erase the board, display the word TIE along
with the score, pause for 3 seconds, and start over. YOU MUST WORK
ALONE ON THIS PROBLEM.
Hint:
Some folks have had some problems getting apmatrix to work with the graphics code. For this assignment, you may use C++ built-in matrices. So, instead of declaring:
apmatrix<int> board(3,3);
You would declare:
int board[3][3];
Note that you must manually initialize the board, as in:
const int EMPTY = -1;
int row, col;
for (row=0; row<3; row++)
for (col=0; col<3; col++)
board[row][col] = EMPTY;
Update:
The homework that was due today is now due tomorrow as a DOUBLE assignment, and with the following changes:
#1) Your program should read in *two* digits to determine N (so if the user enters, say, '3' '2', you should make a 32x32 grid, and '0' '5' would produce a 5x5 grid).
#2) Your Tic Tac Toe program should read in *two* digits -- N and K. The first digit, N, determines the board size -- make the board NxN (note that N must be between 2 and 9 inclusive). The second digit, K, determines how many pieces in a row constitutes a victory. So, "normal" Tic Tac Toe is played if the user enters '3' '3', meaning a 3x3 board with 3-in-a-row to win. But the user could also enter '9' '4', producing a 9x9 board requiring 4-in-a-row to win.
Good luck.
DK