TicTacToe is usually played on a 3-by-3 square board. To make things more interesting (and to help you learn how to write flexible code) our version will allow any square board size. To see what the finished product might look like, run this file: TicTacToe6.pyc. Enter the board size (e.g. 3, 4, or 5 for a 3-by-3, 4-by-4, or 5-by-5 square board, respectively) and press the <ENTER> key. When the board appears, click on it with the left mouse button to select squares. Note that it is possible that the board will pop up behind other windows. If you don't see the board after entering the board size, try moving or minimizing some other windows.
Follow this cycle of update-edit-commit whenever you make changes to your program.
Edit the TicTacToe.py module in your project so that it creates a graphics window and draws a 3-by-3 TicTacToe grid. Your finished program may look something like TicTacToe0.pyc . Try it out before writing your code.This task is fairly simple, but you should do it in a way that will help you plan ahead for future versions. Here are a few lines of code that you should use. Defining named constants and using them in your code instead of numbers can avoid the use of "magic numbers" that can make code difficult to enhance and maintain. In this case, it helps because the board size will not always be 3 in later versions of the program,
BOARDSIZE = 3 # number of rows and columns BOARDRANGE = range(BOARDSIZE) # range of rows and columns PPS = 150 # pixels per square WINDOWSIZE = PPS * BOARDSIZE # width and height of window INSET = 15 # num of white pixels around X's and O's in squares
If you want to make the board linger on the screen for a few seconds and then disappear like the sample program does, import the time module, and include the line time.sleep(3) before your window.close() statement. Don't forget that you also need to import the zellegraphics module.
If you want to require the user to click on the window to
make it disappear instead of making it linger for a few seconds,
include the line window.getMouse()
before your
window.close()
statement, instead of the line
time.sleep(3).
Before going on to the next step, commit your project to your Subversion repository by right-clicking it and choosing Team → Commit... Please make sure your commit comment begins with the words Phase 0.
Before moving on to the next step, both you and your team should update your working copy so it reflects what's in the repository.
Before going on to the next step, commit your project to your Subversion repository. Please begin your commit comment with Phase 1.
Before moving on to the next step, both you and your team should update your working copy so it reflects what's in the repository.
def rectUpperRight(row, col): """coordinates of top right corner of inset X or O""" return Point(PPS*(col+1) - INSET, PPS*row + INSET)
Call each function, drawX() and drawO(), with some different values for the parameters and verify that they work correctly. Can you put an X and an O in the same square? (In a later step you will solve this).
Before going on to the next step, commit your project to your Subversion repository. Please make sure your commit comment indicates which phase you just completed.
Before moving on to the next step, both you and your team should update your working copy so it reflects what's in the repository.
Before going on to the next step, commit your project to your Subversion repository. Please make sure your commit comment indicates which phase you just completed.
Before moving on to the next step, both you and your team should update your working copy so it reflects what's in the repository.
Before going on to the next step, commit your project to your Subversion repository. Please make sure your commit comment indicates which phase you just completed.
Before moving on to the next step, both you and your team should update your working copy so it reflects what's in the repository.
Before going on to the next step, commit your project to your Subversion repository. Please make sure your commit comment indicates which phase you just completed.
Before moving on to the next step, both you and your team should update your working copy so it reflects what's in the repository.
Congratulations on completing this interesting project. This was a challenge but you did well by completing it.
Commit your project to your Subversion repository. Please make sure your commit comment indicates that you have completed the project.
You and your team should update your working copy so it reflects the completed version of the project.