我正在制作一个TicTacToe游戏进行课堂作业,有些地方我被卡住并且可以使用一些帮助...游戏应该能够在网格中绘制X和Os并执行完整游戏 这是我的代码
import turtle
import math
import random
cellSize = 100
turtleWidth =10
gridColor = 'Black'
xColor = 'Blue'
oColor = 'Red'
winColor = 'green'
drawColor = 'Gray'
winninTriples = ((0,1,2)
def onclick(x, y):
print x, y
turtle.Screen().onscreenclick(onclick)
#the grid is here
def drawGrid(pen, length, xcoor, ycoor):
startX = [xcoor,xcoor,xcoor+length, xcoor+(2*length)]
endX = [xcoor+(3*length), xcoor+(3*length), xcoor+(length),xcoor+(2*length)]
startY = [ycoor+(2*length),ycoor+length, ycoor, ycoor]
endY = [ycoor+(2*length), ycoor+length, ycoor+(3*length),ycoor+(3*length)]
for grid in range(4):
p.up()
p.goto(startX[grid],startY[grid])
p.down()
p.goto(endX[grid],endY[grid])
pen = turtle.Turtle()
pen.width(5)
drawGrid(pen,100,-40,-50)
board = [0,1,2,
3,4,5,
6,7,8]
def theWinnner(grid0,grid1,grid2,grid3,grid4,grid5,grid6,grid7,grid8):
X = 'X wins'
O = 'O wins'
No = 'Draw'
#this was a code that was given, I am supposed to add on to it and I am not sure how it can be modified and what should I put as the parameters when executing it?
def drawX(t,x,y,size):
drawLine(t, x + size/4, y + size/4, x - size/4, y - size/4)
drawLine(t, x - size/4, y + size/4, x + size/4, y - size/4)
def drawO(t,x,y,size):
t.cirle(size)
def Move():
y = input("Please choose a row:")
x = input("Now please choose a column:")
if x in ['0','1','2'] and y in ['0','1','2']:
return("Your destination is " + y + " " + "and " + x)
else:
return("One or more of your dimensions is out of bounds")
这是我迄今为止所做的工作,关于下一步做什么,我有点迷茫。
答案 0 :(得分:0)
我拿了代码,让它工作,并想出下一步该做什么。
我要做的第一件事就是使用Turtle()
函数设置一个电路板。我会使用Turtle.ht()
隐藏乌龟,然后制作线条,并找出每个方格所在的区域。使用if循环,制作'按钮'或者如果按下,则为X
或O
的空格。
然后使用Turtle.forward()
,Turtle.right()
,Turtle.back()
和Turtle.left()
制作X
和O
&#39。另外,修复您的缩进,这会产生多个错误,并添加from turtle import *
。