Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 只有我的tic tac toe程序中的圆圈移动_Python - Fatal编程技术网

Python 只有我的tic tac toe程序中的圆圈移动

Python 只有我的tic tac toe程序中的圆圈移动,python,Python,下面的代码是tic-tac-toe Python游戏的开始。我做了两只乌龟,一只用来做十字架,一只用来做圆圈,但即使在条件满足的情况下,十字架乌龟似乎也不动 import turtle clickCount=0 turtle.setup(750,750) wn=turtle.Screen() grid=turtle.Turtle() grid.speed(15) grid.pensize(10) grid.penup() grid.goto(-300,-300) grid.pendown()

下面的代码是tic-tac-toe Python游戏的开始。我做了两只乌龟,一只用来做十字架,一只用来做圆圈,但即使在条件满足的情况下,十字架乌龟似乎也不动

import turtle 

clickCount=0
turtle.setup(750,750)
wn=turtle.Screen()
grid=turtle.Turtle()
grid.speed(15)
grid.pensize(10)
grid.penup()
grid.goto(-300,-300)
grid.pendown()
grid.goto(-300,300)
grid.goto(300,300)
grid.goto(300,-300)
grid.goto(-300,-300)
grid.goto(-300,-100)
grid.goto(300,-100)
grid.goto(300,100)
grid.goto(-300,100)   
grid.penup()
grid.goto(-100,300)
grid.pendown()
grid.goto(-100,-300)
grid.goto(100,-300)
grid.goto(100,300)


cross=turtle.Turtle()
cross.penup()
circle=turtle.Turtle()
circle.shape("circle")
circle.penup()


def clickthingy(x,y): 
    clickCount=0

    if x>-300 and x<-100:
        if y>100 and y<300:
            if clickCount%2==0:
                circle.goto(-200,200)
                clickCount=clickCount+1
            else:
                cross.goto(-200,200)
                clickCount=clickCount+1
        if y<100 and y>-100:
            if clickCount%2==0:
                circle.goto(-200,0)
                clickCount=clickCount+1
            else:
                cross.goto(-200,0)
                clickCount=clickCount+1
        if y<-100 and y>-300:
            if clickCount%2==0:
                circle.goto(-200,-200)
                clickCount=clickCount+1
            else:
                cross.goto(-200,-200)
                clickCount=clickCount+1         

   if x>-100 and x<100:
    if y>100 and y<300:
        if clickCount%2==0:
            circle.goto(0,200)
            clickCount=clickCount+1
        else:
            cross.goto(0,200)
            clickCount=clickCount+1
    if y<100 and y>-100:
        if clickCount%2==0:
            circle.goto(0,0)
            clickCount=clickCount+1
        else:
            cross.goto(0,0)
            clickCount=clickCount+1
    if y<-100 and y>-300:
        if clickCount%2==0:
            circle.goto(0,-200)
            clickCount=clickCount+1
        else:
            cross.goto(0,-200)
            clickCount=clickCount+1   

    if x>100 and x<300:
        if y>100 and y<300:
            if clickCount%2==0:
                circle.goto(200,200)
                clickCount=clickCount+1
            else:
                cross.goto(200,200)
                clickCount=clickCount+1
        if y<100 and y>-100:
            if clickCount%2==0:
                circle.goto(200,0)
                clickCount=clickCount+1
            else:
                cross.goto(200,0)
                clickCount=clickCount+1
            if y<-100 and y>-300:
                if clickCount%2==0:
                    circle.goto(200,-200)
                    clickCount=clickCount+1
                else:
                    cross.goto(200,-200)
                    clickCount=clickCount+1   

wn.onclick(clickthingy)
wn.listen()
wn.mainloop()
导入海龟
单击计数=0
海龟。设置(750750)
wn=tutle.Screen()
grid=turtle.turtle()
网格速度(15)
网格。养老金(10)
grid.penup()
网格.转到(-300,-300)
grid.pendown()
网格。转到(-300300)
网格。转到(300300)
网格。转到(300,-300)
网格.转到(-300,-300)
网格。转到(-300,-100)
网格。转到(300,-100)
网格。转到(300100)
网格。转到(-300100)
grid.penup()
网格。转到(-100300)
grid.pendown()
网格。转到(-100,-300)
网格。转到(100,-300)
网格。转到(100300)
克罗斯=乌龟。乌龟()
十字形
圆圈=海龟。海龟()
圆。形状(“圆”)
circle.penup()
def单击内容y(x,y):
单击计数=0

如果x>-300和x100以及y-100和x100以及y100和x100以及y,则每次单击都将
clickCount
变量重置为零。将其改为全局变量:

clickCount = 0

def clickthingy(x,y): 
    global clickCount
    ....
免责声明:虽然这将使它工作,但它通常被认为是horible风格。尝试重组你的计划(正如yurib和That1Guy的评论所建议的那样)


这段代码不可读。把它分解成函数,试着缩小问题的范围,并发布最小的相关代码。虽然你的建议会起作用,但这是一个糟糕的解决方案<代码>单击计数
应该是对象上的属性<代码>全局几乎总是个坏主意。我完全同意。添加了一个免责声明。