-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
295 lines (254 loc) · 12.2 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import pygame, sys
from UI.HiveGame import HiveGame
from UI.constants import *
from UI.Button import Button
first_player = None
second_player = None
first_player_mode = None
second_player_mode = None
first_player_diff = None
second_player_diff = None
#difficulty menu
def difficulty_menu(player_num):
while True:
SCREEN.blit(BG, (0, 0))
MENU_MOUSE_POS = pygame.mouse.get_pos()
MENU_TEXT = get_font(75).render("Select Difficulty", True, "#b68f40")
MENU_RECT = MENU_TEXT.get_rect(center=(400, 100))
EASY_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 250),
text_input="Easy", font=get_font(65), base_color="#d7fcd4", hovering_color="White")
MEDIUM_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 380),
text_input="Medium", font=get_font(65), base_color="#d7fcd4", hovering_color="White")
HARD_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 510),
text_input="Hard", font=get_font(65), base_color="#d7fcd4", hovering_color="White")
SCREEN.blit(MENU_TEXT, MENU_RECT)
#hovering
for button in [EASY_BUTTON, MEDIUM_BUTTON, HARD_BUTTON]:
button.changeColor(MENU_MOUSE_POS)
button.update(SCREEN)
#events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#mouse click
global first_player_diff, second_player_diff
if event.type == pygame.MOUSEBUTTONDOWN:
#play button click
if EASY_BUTTON.checkForInput(MENU_MOUSE_POS):
if player_num == 1:
first_player_diff = PLAYER_DIFFICULTY_EASY
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
player_menu(2)
return
else:
second_player_diff = PLAYER_DIFFICULTY_EASY
# print("first_player, first_player_diff, second_player, second_player_diff")
# print(first_player, first_player_diff, second_player, second_player_diff)
# print("first_player, first_player_diff, second_player, second_player_diff")
pygame.mixer.music.load('assets/board-start.mp3')
pygame.mixer.music.play(1)
launch()
return
#options button click
if MEDIUM_BUTTON.checkForInput(MENU_MOUSE_POS):
if player_num == 1:
first_player_diff = PLAYER_DIFFICULTY_MEDIUM
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
player_menu(2)
return
else:
second_player_diff = PLAYER_DIFFICULTY_MEDIUM
pygame.mixer.music.load('assets/board-start.mp3')
pygame.mixer.music.play(1)
launch()
return
#quit button click
if HARD_BUTTON.checkForInput(MENU_MOUSE_POS):
if player_num == 1:
first_player_diff = PLAYER_DIFFICULTY_HARD
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
player_menu(2)
return
else:
second_player_diff = PLAYER_DIFFICULTY_HARD
pygame.mixer.music.load('assets/board-start.mp3')
pygame.mixer.music.play(1)
launch()
return
pygame.display.update()
#mode menu
def mode_menu(player_num):
while True:
SCREEN.blit(BG, (0, 0))
MENU_MOUSE_POS = pygame.mouse.get_pos()
Text = "Select AI's Algorithm"
MENU_TEXT = get_font(75).render(Text, True, "#b68f40")
MENU_RECT = MENU_TEXT.get_rect(center=(400, 100))
MINMAX_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 250),
text_input="Min-Max", font=get_font(65), base_color="#d7fcd4", hovering_color="White")
ALPHABETA_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 380),
text_input="Alpha-Beta", font=get_font(65), base_color="#d7fcd4", hovering_color="White")
ITERATIVE_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 510),
text_input="Iterative Deepening", font=get_font(65), base_color="#d7fcd4", hovering_color="White")
SCREEN.blit(MENU_TEXT, MENU_RECT)
#hovering
for button in [MINMAX_BUTTON, ALPHABETA_BUTTON, ITERATIVE_BUTTON]:
button.changeColor(MENU_MOUSE_POS)
button.update(SCREEN)
#events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#mouse click
global first_player_mode, second_player_mode
if event.type == pygame.MOUSEBUTTONDOWN:
#play button click
if MINMAX_BUTTON.checkForInput(MENU_MOUSE_POS):
if player_num == 1:
first_player_mode = AI_MODE_MINMAX
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
difficulty_menu(1)
return
else:
second_player_mode = AI_MODE_MINMAX
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
difficulty_menu(2)
return
#options button click
if ALPHABETA_BUTTON.checkForInput(MENU_MOUSE_POS):
if player_num == 1:
first_player_mode = AI_MODE_ALPHA_BETA
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
difficulty_menu(1)
return
else:
second_player_mode = AI_MODE_ALPHA_BETA
pygame.mixer.music.load('assets/board-start.mp3')
pygame.mixer.music.play(1)
difficulty_menu(2)
return
#quit button click
if ITERATIVE_BUTTON.checkForInput(MENU_MOUSE_POS):
if player_num == 1:
first_player_mode = AI_MODE_ITERATIVE
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
difficulty_menu(1)
return
else:
second_player_mode = AI_MODE_ITERATIVE
pygame.mixer.music.load('assets/board-start.mp3')
pygame.mixer.music.play(1)
difficulty_menu(2)
return
pygame.display.update()
def player_menu(player_num):
while True:
SCREEN.blit(BG, (0, 0))
MENU_MOUSE_POS = pygame.mouse.get_pos()
Text = "Select First Player (white)"
if player_num == 2:
Text = "Select Second Player (black)"
MENU_TEXT = get_font(75).render(Text, True, "#b68f40")
MENU_RECT = MENU_TEXT.get_rect(center=(400, 100))
HUMAN_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 250),
text_input="Human", font=get_font(65), base_color="#d7fcd4", hovering_color="White")
AI_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 400),
text_input="AI", font=get_font(65), base_color="#d7fcd4", hovering_color="White")
SCREEN.blit(MENU_TEXT, MENU_RECT)
#hovering
for button in [HUMAN_BUTTON, AI_BUTTON]:
button.changeColor(MENU_MOUSE_POS)
button.update(SCREEN)
#events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#mouse click
global first_player, second_player
if event.type == pygame.MOUSEBUTTONDOWN:
#play button click
if HUMAN_BUTTON.checkForInput(MENU_MOUSE_POS):
if player_num == 1:
first_player = PLAYER_TYPE_HUMAN
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
player_menu(2)
return
else:
second_player = PLAYER_TYPE_HUMAN
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
launch()
return
#options button click
if AI_BUTTON.checkForInput(MENU_MOUSE_POS):
if player_num == 1:
first_player = PLAYER_TYPE_AI
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
mode_menu(1)
return
else:
second_player = PLAYER_TYPE_AI
pygame.mixer.music.load('assets/board-start.mp3')
pygame.mixer.music.play(1)
mode_menu(2)
return
pygame.display.update()
#main menu
def main_menu():
while True:
SCREEN.blit(BG, (0, 0))
MENU_MOUSE_POS = pygame.mouse.get_pos()
MENU_TEXT = get_font(100).render("MAIN MENU", True, "#b68f40")
MENU_RECT = MENU_TEXT.get_rect(center=(400, 100))
PLAY_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 250),
text_input="PLAY", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
QUIT_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 400),
text_input="QUIT", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
# OPTIONS_BUTTON = Button(image=pygame.image.load("assets/Rect.png"), pos=(400, 400),
# text_input="OPTIONS", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
SCREEN.blit(MENU_TEXT, MENU_RECT)
#hovering
# for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
for button in [PLAY_BUTTON, QUIT_BUTTON]:
button.changeColor(MENU_MOUSE_POS)
button.update(SCREEN)
#events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#mouse click
if event.type == pygame.MOUSEBUTTONDOWN:
#play button click
if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
pygame.mixer.music.load('assets/menu-sound.mp3')
pygame.mixer.music.play(1)
player_menu(1)
#options button click
# if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
# options()
#quit button click
if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
pygame.quit()
sys.exit()
pygame.display.update()
def launch():
pygame.init()
game = HiveGame([first_player, second_player], [first_player_mode, second_player_mode], [first_player_diff, second_player_diff])
game.start_game_loop()
pygame.quit()
if __name__ == "__main__":
main_menu()
#launch()