forked from drak00/AI-plus-Chess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
159 lines (128 loc) · 3.44 KB
/
menu.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
"""
This is the Offline menu.
It has a single player, two players AI mode and back options.
You can select an option by double clicking on it.
"""
import pygame as pg
from ai import ai_move, ai_reset
from main import main
import random
import sys
# Game Initialization
pg.init()
# menu Resolution
screen_width=600
screen_height=600
screen=pg.display.set_mode((screen_width, screen_height))
font = pg.font.SysFont("Helvetica",75)
#
def display_main(choice):
"""
Link option To main board
"""
return main(choice)
def player_format(message, player_size, player_color):
"""
Add Menu Options
"""
new_player=font.render(message, 0, player_color)
return new_player
# Colors
white=pg.Color("ghostwhite")
black=(0, 0, 0)
brown=(66,44,22)
green=pg.Color("chartreuse")
blue=(0, 0, 255)
yellow=pg.Color("Peru")
bg_color=pg.Color("chartreuse")
red=(255,0,0)
font = pg.font.SysFont("Liberation", 50)
# Game Framerate
clock = pg.time.Clock()
FPS=30
# Main Menu
def main_menu():
menu=True
selected=""
mode=""
while menu:
for event in pg.event.get():
if event.type==pg.QUIT:
pg.quit()
quit()
#selecting menu Items
if event.type == pg.MOUSEBUTTONDOWN:
(mouseX, mouseY) = pg.mouse.get_pos()
a,b=mouseX,mouseY
if (60 <= a <= 330) and (200<=b<=230):
if selected !="player1":
selected="player1"
elif selected =="player1":
mode="player1"
elif (60 <= a <= 300) and (300<=b<=330):
if selected !="player2":
selected="player2"
elif selected =="player2":
mode="player2"
elif (60 <= a <= 200) and (400<=b<=430):
if selected !="aimode":
selected="aimode"
elif selected =="aimode":
mode="aimode"
elif (460 <= a <= 550) and (500<=b<=530):
if selected !="quit":
selected="quit"
elif selected =="quit":
mode="quit"
# Main Menu UI
# screen.fill(yellow)
title=player_format("STEAM CHESS ENGINE", 100, yellow)
name=pg.transform.scale(pg.image.load("images/menu3.png"),(640,640)) #background image
#selections and event trigger
if selected=="player1":
player_start=player_format("SINGLE PLAYER", 75, green)
if mode=="player1":
player_start = player_format("SINGLE PLAYER", 75, brown)
else:
player_start = player_format("SINGLE PLAYER", 75, white)
if selected=="player2":
player2_start=player_format("TWO PLAYERS", 75, green)
if mode=="player2":
player2_start = player_format("TWO PLAYER", 75, brown)
display_main(False)
mode=""
player=""
else:
player2_start = player_format("TWO PLAYERS", 75, white)
if selected=="aimode":
if mode!="aimode":
player_ai=player_format("AI MODE", 75, green)
elif mode=="aimode":
player_ai = player_format("AI MODE", 75, brown)
display_main(True)
mode=""
player=""
else:
player_ai = player_format("AI MODE", 75, white)
if selected=="quit":
player_quit=player_format("BACK", 75, red)
if mode=="quit":
mode=""
player=""
menu=False
else:
player_quit = player_format("BACK", 75, white)
# Main Menu player
screen.blit(name, (0,1))
screen.blit(title, ( 60 , 30))
screen.blit(player_start, (60, 200))
screen.blit(player2_start, (60, 300))
screen.blit(player_ai, (60, 400))
screen.blit(player_quit, (462, 500))
pg.display.update()
clock.tick(FPS)
pg.display.set_caption("STEAM CHESS ENGINE")
#Initialize the Game
# main_menu()
# pg.quit()
# quit()