【发布时间】:2018-05-27 03:41:08
【问题描述】:
所以我对 python 还是很陌生,并试图通过制作小项目来学习。 我正在制作的游戏旨在通过创建一堆随机圆圈来测试您的鼠标准确性,玩家要在给定的时间内单击这些圆圈。在游戏结束时,它应该告诉玩家他们的得分,以及他们有多少次点击错误。
我一直在使用乌龟来尝试这样做,但我被卡住了:
import turtle
import random
t = turtle.Pen()
win = turtle.Screen()
win.bgcolor("lightgreen")
win.title("clicky")
def mycircle(red, green, blue):
t.color(red, green, blue)
t.begin_fill()
x = random.randint(10,50)
t.circle(x)
t.end_fill()
t.up()
y = random.randint(0,360)
t.seth(y)
if t.xcor() < -300 or t.xcor() > 300:
t.goto(0, 0)
elif t.ycor() < -300 or t.ycor() > 300:
t.goto(0, 0)
z = random.randint(0,100)
t.forward(z)
t.down()
for i in range(0, 20):
a = random.randint(0,100)/100.0
b = random.randint(0,100)/100.0
c = random.randint(0,100)/100.0
mycircle(a, b, c)
我一直试图弄清楚的主要问题是:
如何使生成的圆圈彼此远离?它们重叠 经常发生,我希望避免这种情况。
如何让圆圈立即生成而不是必须 画了吗?
【问题讨论】:
标签: python python-3.x turtle-graphics