所以我一直在设计一个游戏,你必须留在窗口,但我不知道如何在游戏结束时离开窗口。如果你能提供帮助就会很棒。你可以告诉我我是python的新手,所以请不要判断:)
import turtle
points = 0
print("Welcome to Enterio!")
print("You have to use the arrow keys to finish the game!")
print("If you leave the window COMPLETLY than your lose.")
print(" ")
start = input("Start? (y/n) ")
if(start == "y"):
print("Level 1")
wn = turtle.Screen()
wn.bgcolor("lightblue")
player = turtle.Turtle()
player.color("black")
player.shape("triangle")
speed = 1
while(True):
if(points == 10):
speed += 5
print("Level 2")
elif(points == 20):
speed += 5
print("Level 3")
elif(points == 30):
print("You Win!")
end = input("")
player.penup()
player.forward(speed)
def right():
player.right(90)
def left():
player.left(90)
def lvlup():
global speed
speed += 1
global points
points += 1
if(points > 1):
print("You have", points, "points")
else:
print("You have", points, "point.")
turtle.listen()
turtle.onkey(left, "Left")
turtle.onkey(right, "Right")
turtle.onkey(lvlup, "Up")
elif(start == "n"):
print("Ok, bye!")
pause = input("")
答案 0 :(得分:1)
这里有一些代码,以便您了解它是如何工作的。
import turtle
pointer = turtle.Turtle() # Create a turtle.
w = turtle.window_width () # | Get our window dimensions.
h = turtle.window_height() # }
w, h = w // 2, h // 2 # Divide by two, because we start at (0, 0).
while True:
x, y = turtle.pos() # Get x, y positions.
if abs(x) > w or abs(y) > h: # Check if we are not outside of the window.
turtle.bye() # Kill the turtle. ;(
turtle.forward(5) # Move.