我正在为一个班级作业做一个Tictakoe游戏,有些地方我被困了,需要一些帮助…游戏应该能够在网格中绘制Xs和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")
我下一步要做的就是这样。在
我接受了代码,使之生效,并想出了下一步该怎么做。 我要做的第一件事是使用}制作}。同时,修复你的缩进,这将抛出几个错误,并添加
Turtle()
函数设置一个板。我将使用Turtle.ht()
隐藏海龟,然后画线,并计算出每个正方形所在的区域。使用if循环,生成“button”或空格,如果按下,将是X
或O
。 然后使用Turtle.forward()
、Turtle.right()
、Turtle.back()
、和{X
和{from turtle import *
。在相关问题 更多 >
编程相关推荐