Загрузка данных
import turtle
import random
import time
screen = turtle.Screen()
screen.title("Flugzeug-Abenteuer")
screen.bgcolor("skyblue")
screen.setup(700, 500)
screen.tracer(0)
# Form des Flugzeugs (Nase zeigt nach vorne)
turtle.register_shape("flugzeug", (
(0, 20), (4, 8), (22, -4), (22, -9), (4, -5), (3, -14), (10, -20),
(10, -24), (0, -20), (-10, -24), (-10, -20), (-3, -14), (-4, -5),
(-22, -9), (-22, -4), (-4, 8)))
flieger = turtle.Turtle()
flieger.shape("flugzeug")
flieger.color("black", "red")
flieger.penup()
flieger.goto(-250, 0)
text = turtle.Turtle()
text.hideturtle()
text.penup()
text.color("black")
stufe = 0
punkte = 0
leben = 3
def waehle_leicht():
global stufe
stufe = 1
def waehle_mittel():
global stufe
stufe = 2
def waehle_schwer():
global stufe
stufe = 3
def hoch():
if flieger.ycor() < 210:
flieger.sety(flieger.ycor() + 25)
def runter():
if flieger.ycor() > -210:
flieger.sety(flieger.ycor() - 25)
def vor():
if flieger.xcor() < 0:
flieger.setx(flieger.xcor() + 25)
def zurueck():
if flieger.xcor() > -300:
flieger.setx(flieger.xcor() - 25)
screen.listen()
screen.onkeypress(waehle_leicht, "1")
screen.onkeypress(waehle_mittel, "2")
screen.onkeypress(waehle_schwer, "3")
screen.onkeypress(hoch, "Up")
screen.onkeypress(runter, "Down")
screen.onkeypress(vor, "Right")
screen.onkeypress(zurueck, "Left")
# Start: Schwierigkeit waehlen
text.goto(0, 60)
text.write("FLUGZEUG-ABENTEUER", align="center", font=("Arial", 26, "bold"))
text.goto(0, 0)
text.write("Waehle: 1 = leicht 2 = mittel 3 = schwer",
align="center", font=("Arial", 16, "normal"))
text.goto(0, -40)
text.write("Pfeiltasten: hoch, runter, vor, zurueck",
align="center", font=("Arial", 14, "normal"))
while stufe == 0:
screen.update()
time.sleep(0.05)
if stufe == 1:
name = "leicht"
basis = 4
anzahl = 3
groesse = 1.5
elif stufe == 2:
name = "mittel"
basis = 6
anzahl = 4
groesse = 2
else:
name = "schwer"
basis = 8
anzahl = 5
groesse = 2.5
wolken = []
for i in range(anzahl):
wolke = turtle.Turtle()
wolke.shape("circle")
wolke.color("dimgray")
wolke.shapesize(groesse)
wolke.penup()
wolke.goto(random.randint(380, 900), random.randint(-200, 200))
wolken.append(wolke)
def zeige():
text.clear()
text.goto(0, 215)
zeile = "Stufe: " + name + " Punkte: " + str(punkte) + " Leben: " + str(leben)
text.write(zeile, align="center", font=("Arial", 16, "normal"))
zeige()
while leben > 0:
screen.update()
time.sleep(0.02)
tempo = basis + punkte // 5
for wolke in wolken:
wolke.setx(wolke.xcor() - tempo)
if wolke.xcor() < -380:
punkte = punkte + 1
wolke.goto(random.randint(380, 600), random.randint(-200, 200))
zeige()
elif flieger.distance(wolke) < 16 + 10 * groesse:
leben = leben - 1
wolke.goto(random.randint(380, 600), random.randint(-200, 200))
zeige()
flieger.color("black", "yellow")
screen.update()
time.sleep(0.3)
flieger.color("black", "red")
text.clear()
text.goto(0, 10)
text.write("Spiel vorbei!", align="center", font=("Arial", 30, "bold"))
text.goto(0, -30)
text.write("Stufe " + name + ", Punkte: " + str(punkte),
align="center", font=("Arial", 18, "normal"))
screen.update()
screen.mainloop()