微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么只有一部分 python 海龟函数在工作?

如何解决为什么只有一部分 python 海龟函数在工作?

正在开发带有海龟图形的命令行游戏。我创建了几个不同的函数来执行此操作,包括绘制一个带有复选标记的正方形并在下面打印一个字符串的函数advancement(color,title)

在我最初的测试中,这奏效了。但是,在绘制并清除了其他几张海龟图之后,当我将其向下移动到预期位置时,方块不再显示,但其他所有内容显示

在第 100 行,函数第一次运行时,运行正常,但在第 128 和 199 行,只画了支票,没有画正方形。关于解决此问题的原因或方法有什么想法吗?

代码作为它自己的单独文件运行良好,所以我很困惑。

提前致谢!

import time
import turtle
import math
import random
from colorama import Fore,Style
from deep_translator import GoogleTranslator
from words import word_list
# translated = GoogleTranslator(source='fr',target='en').translate("Bonjour")  # output -> Weiter so,du bist großartig
# print(translated)
# opening setup

screen = turtle.Screen()
sheldon = turtle.Turtle()
screen.bgcolor("black")
sheldon.shape("circle")
sheldon.color("white")
sheldon.speed(10)
sheldon.hideturtle()
def advancement(color,title):
    sheldon.speed(5)
    sheldon.pensize(10)
    sheldon.up()
    sheldon.goto(-150,-150)
    sheldon.color(color)
    sheldon.down()
    screen.tracer(1)
    for advancementSquare in range(4):
         sheldon.forward(300)
         sheldon.left(90)
    sheldon.up()
    sheldon.goto(-100,-30)
    sheldon.pensize(15)
    sheldon.down()
    sheldon.setheading(315)
    sheldon.forward(70)
    sheldon.left(90)
    sheldon.forward(200)
    sheldon.pensize(1)
    sheldon.up()
    sheldon.goto(0,-200)
    sheldon.down()
    screen.update()
    sheldon.write("Advancement Made: " + title,False,align="center",font=("Modern",35))
    sheldon.up()
    screen.update()
    time.sleep(3)
    screen.clearscreen()
    screen.bgcolor("black")
def smallCircle(x,y,color):
    sheldon.up()
    sheldon.speed(0)
    screen.tracer(10)
    sheldon.color(color)
    sheldon.fillcolor(color)
    sheldon.goto(x,y)
    sheldon.down()
    sheldon.begin_fill()
    for circle in range(120):
        sheldon.forward(1)
        sheldon.left(3)
    sheldon.end_fill()
    screen.update()
def smileCurve(x,color):
    sheldon.up()
    sheldon.goto(x,y)
    sheldon.color(color)
    sheldon.down()
    screen.tracer(5)
    sheldon.setheading(180)
    sheldon.pensize(5)
    for curveLeft in range(50):
        sheldon.forward(2)
        sheldon.right(1)
    sheldon.up()
    sheldon.goto(x,y)
    sheldon.setheading(0)
    sheldon.down()
    for curveRight in range(50):
        sheldon.forward(2)
        sheldon.left(1)
    screen.update()
    sheldon.pensize(1)
def loadingScreen(x,color):
    screen.tracer(10)
    sheldon.up()
    sheldon.goto(x,y)
    sheldon.down()
    sheldon.color(color)
    for bar in range(abs(x)):
        sheldon.setheading(90)
        sheldon.forward(5)
        sheldon.right(90)
        sheldon.forward(1)
        sheldon.right(90)
        sheldon.forward(5)
        sheldon.left(90)
        sheldon.forward(1)
    time.sleep(1)

advancement("green","Tutorial Complete!")


smallCircle(-49,50,"white")
smallCircle(51,"white")
smileCurve(0,-40,"white")
time.sleep(3)
screen.clearscreen()
screen.bgcolor("black")

sheldon.up()
sheldon.goto(0,-80)
sheldon.down()
sheldon.write("Loading...",font=("Comic Sans MS",20))
sheldon.up()

loadingScreen(-400,-100,"light blue")

sheldon.up()
sheldon.goto(0,-150)
sheldon.down()
sheldon.write("Complete!",30))
sheldon.up()
screen.update()
time.sleep(1.5)
screen.clearscreen()
screen.bgcolor("black")

advancement("green","Tutorial Complete!")


food = float(100)
health = float(100)
money = float(100)
mood = float(100)
alive = 1

player = input("Please enter your name: ")
print("Welcome," + player + ". In this game,you must make " + Fore.GREEN + "decisions " + Style.RESET_ALL + "to survive.")
time.sleep(2)
firstChoice = int(input("""Let's do an example. Would you rather have a great job [1],great health [2],or cheap food? [3]
Please enter the corresponding number. """))
print("...")
time.sleep(2)

if firstChoice == 1:
    money = money + 30
    mood = mood + 20
elif firstChoice == 2:
    health = health + 50
    mood = mood + 30
elif firstChoice == 3:
    food = food + 70
    money = money +20
    health = health - 10
else:
    print("Wow. You Couldn't even answer the first question. I can't handle bad responses. Note that,in the future,if you respond incorrectly,the game may crash. \n And burn. \n" + Fore.RED + "Violently" + Style.RESET_ALL)
    # add an if statement here to override the incorrect answer statement from later


# Random stat distribution

# stat = 0
# stats = [food,health,money,mood]
# for randomStat in range(4):
#     statEffect = random.randrange(-2,4)
#     newStat = stats[stat] + statEffect

food = food + random.randrange(-20,40)
health = health + random.randrange(-20,40)
money = money + random.randrange(-20,40)
mood = mood + random.randrange(-20,40)


# continuing,one-time intro things

print("Interesting choice - but that wasn't really an example. All of your" + Fore.RED + " actions " + Style.RESET_ALL + "have" + Fore.RED + " consequences." + Style.RESET_ALL)
time.sleep(3.2)
input("Press enter to continue.")
print("I guess I should explain some more. ")
time.sleep(2.5)
print("""In this game,you -""",player,"""- have stats. If these get too low,bad things happen. """)
time.sleep(4)
input("Press enter to continue.")
print("""At the start of each """ + Fore.CYAN + """day,""" + Style.RESET_ALL + """you will be presented with your current stats,as well as your options.""")
time.sleep(3.5)
print("Here are your current stats. These are dependant on your first decision,as well as random chance - just like real life. Generally,100 is a solid baseline.")
time.sleep(3)
#stating initial stats based on choice 1 + random.randrange
print("You currently have\n" + Fore.BLUE + str(food) + Style.RESET_ALL + " food,\n" + Fore.BLUE + str(health) + Style.RESET_ALL + " health,\n"+ Fore.BLUE + str(money) + Style.RESET_ALL + " money,and \n"+ Fore.BLUE + str(mood) + Style.RESET_ALL + " mood.")
time.sleep(3)
input("Press enter to continue.")

print("There are a few other things you should kNow. There are no second chances - if you die,that's it. Always be prepared.")
time.sleep(3)
print("Also,some decisions have their possible answers in [brackets]. Make sure you always insert a valid answer if necessary - if you don't,you may be punished \n or the game may crash. Both of those options make me sad.")
time.sleep(5)
input("Press enter to continue.")

advancement("green","Tutorial Complete!")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。