Skip to content

Commit db33ebb

Browse files
Update Day-19
1 parent 301f092 commit db33ebb

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

Day-19-TurtleHurdle/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Turtle-Hurdle
2+
3+
### An implementation of Turtle-Hurdle.
4+
5+
<img src= 'https://user-images.githubusercontent.com/65078610/105209379-c3d5d380-5b6f-11eb-9d67-a4c0fe8e3cc7.gif' width="500">

Day-19-TurtleHurdle/etch-a-sketch.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from turtle import Turtle,Screen
2+
3+
tim = Turtle()
4+
screen = Screen()
5+
6+
tim.shape('turtle')
7+
tim.color('SeaGreen')
8+
9+
def move_forwards():
10+
tim.forward(10)
11+
def move_down():
12+
tim.backward(10)
13+
def move_left():
14+
tim.left(10)
15+
def move_right():
16+
tim.right(10)
17+
def clear():
18+
tim.clear()
19+
tim.penup()
20+
tim.home()
21+
tim.pendown()
22+
screen.onkey(move_forwards,"Up")
23+
screen.onkey(move_down,"Down")
24+
screen.onkey(move_left,"Left")
25+
screen.onkey(move_right,"Right")
26+
screen.onkey(clear,"c")
27+
# Adding event listener
28+
screen.listen()
29+
screen.exitonclick()

Day-19-TurtleHurdle/main.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from turtle import Turtle,Screen
2+
import random
3+
4+
screen = Screen()
5+
# Setup width & height of screen
6+
screen.setup(width=500,height=400)
7+
8+
colors = ['red','orange','yellow','green','blue','purple']
9+
turtles_obj = []
10+
for i in range(6):
11+
tim = Turtle(shape='turtle')
12+
turtles_obj.append(tim)
13+
tim.penup()
14+
tim.color(colors[i])
15+
16+
race = 'yes'
17+
while race=='yes':
18+
# Set all turtles to start position
19+
for index,y in enumerate(range(-75,76,30)):
20+
turtles_obj[index].goto(-200,y)
21+
22+
# Take user input for turtle bet
23+
user_bet = screen.textinput(title="Make your bet", prompt="Which turtle will win the race? Enter a color: ")
24+
if user_bet:
25+
race_on = True
26+
27+
while race_on:
28+
for turtle in turtles_obj:
29+
if turtle.xcor() > 230:
30+
if user_bet in turtle.pencolor():
31+
race = screen.textinput(title="Race again?", prompt=f"You've won! The {turtle.pencolor()} turtle is the winner!\n Race again? yes/no: ")
32+
else:
33+
race = screen.textinput(title="Race again?", prompt=f"You've lost! The {turtle.pencolor()} turtle is the winner!\n Race again? yes/no: ")
34+
race_on = False
35+
distance = random.randint(0,10)
36+
turtle.forward(distance)
37+
38+
# Adding event listener
39+
screen.listen()
40+
screen.exitonclick()

0 commit comments

Comments
 (0)