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()
烟花代码python
于 2024-07-22 10:14:21 首次发布