如何解决如何设置计分板和“游戏结束”屏幕我的游戏?
所以我正在为一个学校项目编写这个游戏,但我遇到了一些问题。我也不擅长编码,所以问题可能有明显的修复
问题是记分牌到处都是。 “score”这个词出现了,但是在吃掉这些点之后,数字没有增加,数字0被卡在它下面。我希望将数字(即分数)和“分数”一词放在一起,但不知道该怎么做。 这一切都发生在 def start1()
我知道这很多,但我真的很迷茫,希望得到帮助。谢谢
from turtle import Turtle,Screen
from random import randrange
import turtle
pen= turtle.Turtle()
wn = turtle.Screen()
FRAMES_PER_SECOND = 10
WIDTH,HEIGHT = 500,500
STAMP_SIZE = 20
DOT_SIZE = 10
def turnRight():
screen.onkey(None,'Right')
turtle.right(45)
screen.onkey(turnRight,'Right')
def turnLeft():
screen.onkey(None,'Left')
turtle.left(45)
screen.onkey(turnLeft,'Left')
def dotGood(food):
x = randrange(DOT_SIZE - WIDTH // 2,WIDTH // 2 - DOT_SIZE)
y = randrange(DOT_SIZE - HEIGHT // 2,HEIGHT // 2 - DOT_SIZE)
food.goto(x,y)
return ((x,y),food.stamp())
def eaten(food):
global dot
((x,stamp_id) = dot
if abs(turtle.xcor() - x) < DOT_SIZE and abs(turtle.ycor() - y) < DOT_SIZE:
food.clearstamp(stamp_id)
dot = dotGood(food)
return True
return False
def increase_speed():
if eaten(food) == True:
speed = speed + 2
def move():
global score
if not moving:
return
if eaten(food):
score += 1
turtle.shapesize((STAMP_SIZE + 5 * score) / STAMP_SIZE)
turtle.forward(1)
screen.ontimer(move,10 // FRAMES_PER_SECOND)
xcor = turtle.xcor()
ycor = turtle.ycor()
print(xcor,ycor)
if ycor < -250:
print("out") #this is to help me see that the computer kNows when the turtle goes out of boundaries
game_over()
if ycor > 250:
print("out")
game_over()
if xcor > 250:
print("out")
game_over()
if xcor < -250:
print("out")
game_over()
def game_over():
turtle.clear()
wn.bgcolor("green")
#turtle.write("GAME OVER",move=False,align="center",font=("Arial",40,"bold"))
def start1():
global moving
moving = True
move()
turtle.write("score: ",30,"bold"))
turtle.write(score,"bold"))
def stop():
global moving
moving = False
screen = Screen()
screen.setup(WIDTH,HEIGHT)
screen.bgcolor('black')
turtle = Turtle(shape='turtle')
turtle.speed("slowest")
turtle.color('green')
turtle.penup()
food = Turtle(shape='circle',visible=False)
food.speed('fastest')
food.turtlesize(DOT_SIZE / STAMP_SIZE)
food.color('red')
food.penup()
# globals
moving = False
dot = dotGood(food)
score = 0
screen.onkey(turnRight,'Right')
screen.onkey(turnLeft,'Left')
screen.onkey(start1,'Up')
screen.onkey(stop,'Down')
screen.listen()
screen.mainloop()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。