PLEASE READ VERY CAREFULLY write a client.py and server.py file for tic-tac-toe IN PYTHON with the following...

60.1K

Verified Solution

Question

Programming

PLEASE READ VERY CAREFULLY

write a client.py and server.py file for tic-tac-toe INPYTHON with the following restrictions (SO WRITE TWO FILES THATPLAY PYTHON THROUGH A SOCKET)


Use a 5 x 5 grid (dimensions are subject to change, so useconstants for NUM_ROWS and NUM_COLS)


Use 'X' for player 1 and 'O' for player 2 (symbols and the numberof players is subject to change, so use constants)


Each player can make 1 move per turn before having to wait for thenext player to move. If an illegal move is made, an
error message is sent to the player by the server and the playerloses the current turn

SO AGAIN TO RECAP A TIC TAC TOE PROGRAM IN PYTHON THAT ALLOWSTWO PLAYERS TO PLAY TOGETHER, a client and a server file

the end result will include coding similar to this

HOST = '127.0.0.1'
PORT = 12345
NUM_CONNECTIONS = 1

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((HOST, PORT))
sock.listen(NUM_CONNECTIONS)

Answer & Explanation Solved by verified expert
4.4 Ratings (1029 Votes)
Gui Scipt tttguipy Import the GUI library Tkinter import tkinter Import the messagebox module explicitly from tkinter import messagebox Import the webbroswer module for opening a link import webbrowser Import the client module from tttclient import TTTClientGame Import multithreading module import threading Import socket import socket Constants CWINDOWWIDTH 640 CWINDOWHEIGHT 480 CWINDOWMINWIDTH 480 CWINDOWMINHEIGHT 360 CCOLORBLUELIGHT e4f1fe CCOLORBLUEDARK 304e62 CCOLORBLUE a8d4f2 class CanvasWidget Abstract The base class for all the canvas widgets count 0 Count the number of widgets initialized def initself canvas Initializes the widget selfcanvas canvas Generate a unique id for each widget for tags selfid strCanvasWidgetcount CanvasWidgetcount CanvasWidgetcount 1 Generate a unique tag for each widget selftagname selfclassname selfid Initialize instance variables selfdisabled False Set default colors selfnormalcolor CCOLORBLUE selfhoveredcolor CCOLORBLUEDARK def setclickableself clickable Sets if the widget can be clicked ifclickable selfcanvastagbindselftagname selfonclick else selfcanvastagunbindselftagname def onclickself event Private This function will be called when the user clicks on the widget ifselfdisabled return False if selfcommand is not None selfcommand return True else printError selfclassname selfid does not have a command raise AttributeError return False def sethoverableself hoverable Sets if the widget can be hovered ifhoverable selfcanvastagbindselftagname selfonenter selfcanvastagbindselftagname selfonleave else selfcanvastagunbindselftagname selfcanvastagunbindselftagname def onenterself event Private This function will be called when the mouse enters into the widget ifselfdisabled return False selfcanvasitemconfigselftagname fillselfhoveredcolor return True def onleaveself event Private This function will be called when the mouse leaves the widget ifselfdisabled return False selfcanvasitemconfigselftagname fillselfnormalcolor return True def disableself Disables the widget so it wont respond to any events selfdisabled True def enableself Enables the widget so it starts to respond to events selfdisabled False def isenabledself Returns True if the widget is disabled return selfdisabled def configself kwargs Configures the widgets options return selfcanvasitemconfigselftagname kwargs def deleteself selfcanvasdeleteselftagname class CanvasClickableLabelCanvasWidget A clickable label that shows text and can respond to user click events def initself canvas x y labeltext normalcolor hoveredcolor Initializes the clickable label object Initialize super class CanvasWidgetinitself canvas Set color scheme for different states selfnormalcolor normalcolor selfhoveredcolor hoveredcolor Create the clickable label text canvascreatetextx y fontHelvetica 14 underline textlabeltext fillselfnormalcolor tagsselftagname Bind events selfsethoverableTrue selfsetclickableTrue class CanvasButtonCanvasWidget A button that responds to mouse clicks Define constant width and height WIDTH 196 HEIGHT 32 def initself canvas x y buttontext normalcolor hoveredcolor normaltextcolor hoveredtextcolor Initialize the button object Initialize super class CanvasWidgetinitself canvas Set color scheme for different states selfnormalcolor normalcolor selfhoveredcolor hoveredcolor selfnormaltextcolor normaltextcolor selfhoveredtextcolor hoveredtextcolor Create the rectangle background canvascreaterectanglex selfWIDTH2 selfHEIGHT2 y selfHEIGHT2 x selfWIDTH2 selfHEIGHT2 y selfHEIGHT2 fillselfnormalcolor outline tagsselftagname rect selfid Create the two circles on both sides to create a rounded edge canvascreateovalx selfWIDTH2 y selfHEIGHT2 x selfWIDTH2 selfHEIGHT y selfHEIGHT2 fillselfnormalcolor outline tagsselftagname ovall selfid canvascreateovalx selfWIDTH2 selfHEIGHT y selfHEIGHT2 x selfWIDTH2 y selfHEIGHT2 fillselfnormalcolor outline tagsselftagname ovalr selfid Create the button text canvascreatetextx y fontHelvetica 16 bold textbuttontext fillselfnormaltextcolor tagsselftagname text selfid Bind events selfsethoverableTrue selfsetclickableTrue def onenterself event Override Change the text to a different color when the enter event is triggered ifsuperonenterevent selfcanvasitemconfigtext selfid fillselfhoveredtextcolor def onleaveself event Override Change the text to a different color when the leave event is triggered ifsuperonleaveevent selfcanvasitemconfigtext selfid fillselfnormaltextcolor class CanvasSquareCanvasWidget A square that responds to mouse click event This is for the grid board def initself canvas x y width normalcolor hoveredcolor disabledcolor Initialize the square object Initialize super class CanvasWidgetinitself canvas Set color scheme for different states selfnormalcolor normalcolor selfhoveredcolor hoveredcolor selfdisabledcolor disabledcolor Create the circle background canvascreaterectanglex width2 y width2 x width2 y width2 fillselfnormalcolor outline tagsselftagname oval selfid Bind events selfsethoverableTrue selfsetclickableTrue def disableself Override Change the color when the square is disabled superdisable selfcanvasitemconfigselftagname fillselfdisabledcolor def enableself Override Change the color back to normal when the square is disabled superenable selfcanvasitemconfigselftagname fillselfnormalcolor def settempcolorself color selfcanvasitemconfigselftagname fillcolor class BaseScenetkinterCanvas Abstract The base class for all scenes BaseScene deals with general widgets and handles window resizing event def initself parent Initializes the scene Initialize the superclass Canvas tkinterCanvasinitself parent bgCCOLORBLUELIGHT widthCWINDOWWIDTH heightCWINDOWHEIGHT Bind the windowresizing event selfbind selfonresize Set selfwidth and selfheight for later use selfwidth CWINDOWWIDTH selfheight CWINDOWHEIGHT def onresizeself event Private This function is called when the window is being resied Determine the ratio of old widthheight to new widthheight selfwscale floateventwidthselfwidth selfhscale floateventheightselfheight selfwidth eventwidth selfheight eventheight Resize the canvas selfconfigwidthselfwidth heightselfheight Rescale all the objects tagged with the all tag selfscaleall 0 0 selfwscale selfhscale def createbuttonself x y buttontext normalcolorCCOLORBLUE hoveredcolorCCOLORBLUEDARK normaltextcolorCCOLORBLUEDARK hoveredtextcolorCCOLORBLUELIGHT Creates a button widget and returns it Note this will return a CanvasButton object not the ID as other standard Tkinter canvas widgets usually returns return CanvasButtonself x y buttontext normalcolor hoveredcolor normaltextcolor hoveredtextcolor def createsquareself x y width normalcolorCCOLORBLUE hoveredcolorCCOLORBLUEDARK disabledcolorCCOLORBLUELIGHT Creates a square widget and returns it Note this will return a CanvasSquare object not the ID as other standard Tkinter canvas widgets usually returns return CanvasSquareself x y width normalcolor hoveredcolor disabledcolor def    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students