How to Create a XO Game using python ? | python

Pubblicato il: 03 dicembre 2021
sul canale di: House Of Dispute*
74
4

Source Code:


from turtle import *

from freegames import line


def grid():
"Draw tic-tac-toe grid."
line(-67, 200, -67, -200)
line(67, 200, 67, -200)
line(-200, -67, 200, -67)
line(-200, 67, 200, 67)


def drawx(x, y):
"Draw X player."
line(x, y, x + 133, y + 133)
line(x, y + 133, x + 133, y)


def drawo(x, y):
"Draw O player."
up()
goto(x + 67, y + 5)
down()
circle(62)


def floor(value):
"Round value down to grid with square size 133."
return ((value + 200) // 133) * 133 - 200


state = {'player': 0}
players = [drawx, drawo]


def tap(x, y):
"Draw X or O in tapped square."
x = floor(x)
y = floor(y)
player = state['player']
draw = players[player]
draw(x, y)
update()
state['player'] = not player


setup(420, 420, 370, 0)
hideturtle()
tracer(False)
grid()
update()
onscreenclick(tap)
done()


In questa pagina del sito puoi guardare il video online How to Create a XO Game using python ? | python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato House Of Dispute* 03 dicembre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 74 volte e gli è piaciuto 4 spettatori. Buona visione!