-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay23.py
More file actions
83 lines (69 loc) · 2 KB
/
Day23.py
File metadata and controls
83 lines (69 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import time
from turtle import Screen, Turtle
from PIL import Image
from Cars import Cars
from Player import Player
from Scoreboard import Scoreboard
zero = 0
game_over = False
turtle_helper = Turtle()
turtle_helper.penup()
turtle_helper.hideturtle()
turtle_helper.speed("fastest")
screen = Screen()
screen.tracer(zero)
screen.setup(width=600, height=600)
player = Player()
scoreboard = Scoreboard()
scoreboard.update_level()
cars = Cars()
turtle_helper.penup()
turtle_helper.goto(100, 275)
turtle_helper.pencolor("violetred")
turtle_helper.write("Day 23 - Turtle Crossing", align="right", font=("Palatino Linotype", 15, "italic"))
turtle_helper.pendown()
def display_game_over():
"""
Description:
Method to display that the game is over.
"""
turtle_helper.penup()
turtle_helper.goto(-100, zero)
turtle_helper.pencolor("brown2")
turtle_helper.write("GAME OVER!", font=("Courier", 25, "bold"))
def delete_file(file_path):
"""
Description:
Method to delete the file at the given path.
"""
try:
os.remove(file_path)
except FileNotFoundError:
print("File not found")
except PermissionError:
print("You don't have permission to delete this file")
while not game_over:
screen.update()
time.sleep(0.1)
screen.listen()
screen.onkey(player.move_turtle, key="Up")
cars.generate_random_car()
cars.move_cars()
for car in cars.car_list: # To check collision between player and cars.
if player.distance(car) < 25:
game_over = True
display_game_over()
if player.ycor() >= 280: # Indicating level completion.
scoreboard.clear()
scoreboard.update_level()
player.hideturtle()
player = Player()
cars.level_up()
fileName = "Turtle Crossing"
turtle_helper.getscreen().getcanvas().postscript(file=fileName + '.eps')
img = Image.open(fileName + '.eps')
img.save(fileName + '.jpg')
img.close()
delete_file(r"Turtle Crossing.eps")
screen.exitonclick()