diff --git a/.DS_Store b/.DS_Store index 33ddf2c..6aee1eb 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Gui.PNG b/Gui.PNG new file mode 100644 index 0000000..ddfa971 Binary files /dev/null and b/Gui.PNG differ diff --git a/README.md b/README.md index cdf1fac..41337e6 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,3 @@ -# Sudoku Game In Python +# Tic Tac Toe Game In Python - -### run: - -* python gui.py - -### Mac - -* python3 gui.py \ No newline at end of file + \ No newline at end of file diff --git a/Winning_message.PNG b/Winning_message.PNG new file mode 100644 index 0000000..9ebcf05 Binary files /dev/null and b/Winning_message.PNG differ diff --git a/data/.DS_Store b/data/.DS_Store deleted file mode 100644 index 4f5efd7..0000000 Binary files a/data/.DS_Store and /dev/null differ diff --git a/data/Highscore.txt b/data/Highscore.txt deleted file mode 100644 index e69de29..0000000 diff --git a/data/audios/.DS_Store b/data/audios/.DS_Store deleted file mode 100644 index e06e2bb..0000000 Binary files a/data/audios/.DS_Store and /dev/null differ diff --git a/data/audios/Crash.mp3 b/data/audios/Crash.mp3 deleted file mode 100644 index b94cf51..0000000 Binary files a/data/audios/Crash.mp3 and /dev/null differ diff --git a/data/audios/game.mp3 b/data/audios/game.mp3 deleted file mode 100644 index 2b04fbc..0000000 Binary files a/data/audios/game.mp3 and /dev/null differ diff --git a/data/audios/rtn.mp3 b/data/audios/rtn.mp3 deleted file mode 100644 index 94dcb7f..0000000 Binary files a/data/audios/rtn.mp3 and /dev/null differ diff --git a/data/images/.DS_Store b/data/images/.DS_Store deleted file mode 100644 index a0fd77d..0000000 Binary files a/data/images/.DS_Store and /dev/null differ diff --git a/data/images/Background.png b/data/images/Background.png deleted file mode 100644 index 3ed5060..0000000 Binary files a/data/images/Background.png and /dev/null differ diff --git a/data/images/Car.png b/data/images/Car.png deleted file mode 100644 index e747827..0000000 Binary files a/data/images/Car.png and /dev/null differ diff --git a/data/images/Coming Cars/CC1.png b/data/images/Coming Cars/CC1.png deleted file mode 100644 index d4bcb4b..0000000 Binary files a/data/images/Coming Cars/CC1.png and /dev/null differ diff --git a/data/images/Coming Cars/CC2.png b/data/images/Coming Cars/CC2.png deleted file mode 100644 index 552dcf4..0000000 Binary files a/data/images/Coming Cars/CC2.png and /dev/null differ diff --git a/data/images/Coming Cars/CC3.png b/data/images/Coming Cars/CC3.png deleted file mode 100644 index c556452..0000000 Binary files a/data/images/Coming Cars/CC3.png and /dev/null differ diff --git a/data/images/Coming Cars/CC4.png b/data/images/Coming Cars/CC4.png deleted file mode 100644 index 4761af9..0000000 Binary files a/data/images/Coming Cars/CC4.png and /dev/null differ diff --git a/data/images/Coming Cars/CC5.png b/data/images/Coming Cars/CC5.png deleted file mode 100644 index 2f7334f..0000000 Binary files a/data/images/Coming Cars/CC5.png and /dev/null differ diff --git a/data/images/Coming Cars/CC6.png b/data/images/Coming Cars/CC6.png deleted file mode 100644 index 6d5dcbe..0000000 Binary files a/data/images/Coming Cars/CC6.png and /dev/null differ diff --git a/data/images/Coming Cars/CC7.png b/data/images/Coming Cars/CC7.png deleted file mode 100644 index 3fefdbf..0000000 Binary files a/data/images/Coming Cars/CC7.png and /dev/null differ diff --git a/data/images/Coming Cars/CC8.png b/data/images/Coming Cars/CC8.png deleted file mode 100644 index 6c690ad..0000000 Binary files a/data/images/Coming Cars/CC8.png and /dev/null differ diff --git a/data/images/Coming Cars/CC9.png b/data/images/Coming Cars/CC9.png deleted file mode 100644 index d9a0e9b..0000000 Binary files a/data/images/Coming Cars/CC9.png and /dev/null differ diff --git a/data/images/Explosion.png b/data/images/Explosion.png deleted file mode 100644 index 05ff1d4..0000000 Binary files a/data/images/Explosion.png and /dev/null differ diff --git a/data/images/Fuel.png b/data/images/Fuel.png deleted file mode 100644 index b285bec..0000000 Binary files a/data/images/Fuel.png and /dev/null differ diff --git a/data/images/GameOver.png b/data/images/GameOver.png deleted file mode 100644 index 0dbbcb0..0000000 Binary files a/data/images/GameOver.png and /dev/null differ diff --git a/data/images/Going Cars/GC1.png b/data/images/Going Cars/GC1.png deleted file mode 100644 index e4e9af1..0000000 Binary files a/data/images/Going Cars/GC1.png and /dev/null differ diff --git a/data/images/Going Cars/GC2.png b/data/images/Going Cars/GC2.png deleted file mode 100644 index 5da0299..0000000 Binary files a/data/images/Going Cars/GC2.png and /dev/null differ diff --git a/data/images/Going Cars/GC3.png b/data/images/Going Cars/GC3.png deleted file mode 100644 index 9ea6b61..0000000 Binary files a/data/images/Going Cars/GC3.png and /dev/null differ diff --git a/data/images/Going Cars/GC4.png b/data/images/Going Cars/GC4.png deleted file mode 100644 index a437d5e..0000000 Binary files a/data/images/Going Cars/GC4.png and /dev/null differ diff --git a/data/images/Going Cars/GC5.png b/data/images/Going Cars/GC5.png deleted file mode 100644 index 090dacb..0000000 Binary files a/data/images/Going Cars/GC5.png and /dev/null differ diff --git a/data/images/Going Cars/GC6.png b/data/images/Going Cars/GC6.png deleted file mode 100644 index f8cf0fb..0000000 Binary files a/data/images/Going Cars/GC6.png and /dev/null differ diff --git a/data/images/Going Cars/GC7.png b/data/images/Going Cars/GC7.png deleted file mode 100644 index 6279978..0000000 Binary files a/data/images/Going Cars/GC7.png and /dev/null differ diff --git a/data/images/Going Cars/GC8.png b/data/images/Going Cars/GC8.png deleted file mode 100644 index 401de16..0000000 Binary files a/data/images/Going Cars/GC8.png and /dev/null differ diff --git a/data/images/Going Cars/GC9.png b/data/images/Going Cars/GC9.png deleted file mode 100644 index 3a4a03f..0000000 Binary files a/data/images/Going Cars/GC9.png and /dev/null differ diff --git a/data/images/LeftDisplay.png b/data/images/LeftDisplay.png deleted file mode 100644 index ff30950..0000000 Binary files a/data/images/LeftDisplay.png and /dev/null differ diff --git a/data/images/RightDisplay.png b/data/images/RightDisplay.png deleted file mode 100644 index 48f0828..0000000 Binary files a/data/images/RightDisplay.png and /dev/null differ diff --git a/data/images/Road.png b/data/images/Road.png deleted file mode 100644 index 1820217..0000000 Binary files a/data/images/Road.png and /dev/null differ diff --git a/data/images/Sand.jpg b/data/images/Sand.jpg deleted file mode 100644 index b6f640e..0000000 Binary files a/data/images/Sand.jpg and /dev/null differ diff --git a/data/images/Strip.png b/data/images/Strip.png deleted file mode 100644 index fad42aa..0000000 Binary files a/data/images/Strip.png and /dev/null differ diff --git a/data/images/Tree.png b/data/images/Tree.png deleted file mode 100644 index 4aa382c..0000000 Binary files a/data/images/Tree.png and /dev/null differ diff --git a/draw_messge.PNG b/draw_messge.PNG new file mode 100644 index 0000000..08f6243 Binary files /dev/null and b/draw_messge.PNG differ diff --git a/resources/base.png b/resources/base.png new file mode 100644 index 0000000..95c69de Binary files /dev/null and b/resources/base.png differ diff --git a/speed.py b/speed.py deleted file mode 100644 index b797d61..0000000 --- a/speed.py +++ /dev/null @@ -1,395 +0,0 @@ -import pygame -import time -import random -import os - -pygame.init() -pygame.mixer.init() - -gameWindow = pygame.display.set_mode((1200,700)) -pygame.display.set_caption("Speed Racer") - -clock = pygame.time.Clock() -fps = 60 - -font1 = pygame.font.SysFont("Franklin Gothic Demi Cond",50) - -car = pygame.image.load("data/images/Car.png") -car = pygame.transform.scale(car,(150,150)).convert_alpha() - -road = pygame.image.load("data/images/Road.png") -road = pygame.transform.scale(road,(400,700)).convert_alpha() - -sand = pygame.image.load("data/images/Sand.jpg") -sand = pygame.transform.scale(sand,(150,700)).convert_alpha() - -leftDisp = pygame.image.load("data/images/LeftDisplay.png") -leftDisp = pygame.transform.scale(leftDisp,(250,700)).convert_alpha() - -rightDisp = pygame.image.load("data/images/RightDisplay.png") -rightDisp = pygame.transform.scale(rightDisp,(250,700)).convert_alpha() - -tree = pygame.image.load("data/images/Tree.png") -tree = pygame.transform.scale(tree,(185,168)).convert_alpha() -treeLXY = [[290,0],[290,152.5],[290,305],[290,457.5],[290,610]] -treeRXY = [[760,0],[760,152.5],[760,305],[760,457.5],[760,610]] - -strip = pygame.image.load("data/images/Strip.png") -strip = pygame.transform.scale(strip,(25,90)).convert_alpha() -stripXY = [[593,0],[593,152.5],[593,305],[593,457.5],[593,610]] - -explosion = pygame.image.load("data/images/Explosion.png") -explosion = pygame.transform.scale(explosion,(290,164)).convert_alpha() - -fuel = pygame.image.load("data/images/Fuel.png") -fuel = pygame.transform.scale(fuel,(98,104)).convert_alpha() - -comingCars,goingCars = [],[] -speedCC = [13,14,15,14,14,15,13,14,15] -speedGC = [8,6,7,5,8,7,8,6,8] - -for i in range(1,10): - CCi = pygame.image.load("data/images/Coming Cars/"+"CC"+str(i)+".png") - CCi = pygame.transform.scale(CCi, (75, 158)).convert_alpha() - comingCars.append([CCi,speedCC[i-1]]) - GCi = pygame.image.load("data/images/Going Cars/"+"GC"+str(i)+".png").convert_alpha() - GCi = pygame.transform.scale(GCi,(75,158)).convert_alpha() - goingCars.append([GCi,speedGC[i-1]]) - -def distance(carX,obstX,carY,obstY,isFuel = False): - - if not isFuel: - carX += 75 # 75,75,37,79,55,130 - carY += 75 - obstX += 37 - obstY += 79 - - return abs(carX - obstX) < 55 and abs(carY - obstY) < 130 - else: - carX += 75 - carY += 75 - obstX += 98 - obstY += 104 - - return abs(carX - obstX) < 70 and abs(carY - obstY) < 80 - -def textOnScreen(text,color,x,y,font): - screenText = font.render(text,True,color) - gameWindow.blit(screenText,[x,y]) - -def slowDown(carX,carY,dist,highscore): - - stripXY_ = [[593, 0], [593, 152.5], [593, 305], [593, 457.5], [593, 610]] - exitScreen = False - - stripSpeed = 2 - - start = time.time() - while not exitScreen: - if time.time() - start > 3: - stripSpeed = 1 - if time.time() - start > 6: - exitScreen = True - for event in pygame.event.get(): - if event.type == pygame.QUIT: - exitScreen = True - - gameWindow.fill((0,0,0)) - gameWindow.blit(leftDisp, (0, 0)) - textOnScreen("DISTANCE", (255, 255, 0), 27, 388, font1) - textOnScreen(str(dist) + " Kms", (255, 0, 0), 56, 480, font1) - textOnScreen("FUEL", (255, 255, 0), 73, 90, font1) - textOnScreen(str(0.00) + ' %', (255, 0, 0), 75, 184, font1) - gameWindow.blit(rightDisp, (950, 0)) - textOnScreen("HIGHSCORE", (255, 255, 0), 958, 236, font1) - if(highscore < 10): - disp = str(0) + str(highscore) - else: - disp = str(highscore) - textOnScreen(disp + " Kms", (255, 0, 0), 1005, 342, font1) - gameWindow.blit(road, (400, 0)) - gameWindow.blit(sand,(250,0)) - gameWindow.blit(sand,(800,0)) - - for i in range(len(stripXY_)): - stripXY_[i][1] += stripSpeed - if stripXY_[i][1] > 700: - stripXY_[i] = [593, -60] - for i in range(len(treeLXY)): - treeLXY[i][1] += stripSpeed - if treeLXY[i][1] > 700: - treeLXY[i] = [290,-60] - for i in range(len(treeRXY)): - treeRXY[i][1] += stripSpeed - if treeRXY[i][1] > 700: - treeRXY[i] = [760,-60] - - for X,Y in stripXY_: - gameWindow.blit(strip,(X,Y)) - for treeX,treeY in treeLXY: - gameWindow.blit(tree,(treeX,treeY)) - for treeX,treeY in treeRXY: - gameWindow.blit(tree,(treeX,treeY)) - - gameWindow.blit(car,(carX,carY)) - pygame.display.update() - -def gameLoop(): - - pygame.mixer.music.load("data/audios/game.mp3") - pygame.mixer.music.play() - - time.sleep(1) - - carX,carY = 625,540 - drift = 4 - carSpeedX = 0 - - obstacleXY = [[460,-10],[710,-300]] - c1,c2 = random.randint(0,8),random.randint(0,8) - if(c1 == c2): - c1 = random.randint(0,8) - - obstacleSpeed = [comingCars[c1][1],goingCars[c2][1]] - obstacles = [comingCars[c1][0],goingCars[c2][0]] - - stripSpeed = 9 - - exitGame = False - gameOver = False - explode = False - - fuelCount = 50 - fuelX,fuelY = random.randint(420,620),-1000 - fuelSpeed = 8 - dist = 0 - - with open("data/Highscore.txt","r") as f: - highscore = int(f.read()) - - slow = False - plotFuel = True - - start1 = time.time() - start = [start1,start1] - start2 = start1 - start3 = start1 - start4 = start1 - arrival = [2,3.5] - - while not exitGame: - if gameOver: - - if slow: - slowDown(carX,carY,dist,highscore) - time.sleep(2) - - pygame.mixer.music.stop() - pygame.mixer.music.load("data/audios/rtn.mp3") - pygame.mixer.music.play() - - exitScreen = False - go = pygame.image.load("data/images/GameOver.png") - go = pygame.transform.scale(go,(1239,752)).convert_alpha() - - with open("data/Highscore.txt","w") as f: - f.write(str(highscore)) - - while not exitScreen: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - exitScreen = True - elif event.type == pygame.KEYDOWN: - if event.key == pygame.K_RETURN: - pygame.mixer.music.stop() - homeScreen() - gameWindow.fill((0,0,0)) - gameWindow.blit(go,(0,0)) - if(dist < 10): - disp = str(0) + str(dist) - else: - disp = str(dist) - textOnScreen(disp,(255,0,0),540,429,font1) - pygame.display.update() - clock.tick(fps) - - pygame.quit() - quit() - else: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - exitGame = True - elif event.type == pygame.KEYDOWN: - if event.key == pygame.K_RIGHT: - carSpeedX = drift - elif event.key == pygame.K_LEFT: - carSpeedX = -drift - elif event.key == pygame.K_a: - obstacleXY[0][0] -= 20 - elif event.key == pygame.K_d: - obstacleXY[1][0] += 20 - - carX += carSpeedX - fuelY += fuelSpeed - - if time.time() - start4 >= 2: - dist += 1 - if dist > highscore: - highscore = dist - start4 = time.time() - - if time.time() - start2 >= 3: - fuelCount -= 5 - start2 = time.time() - - if distance(carX,fuelX,carY,fuelY,True) and plotFuel: - plotFuel = False - fuelCount += 20 - - for i in range(len(obstacleXY)): - obstacleXY[i][1] += obstacleSpeed[i] - - fuelper = fuelCount/50 - if fuelper >= 1: - fuelper = 1 - - gameWindow.fill((0,0,0)) - gameWindow.blit(leftDisp,(0,0)) - textOnScreen("DISTANCE", (255, 255, 0),27,388,font1) - if(dist < 10): - disp = str(0) + str(dist) - else: - disp = str(dist) - textOnScreen(disp + " Kms",(255,0,0),56,480,font1) - textOnScreen("FUEL",(255,255,0),73,90,font1) - textOnScreen(str(fuelper*100) + ' %',(255,0,0),60,184,font1) - gameWindow.blit(rightDisp, (950, 0)) - textOnScreen("HIGHSCORE",(255,255,0),958,236,font1) - if(highscore < 10): - disp = str(0) + str(highscore) - else: - disp = str(highscore) - textOnScreen(disp + " Kms",(255,0,0),1005,342,font1) - gameWindow.blit(road,(400,0)) - gameWindow.blit(sand, (250, 0)) - gameWindow.blit(sand, (800, 0)) - - if fuelCount == 0: - gameOver = True - slow = True - - if carX > 720 or carX < 330: - pygame.mixer.music.load("data/audios/Crash.mp3") - pygame.mixer.music.play() - gameOver = True - explode = True - - for i in range(len(obstacleXY)): - if distance(carX,obstacleXY[i][0],carY,obstacleXY[i][1]): - pygame.mixer.music.load("data/audios/Crash.mp3") - pygame.mixer.music.play() - gameOver = True - explode = True - break - for i in range(len(stripXY)): - stripXY[i][1] += stripSpeed - if stripXY[i][1] > 700: - stripXY[i] = [593,-60] - for i in range(len(treeLXY)): - treeLXY[i][1] += stripSpeed - if treeLXY[i][1] > 700: - treeLXY[i] = [290, -60] - for i in range(len(treeRXY)): - treeRXY[i][1] += stripSpeed - if treeRXY[i][1] > 700: - treeRXY[i] = [760, -60] - - for stripX,stripY in stripXY: - gameWindow.blit(strip,(stripX,stripY)) - - if fuelY < 750: - if plotFuel: - gameWindow.blit(fuel,(fuelX,fuelY)) - - gameWindow.blit(car,(carX,carY)) - - for i in range(len(obstacleXY)): - if obstacleXY[i][1] < 750: - gameWindow.blit(obstacles[i],(obstacleXY[i][0], obstacleXY[i][1])) - - for treeX, treeY in treeLXY: - gameWindow.blit(tree, (treeX, treeY)) - for treeX, treeY in treeRXY: - gameWindow.blit(tree, (treeX, treeY)) - - if time.time() - start[0] >= arrival[0]: - x = random.randint(430,530) - x+=3 - obstacleXY[0] = [x,-10] - c1 = random.randint(0,8) - obstacles[0] = comingCars[c1][0] - obstacleSpeed[0] = comingCars[c1][1] - start[0] = time.time() - if time.time() - start[1] >= arrival[1]: - x = random.randint(620,710) - x-=3 - obstacleXY[1] = [x,-10] - c2 = random.randint(0,8) - obstacles[1] = goingCars[c2][0] - obstacleSpeed[1] = goingCars[c2][1] - start[1] = time.time() - if time.time() - start3 >= 15: - fuelX,fuelY = random.randint(420,710),-500 - plotFuel = True - start3 = time.time() - if explode: - gameWindow.blit(explosion,(carX - 63,carY)) - - pygame.display.update() - clock.tick(fps) - - - pygame.quit() - quit() - -def homeScreen(): - - pygame.mixer.music.load("data/audios/rtn.mp3") - pygame.mixer.music.play() - - if not os.path.exists("data/Highscore.txt"): - with open("data/Highscore.txt","w") as f: - f.write("0") - highscore = 0 - else: - with open("data/Highscore.txt","r") as f: - highscore = int(f.read()) - - - background = pygame.image.load("data/images/Background.png") - background = pygame.transform.scale(background,(1213,760)).convert_alpha() - - exitScreen = False - while not exitScreen: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - exitScreen = True - elif event.type == pygame.KEYDOWN: - if event.key == pygame.K_RETURN: - pygame.mixer.music.stop() - gameLoop() - - gameWindow.blit(background,(-6,-32)) - if(highscore < 10): - disp = str(0) + str(highscore) - else: - disp = str(highscore) - textOnScreen(disp,(255,0,0),980,9,font1) - pygame.display.update() - clock.tick(fps) - - pygame.quit() - quit() - - -homeScreen() diff --git a/ttgame.py b/ttgame.py new file mode 100644 index 0000000..2aee41e --- /dev/null +++ b/ttgame.py @@ -0,0 +1,208 @@ +from tkinter import * +from tkinter import ttk +import tkinter.messagebox + +root=Tk() +root.title("Tic Tac Toe") +#add Buttons +bu1=ttk.Button(root,text=' ') +bu1.grid(row=0,column=0,sticky='snew',ipadx=40,ipady=40) +bu1.config(command=lambda: ButtonClick(1)) + +bu2=ttk.Button(root,text=' ') +bu2.grid(row=0,column=1,sticky='snew',ipadx=40,ipady=40) +bu2.config(command=lambda: ButtonClick(2)) + +bu3=ttk.Button(root,text=' ') +bu3.grid(row=0,column=2,sticky='snew',ipadx=40,ipady=40) +bu3.config(command=lambda: ButtonClick(3)) + +bu4=ttk.Button(root,text=' ') +bu4.grid(row=1,column=0,sticky='snew',ipadx=40,ipady=40) +bu4.config(command=lambda: ButtonClick(4)) + +bu5=ttk.Button(root,text=' ') +bu5.grid(row=1,column=1,sticky='snew',ipadx=40,ipady=40) +bu5.config(command=lambda: ButtonClick(5)) + +bu6=ttk.Button(root,text=' ') +bu6.grid(row=1,column=2,sticky='snew',ipadx=40,ipady=40) +bu6.config(command=lambda: ButtonClick(6)) + +bu7=ttk.Button(root,text=' ') +bu7.grid(row=2,column=0,sticky='snew',ipadx=40,ipady=40) +bu7.config(command=lambda: ButtonClick(7)) + +bu8=ttk.Button(root,text=' ') +bu8.grid(row=2,column=1,sticky='snew',ipadx=40,ipady=40) +bu8.config(command=lambda: ButtonClick(8)) + +bu9=ttk.Button(root,text=' ') +bu9.grid(row=2,column=2,sticky='snew',ipadx=40,ipady=40) +bu9.config(command=lambda: ButtonClick(9)) + +playerturn=ttk.Label(root,text=" Player 1 turn! ") +playerturn.grid(row=3,column=0,sticky='snew',ipadx=40,ipady=40) + +playerdetails=ttk.Label(root,text=" Player 1 is X\n\n Player 2 is O") +playerdetails.grid(row=3,column=2,sticky='snew',ipadx=40,ipady=40) + +res=ttk.Button(root,text='Restart') +res.grid(row=3,column=1,sticky='snew',ipadx=40,ipady=40) +res.config(command=lambda: restartbutton()) + +a=1 +b=0 +c=0 +def restartbutton(): + global a,b,c + a=1 + b=0 + c=0 + playerturn['text']=" Player 1 turn! " + bu1['text']=' ' + bu2['text']=' ' + bu3['text']=' ' + bu4['text']=' ' + bu5['text']=' ' + bu6['text']=' ' + bu7['text']=' ' + bu8['text']=' ' + bu9['text']=' ' + bu1.state(['!disabled']) + bu2.state(['!disabled']) + bu3.state(['!disabled']) + bu4.state(['!disabled']) + bu5.state(['!disabled']) + bu6.state(['!disabled']) + bu7.state(['!disabled']) + bu8.state(['!disabled']) + bu9.state(['!disabled']) + +#after getting result(win or loss or draw) disable button +def disableButton(): + bu1.state(['disabled']) + bu2.state(['disabled']) + bu3.state(['disabled']) + bu4.state(['disabled']) + bu5.state(['disabled']) + bu6.state(['disabled']) + bu7.state(['disabled']) + bu8.state(['disabled']) + bu9.state(['disabled']) + + +def ButtonClick(id): + global a,b,c + print("ID:{}".format(id)) + + #for player 1 turn + if id==1 and bu1['text']==' ' and a==1: + bu1['text']="X" + a=0 + b+=1 + if id==2 and bu2['text']==' ' and a==1: + bu2['text']="X" + a=0 + b+=1 + if id==3 and bu3['text']==' ' and a==1: + bu3['text']="X" + a=0 + b+=1 + if id==4 and bu4['text']==' ' and a==1: + bu4['text']="X" + a=0 + b+=1 + if id==5 and bu5['text']==' ' and a==1: + bu5['text']="X" + a=0 + b+=1 + if id==6 and bu6['text']==' ' and a==1: + bu6['text']="X" + a=0 + b+=1 + if id==7 and bu7['text']==' ' and a==1: + bu7['text']="X" + a=0 + b+=1 + if id==8 and bu8['text']==' ' and a==1: + bu8['text']="X" + a=0 + b+=1 + if id==9 and bu9['text']==' ' and a==1: + bu9['text']="X" + a=0 + b+=1 + #for player 2 turn + if id==1 and bu1['text']==' ' and a==0: + bu1['text']="O" + a=1 + b+=1 + if id==2 and bu2['text']==' ' and a==0: + bu2['text']="O" + a=1 + b+=1 + if id==3 and bu3['text']==' ' and a==0: + bu3['text']="O" + a=1 + b+=1 + if id==4 and bu4['text']==' ' and a==0: + bu4['text']="O" + a=1 + b+=1 + if id==5 and bu5['text']==' ' and a==0: + bu5['text']="O" + a=1 + b+=1 + if id==6 and bu6['text']==' ' and a==0: + bu6['text']="O" + a=1 + b+=1 + if id==7 and bu7['text']==' ' and a==0: + bu7['text']="O" + a=1 + b+=1 + if id==8 and bu8['text']==' ' and a==0: + bu8['text']="O" + a=1 + b+=1 + if id==9 and bu9['text']==' ' and a==0: + bu9['text']="O" + a=1 + b+=1 + + #checking for winner + if( bu1['text']=='X' and bu2['text']=='X' and bu3['text']=='X' or + bu4['text']=='X' and bu5['text']=='X' and bu6['text']=='X' or + bu7['text']=='X' and bu8['text']=='X' and bu9['text']=='X' or + bu1['text']=='X' and bu4['text']=='X' and bu7['text']=='X' or + bu2['text']=='X' and bu5['text']=='X' and bu8['text']=='X' or + bu3['text']=='X' and bu6['text']=='X' and bu9['text']=='X' or + bu1['text']=='X' and bu5['text']=='X' and bu9['text']=='X' or + bu3['text']=='X' and bu5['text']=='X' and bu7['text']=='X'): + disableButton() + c=1 + tkinter.messagebox.showinfo("Tic Tac Toe","Winner is player 1") + elif( bu1['text']=='O' and bu2['text']=='O' and bu3['text']=='O' or + bu4['text']=='O' and bu5['text']=='O' and bu6['text']=='O' or + bu7['text']=='O' and bu8['text']=='O' and bu9['text']=='O' or + bu1['text']=='O' and bu4['text']=='O' and bu7['text']=='O' or + bu2['text']=='O' and bu5['text']=='O' and bu8['text']=='O' or + bu3['text']=='O' and bu6['text']=='O' and bu9['text']=='O' or + bu1['text']=='O' and bu5['text']=='O' and bu9['text']=='O' or + bu3['text']=='O' and bu5['text']=='O' and bu7['text']=='O'): + disableButton() + c=1 + tkinter.messagebox.showinfo("Tic Tac Toe","Winner is player 2") + elif b==9: + disableButton() + c=1 + tkinter.messagebox.showinfo("Tic Tac Toe","Match is Draw.") + + if a==1 and c==0: + playerturn['text']=" Player 1 turn! " + elif a==0 and c==0: + playerturn['text']=" Player 2 turn! " + +root.mainloop() +