如何将对象的速度提高到游戏中的水平?

发布于 2025-02-03 17:55:57 字数 1553 浏览 3 评论 0原文

在我的代码(用于游戏的代码)中,我想每次达到一定量的点击和级别时都会提高随机移动对象的速度(我称之为squidward)。但是,我的功能不起作用。我认为功能本身是有道理的,也许我忘了添加一些东西,但是,我几次都看了一下,但是在这一点上,我不知道为了解决它,我还能做些什么。

这是我的代码:

import turtle 
from tkinter import* 
from random import randint 


# set up 
win =  turtle.Screen()
win.title("Squid-game")
win.bgcolor("black")
win.register_shape("squid_big.gif") 

# variabelen 
clicks = -1 
level = 1 
Speed = 1


  
 
# dem Turtle-objekt in Thadäus formen 
squidward = turtle.Turtle()
squidward.shape("squid_big.gif")
squidward.penup()
squidward.speed(Speed)


def Speed():
     global Speed, level, clicks 
     if level == 1 and clicks == 5: 
          level += 1  
          Speed += 1 
     if level == 2 and clicks == 10: 
          level += 1 
          Speed += 5 
     if level == 3 and clicks == 15: 
          level += 1 
          Speed += 2 
          squidward.speed(Speed)

squidward.onclick(Speed())

# zeigt an wie viele Clicks man hat 
pen = turtle.Turtle()
pen.hideturtle()
pen.color("white")
pen.penup 
pen.goto(0, 400)
pen.write (f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))

# Funtion für das Clicken und den random Bewegung 
def clicked (x,y): 
     global clicks 
     clicks += 1 
     pen.clear() 
     pen.write (f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))
     while TRUE:  squidward.goto(randint(-1200, 1200), randint(-1200, 1200)) 

# die Geschwindigkeit muss ich ab einer bestimmten Aazahl bis 10 steigen// Level-up 


squidward.onclick(clicked)

win.mainloop() 

in my code, which is for a game, I want to increase the speed of my randomly moving object ( here I call it squidward ) every time a certain amount of clicks and level is reached. However, my function is not working. I think the function itself makes sense and maybe I forgot to add something, however, I looked over it several times, but at this point I don't know what else I could possibly do in order to fix it.

Here is my code:

import turtle 
from tkinter import* 
from random import randint 


# set up 
win =  turtle.Screen()
win.title("Squid-game")
win.bgcolor("black")
win.register_shape("squid_big.gif") 

# variabelen 
clicks = -1 
level = 1 
Speed = 1


  
 
# dem Turtle-objekt in Thadäus formen 
squidward = turtle.Turtle()
squidward.shape("squid_big.gif")
squidward.penup()
squidward.speed(Speed)


def Speed():
     global Speed, level, clicks 
     if level == 1 and clicks == 5: 
          level += 1  
          Speed += 1 
     if level == 2 and clicks == 10: 
          level += 1 
          Speed += 5 
     if level == 3 and clicks == 15: 
          level += 1 
          Speed += 2 
          squidward.speed(Speed)

squidward.onclick(Speed())

# zeigt an wie viele Clicks man hat 
pen = turtle.Turtle()
pen.hideturtle()
pen.color("white")
pen.penup 
pen.goto(0, 400)
pen.write (f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))

# Funtion für das Clicken und den random Bewegung 
def clicked (x,y): 
     global clicks 
     clicks += 1 
     pen.clear() 
     pen.write (f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))
     while TRUE:  squidward.goto(randint(-1200, 1200), randint(-1200, 1200)) 

# die Geschwindigkeit muss ich ab einer bestimmten Aazahl bis 10 steigen// Level-up 


squidward.onclick(clicked)

win.mainloop() 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您的问题是您只定义了一次乌龟的速度。相反,您应该像这样重置每个级别;

    def Speed():
         global Speed, level, clicks, squidward 
         if level == 1 and clicks == 5: 
              level += 1  
              Speed += 1 

         if level == 2 and clicks == 10: 
              level += 1 
              Speed += 5 

         if level == 3 and clicks == 15: 
              level += 1 
              Speed += 2 
         squidward.speed(Speed)

此外,随着它进入无限循环,clicked()函数永远不会结束

Your problem comes in that you only define the speed of the turtle once. Instead you should reset the speed every level like so;

    def Speed():
         global Speed, level, clicks, squidward 
         if level == 1 and clicks == 5: 
              level += 1  
              Speed += 1 

         if level == 2 and clicks == 10: 
              level += 1 
              Speed += 5 

         if level == 3 and clicks == 15: 
              level += 1 
              Speed += 2 
         squidward.speed(Speed)

In addition, the clicked() function is never ended as it goes into an infinite loop

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文