-
-
Save kraiz/0a4d95b176bdafacc2f6 to your computer and use it in GitHub Desktop.
Python Spiel #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from turtle import * | |
from random import randint | |
shape("turtle") | |
def gestalte_spielfeld(): | |
""" Spielfeld und Figur gestalten """ | |
pass | |
def teste_ziel(): | |
global block | |
print(block) | |
if round(xcor()) == block[0] and round(ycor()) == block[1]: | |
write("Juhu") | |
clear() | |
gestalte_spielfeld() | |
block = erstelle_block() | |
def teste_spielfeld(): | |
if round(xcor()) < 0 or round(xcor()) > 100: | |
backward(10) | |
write("AUA!") | |
undo() | |
if round(ycor()) < 0 or round(ycor()) > 100: | |
backward(10) | |
write("AUA!") | |
undo() | |
def onkey_up(): | |
forward(10) | |
teste_spielfeld() | |
teste_ziel() | |
def onkey_left(): | |
left(90) | |
def onkey_right(): | |
right(90) | |
def erstelle_block(): | |
block = ( | |
randint(0, 10) * 10, # x | |
randint(0, 10) * 10 # y | |
) | |
up() | |
goto(*block) # oder: goto(block[0], block[1]) | |
dot(10) | |
goto(0, 0) | |
return block | |
gestalte_spielfeld() | |
block = erstelle_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