Def Def内的ScoreBored

时间:2019-12-03 19:46:16

标签: python

我正在尝试用Python做一个记分牌。当我单击乌龟时,它会增加一个点,但是我必须单击才能做其他事情。我试图使其成为当您单击Banna时,它会为您的分数增加1分。

代码如下:

import turtle
import random

def on_click(x,y):
    Banna.hideturtle()
    x = random.randint(-230, 230)
    y = random.randint(-150, 150)
    Banna.setposition(int(x), int(y))
    Banna.showturtle()

def stop():
   exit()

bw = turtle.Screen()

bw.bgcolor('black')
bw.title('Banna Game')

border_line = turtle.Turtle()
border_line.color('white')
border_line.penup()
border_line.speed(90)
border_line.setposition(-250, -200)
border_line.width(4)
border_line.pendown()
border_line.forward(500)
border_line.left(90)
border_line.forward(400)
border_line.left(90)
border_line.forward(500)
border_line.left(90)
border_line.forward(400)
border_line.hideturtle()

# Banna

Banna = turtle.Turtle()
Banna.shape('triangle')
Banna.color('yellow')
Banna.penup()
Banna.onclick(on_click)

# Game Keys

turtle.listen()
turtle.onkey(stop, 'e')

bw.mainloop()

0 个答案:

没有答案