Turtle onscreenclick不按预期运行

时间:2018-02-19 15:49:12

标签: python turtle-graphics

我正在尝试创建一个基本的海龟竞赛。我唯一的要求是每次点击屏幕时乌龟必须移动。我试图使用onscreenclick调用一个函数,将海龟向前移动一个随机数量,然后检查它们的x坐标以确定是否有人赢了。

import turtle
import random
import time

def raceRound():
    firstRacer.forward(random.randint(1, 10))
    secondRacer.forward(random.randint(1, 10))
    checkWinner()


def firstRacerSetup():
    # setup turtle

def secondRacerSetup():
    # set up second turtle

def screenSetup():
    # create screen
def checkWinner():
    if firstRacer.xcor() >= 80:
        announcer.write("Congratualtions! You won!")
    if secondRacer.xcor() >= 80:
        announcer.write("Sorry... You lost")

wn = turtle.Screen()
racerName = wn.textinput("Name Entry", "What would you like your turtle's name to be?")
screenSetup()

announcer = turtle.Turtle()
announcer.hideturtle()
announcer.penup()
announcer.goto(0, -140)
announcer.write("Welcome to the race!", align='center')
time.sleep(3)

firstRacerSetup()
secondRacerSetup()
announcer.write("Click to start the race!", align='center')

wn.onscreenclick(raceRound)
turtle.done()

我只是不确定我哪里出错了,一​​些帮助将不胜感激

0 个答案:

没有答案