Skip to content

Instantly share code, notes, and snippets.

@Larseda
Created December 17, 2015 17:27
Show Gist options
  • Select an option

  • Save Larseda/c0da48a3354479dcef24 to your computer and use it in GitHub Desktop.

Select an option

Save Larseda/c0da48a3354479dcef24 to your computer and use it in GitHub Desktop.
Spiel #2
from turtle import *
from random import randint
def gestalte_spielfiguren():
register_shape("hero.gif")
register_shape("block.gif")
block.shape("block.gif")
hero.shape("hero.gif")
block.up()
hero.up()
title("Willkommen zum Spiel")
up()
goto(20,130)
write("Fang die Kuh !")
def gestalte_spielfeld():
""" Spielfeld und Figur gestalten """
bgcolor("green")
up()
goto(-10,-10)
down()
goto(110,-10)
goto(110,110)
goto(-10,110)
goto(-10,-10)
hideturtle()
def teste_ziel():
if round(hero.xcor()) == round(block.xcor()) and round(hero.ycor()) == round(block.ycor()):
hero.write("Juhu")
hero.undo()
setze_block()
def teste_spielfeld():
if round(hero.xcor()) < 0 or round(hero.xcor()) > 100:
hero.backward(10)
hero.write("AUA!")
hero.undo()
if round(hero.ycor()) < 0 or round(hero.ycor()) > 100:
hero.backward(10)
hero.write("AUA!")
hero.undo()
def onkey_up():
hero.forward(10)
teste_spielfeld()
teste_ziel()
def onkey_left():
hero.left(90)
def onkey_right():
hero.right(90)
def setze_block():
blockxy = (
randint(0, 10) * 10, # x
randint(0, 10) * 10 # y
)
block.goto(blockxy[0], blockxy[1])
block=Turtle()
hero=Turtle()
gestalte_spielfiguren()
gestalte_spielfeld()
setze_block()
onkey(onkey_up, "Up")
onkey(onkey_left, "Left")
onkey(onkey_right, "Right")
listen()
mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment