-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuview.py
120 lines (91 loc) · 3.58 KB
/
menuview.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 pygame
import math
from globals import *
from view import Button
from view import size
from layout import calculate_button_height
from layout import calculate_button_layout
from boards import BOARDS
class MainMenuView:
def __init__(self, parent, game):
self.game = game
self.parent = parent
self.screen = game.screen
self.options = ["Play/n(%s, %s)"%(self.parent.rules, self.parent.board), "Change rules", "Change Board"]
self.background = pygame.Surface(self.screen.get_size())
self.background = self.background.convert()
self.background.fill((0, 0, 0))
self.buttons = []
for i in calculate_button_layout(self.options):
self.buttons.append(Button(self, i[0], i[1], i[2], self.on_click))
self.screen.blit(self.background, (0, 0))
def draw(self):
#fill screen with black
self.background.fill((0, 0, 0))
#populate menu
for button in self.buttons:
button.draw()
self.screen.blit(self.background, (0, 0))
def evaluate(self):
if self.buttons:
for button in self.buttons:
button.evaluate()
def on_click(self, data):
if data == self.options[0]:
self.parent.create_game()
elif data == self.options[1]:
self.parent.change_menu(GameRulesMenu(self.parent, self.game))
elif data == self.options[2]:
self.parent.change_menu(BoardMenu(self.parent, self.game))
class GameRulesMenu:
def __init__(self, parent, game):
self.game = game
self.parent = parent
self.screen = game.screen
self.options = list(game.GAME_VARIATIONS.keys())
self.background = pygame.Surface(self.screen.get_size())
self.background = self.background.convert()
self.background.fill((0, 0, 0))
self.buttons = []
for i in calculate_button_layout(self.options):
self.buttons.append(Button(self, i[0], i[1], i[2], self.on_click))
def draw(self):
#fill screen with black
self.background.fill((0, 0, 0))
#populate menu
for button in self.buttons:
button.draw()
self.screen.blit(self.background, (0, 0))
def evaluate(self):
if self.buttons:
for button in self.buttons:
button.evaluate()
def on_click(self, data):
self.parent.change_rules(data)
self.parent.change_menu(MainMenuView(self.parent, self.game))
class BoardMenu:
def __init__(self, parent, application):
self.application = application
self.parent = parent
self.screen = application.screen
self.options = list(self.application.GAME_VARIATIONS[self.parent.rules].allowed_boards)
self.background = pygame.Surface(self.screen.get_size())
self.background = self.background.convert()
self.background.fill((0, 0, 0))
self.buttons = []
for i in calculate_button_layout(self.options):
self.buttons.append(Button(self, i[0], i[1], i[2], self.on_click))
def draw(self):
#fill screen with black
self.background.fill((0, 0, 0))
#populate menu
for button in self.buttons:
button.draw()
self.screen.blit(self.background, (0, 0))
def evaluate(self):
if self.buttons:
for button in self.buttons:
button.evaluate()
def on_click(self, data):
self.parent.change_board(data)
self.parent.change_menu(MainMenuView(self.parent, self.application))