Project: 2 Player Tic-Tac-ToeIt is a requirement that you follow the direction and not give me something off the internet. Yes, YOU MUST USE EZGRAPHICS!Please note you do not have to have a complete,...




Project: 2 Player Tic-Tac-Toe



It is a requirement that you follow the direction and not give me something off the internet. Yes, YOU MUST USE EZGRAPHICS!



Please note you do not have to have a complete, working program that works to get a grade. But make sure you complete each task one at a time and test it. A Completed, working task is better than a buggy, flaky program.



Following the steps outlined below one step at a time and submit all the accomlished functions before the due date is important. Completing each task gets 50, 60, 70, 80, 90 points.



There are several tasks involed doing this:



1. Functions that draw the Tic-Tac-Toe Game Board on the canvas of a window of 900x900. Hint, 9 squares next to each other is easiest. Horizontal or verticle lines work, too.






Function would start with: def ticTacToeBoard():






(Extra Credit: Use drawText function to put numerals 1-9 inside the box)






Requirement: Use a 9-element list to keep track of the corner and length of each box, and the content of the box, i.e. empty or an X or an O)






boxes = [(0,0, ""),(0,0, ""),(0,0, ""),(0,0, ""),(0,0, ""),(0,0, ""),(0,0, ""),(0,0, ""),(0,0, "")]






Hint:





# Below is code you can use to get started



win = GraphicsWindow(900, 900)
win.setTitle("Tic-Tac-Toe")
canvas = win.canvas()



side=(int)(900/3) # global variable that can be used in any function in this file.



boxes = [[0,0,""], [0,0,""], [0,0,""], [0,0,""], [0,0,""], [0,0,""], [0,0,""], [0,0,""],[0,0,""]]



def setupBoxes():



for row in range(3):



x = row * side



for col in range(3):



y = col * side



boxes[row*3 + col][0] = x



boxes[row*3 + col][1] = y



# The above code sets up the boxes list, which has x, y and the content of the box (all empty in the beginning



# You can use the for item in list loop to go through the boxes list one item at a time to draw the boxes one by one.























2. Functions that draw the circle or x inside any particular square.






You can start by making 2 test functions: drawO(x, y, size) and drawX(x,y, size) to draw an O and X in any location on the canvas. Make sure the O and X are sized to fit.






test out the drawO,X function using different X and O x, y and sizes so that you know the X and O you draw will fix inside the box and looks nice.Once you can do this, then make the following 2 functions:






def playO(box) where box is a number 0-8






def playX(box) where box is a number 0-8



3. Ask Player(s) for input using getMouse(), which returns a tuple.







Write a function getBox() to figure out which box (0-8) is being played once a mouseClick is received.






(Important) Detect if the user clicked on a box that has already been played. If there is already X or O in there, you need to ignore the mouse click and keep waiting for another mouse click. This means a infinite while loop (the user can click on already opened box many, many times) until the user click on an empty box.









4. Write the main function that allows the players to play. It would bea loop that goes 9 times and then stop. Each loop would do a getBox() first to see which box is clicked, followed by playO or playX, If you can do (5), then you can break out of the while look using (5). Note: As a rule, first Player gets circle and second player gets X.






The function looks like: def playTicTacToe():



5. Add the logic to detect Game Over.






The function looks like def TicTacToeOver()






which would return True of False by examining the content of the boxes[] list.










Mar 07, 2023
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here