-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
118 lines (107 loc) · 3.99 KB
/
helper.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
import math
import sys
from Button import *
from ButtonGroup import *
buttonHeight = 50
algButtonWidth = 170
playerButtonWidth = 100
startButtonWidth = 110
difficultyButtonWidth = 200
gametypeButtonWidth = 300
topMargin = 30
def homePage(game, display):
algorithm = ButtonGroup(
top=topMargin,
left=game.screenSize[0] / 2 - algButtonWidth,
buttonList=[
Button(display=display, w=algButtonWidth, h=buttonHeight, text="Minimax", value="minimax"),
Button(display=display, w=algButtonWidth, h=buttonHeight, text="Alpha-Beta", value="alphabeta")
],
selected=1
)
player = ButtonGroup(
top=2*topMargin + buttonHeight,
left=game.screenSize[0] / 2 - playerButtonWidth,
buttonList=[
Button(display=display, w=playerButtonWidth, h=buttonHeight,
text="Red", value="red"),
Button(display=display, w=playerButtonWidth, h=buttonHeight,
text="Blue", value="blue")
],
selected=0
)
difficulty = ButtonGroup(
top=3*topMargin + 2*buttonHeight,
left=game.screenSize[0] / 2.55 - difficultyButtonWidth,
buttonList=[
Button(display=display, w=difficultyButtonWidth, h=buttonHeight,
text="Beginner", value="beginner"),
Button(display=display, w=difficultyButtonWidth, h=buttonHeight,
text="Medium", value="medium"),
Button(display=display, w=difficultyButtonWidth, h=buttonHeight,
text="Advanced", value="advanced")
],
selected=0
)
gameType = ButtonGroup(
top=4*topMargin + 3*buttonHeight,
left=game.screenSize[0] / 2 - gametypeButtonWidth,
buttonList=[
Button(display=display, w=gametypeButtonWidth, h=buttonHeight,
text="Player vs Player", value="pvp"),
Button(display=display, w=gametypeButtonWidth, h=buttonHeight,
text="Player vs Computer", value="pve")
],
selected=1
)
start = Button(display=display,
top=5*topMargin + 4*buttonHeight,
left=game.screenSize[0] / 2 - startButtonWidth / 2 + 35,
w=startButtonWidth,
h=buttonHeight,
text="START",
bgColor=(0, 179, 60))
quitbtn = Button(display=display,
top=6*topMargin + 5*buttonHeight,
left=game.screenSize[0] / 2 - startButtonWidth / 2 + 35,
w=startButtonWidth,
h=buttonHeight,
text="QUIT",
bgColor=(255, 20, 0))
algorithm.draw()
player.draw()
difficulty.draw()
gameType.draw()
start.draw()
quitbtn.draw()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if quitbtn.selectByCoord(pos):
pygame.quit()
sys.exit(0)
if not algorithm.selectByCoord(pos):
if not player.selectByCoord(pos):
if not difficulty.selectByCoord(pos):
if not gameType.selectByCoord(pos):
if start.selectByCoord(pos):
return player.getValue(), algorithm.getValue(), \
difficulty.getValue(), gameType.getValue()
pygame.display.update()
def computeTileDimensions(size):
return size * math.sqrt(3), size * 2
def cornerPoint(radius, index, pos):
deg = 60 * index + 30
theta = math.pi / 180 * deg
x, y = pos
return radius * math.cos(theta) + x, radius * math.sin(theta) + y
def integer(number):
try:
int(number)
return True
except ValueError:
return False