-
Notifications
You must be signed in to change notification settings - Fork 50
/
endScreen.py
85 lines (68 loc) · 3.15 KB
/
endScreen.py
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
84
85
import random as rand
import string
from startScreen import *
from globals import *
# game end screen function
def game_end(screen, clock, background_color, player_name):
celeb_text = pygame.font.Font(os.path.join(auxDirectory, 'MR ROBOT.ttf'), 140)
large_text = pygame.font.Font('freesansbold.ttf', 45)
small_text = pygame.font.Font('freesansbold.ttf', 30)
while True:
# to smoothly shine winning message
delay = 0
screen.fill(background_color)
# set flashing colors
color_x = rand.randint(0, 4)
color_y = rand.randint(0, 1)
# Get inputs
mouse_pos = pygame.mouse.get_pos()
mouse_press = pygame.mouse.get_pressed()
for event in pygame.event.get():
# Press R to reset game
if event.type == pygame.KEYDOWN and event.key == pygame.K_r:
return 1
# Press M to go to menu
elif event.type == pygame.KEYDOWN and event.key == pygame.K_m:
return 2
# Press esc or Q to quit
elif event.type == pygame.KEYDOWN and (event.key == pygame.K_q or event.key == pygame.K_ESCAPE):
pygame.quit()
sys.exit()
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# print which player won
if delay == 0:
disp_text(screen, "{0} WINS".format(string.upper(player_name)), (width / 2, height / 2 - 150),
celeb_text, colors[color_x][color_y])
# Drawing buttons for reset, menu and exit.
# Reset button
if abs(mouse_pos[0] - 200) < buttonRadius and abs(mouse_pos[1] - 470) < buttonRadius:
button_circle(screen, colors[0][0], (200, 470), "Reset", large_text, (255, 255, 255),
(width / 2 - 400, height / 2 + 170))
if mouse_press[0] == 1:
return 1
else:
button_circle(screen, colors[0][0], (200, 470), "Reset", small_text, (255, 255, 255),
(width / 2 - 400, height / 2 + 170))
# Menu button
if abs(mouse_pos[0] - 600) < buttonRadius and abs(mouse_pos[1] - 470) < buttonRadius:
button_circle(screen, colors[4][1], (600, 470), "Menu", large_text, (255, 255, 255),
(width / 2, height / 2 + 170))
if mouse_press[0] == 1:
return 2
else:
button_circle(screen, colors[4][1], (600, 470), "Menu", small_text, (255, 255, 255),
(width / 2, height / 2 + 170))
# quit button
if abs(mouse_pos[0] - 1000) < buttonRadius and abs(mouse_pos[1] - 470) < buttonRadius:
button_circle(screen, colors[1][1], (1000, 470), "Quit", large_text, (255, 255, 255),
(width / 2 + 400, height / 2 + 170))
if mouse_press[0] == 1:
pygame.quit()
return 3
else:
button_circle(screen, colors[1][0], (1000, 470), "Quit", small_text, (255, 255, 255),
(width / 2 + 400, height / 2 + 170))
pygame.display.update()
clock.tick(10)