如何设置计分板和“游戏结束”屏幕我的游戏?

问题描述

所以我正在为一个学校项目编写这个游戏,但我遇到了一些问题。我也不擅长编码,所以问题可能有明显的修复

问题是记分牌到处都是。 “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 (将#修改为@)