-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenu.py
145 lines (118 loc) · 5.25 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
# from Menu.Buttons import Button
from Statistics.statistics import *
from Instructions.instructions import *
from game import main_singleplayer
import sys
class Menu:
""" Główne menu gry """
def __init__(self):
self.display_surf = None
self.size = self.width, self.height = 1024, 576
self.color = (255, 192, 203)
pygame.init()
# narysuj tło
self.display_surf = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
self.display_surf.fill(self.color)
# rysuje tytuł
self.title = "MASTERMIND"
font = pygame.font.SysFont('comicsans', 62)
title = font.render(self.title, 1, (47, 23, 56))
self.display_surf.blit(title, (self.width/2 - title.get_width()/2, self.height/6 - title.get_height()/6,))
# rysuje przycisk "Nowa gra"
self.new_g = Button((0, 100, 200), 442, 160, 140, 60, 24, "New Game")
self.new_g.draw(self.display_surf)
# rysuje przycisk "Wczytaj"
self.load = Button((0, 100, 200), 442, 230, 140, 60, 24, "Load Game")
self.load.draw(self.display_surf)
# rysuje przycisk "Statystyki"
self.stats = Button((0, 100, 200), 442, 300, 140, 60, 24, "High Scores")
self.stats.draw(self.display_surf)
# rysuje przycisk "Manuel :P"
self.info = Button((0, 100, 200), 442, 370, 140, 60, 24, "Instructions")
self.info.draw(self.display_surf)
# rysuje przycisk "Wyjscie"
self.esc = Button((0, 100, 200), 442, 440, 140, 60, 24, "Exit")
self.esc.draw(self.display_surf)
pygame.display.update()
class ChooseGame:
pygame.init()
""" klasa menu wyboru rozgrywki """
def __init__(self):
self.size = self.width, self.height = 1024, 576
self.color = (255, 192, 203)
self.background = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
self.background.fill(self.color)
self.title = "Wybierz tryb gry"
# rysuje tytuł
font = pygame.font.SysFont('comicsans', 62)
title = font.render(self.title, 1, (47, 23, 56))
self.background.blit(title,
(self.width / 2 - title.get_width() / 2, self.height / 6 - title.get_height() / 6,))
# rysuje przycisk zwykłego masterminda
self.normal = Button((0, 100, 200), 116, 228, 280, 120, 34, "Klasyczny Mastermind")
self.normal.draw(self.background)
# rysuje przycisk trybu słownego
self.word = Button((0, 100, 200), 628, 228, 280, 120, 34, "Tryb Słowny")
self.word.draw(self.background)
# rysuje przycisk powrotu do menu
self.back = Button((0, 100, 200), 442, 428, 140, 60, 24, "Powrót")
self.back.draw(self.background)
pygame.display.update()
def choose_game(save, back, check_b):
pygame.init()
is_done = False
choice = ChooseGame()
while not is_done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if choice.normal.is_pointing(pos):
pygame.display.quit()
main_singleplayer.GAME_MODE = "Peg"
main_singleplayer.play_game(save, back, check_b, 0)
elif choice.word.is_pointing(pos):
pygame.display.quit()
main_singleplayer.GAME_MODE = "Letter"
main_singleplayer.play_game(save, back, check_b, 0)
elif choice.back.is_pointing(pos):
is_done = True
def main():
menu = Menu()
settings = None
is_running = True
while is_running:
''' Główna pętla gry i obsługa eventów'''
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_running = False
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if menu.esc.is_pointing(pos):
is_running = False
elif menu.stats.is_pointing(pos):
display_stats()
menu = Menu()
elif menu.new_g.is_pointing(pos):
save = Button((255, 0, 100), 500, 645, 150, 50, 24, 'Zapisz')
back = Button((255, 0, 100), 325, 645, 150, 50, 24, 'Menu')
check_b = Button((255, 0, 100), 150, 645, 150, 50, 24, 'Sprawdz')
choose_game(save, back, check_b)
# main_singleplayer.play_game()
menu = Menu()
elif menu.info.is_pointing(pos):
display_instructions()
menu = Menu()
elif menu.load.is_pointing(pos):
save = Button((255, 0, 100), 500, 645, 150, 50, 24, 'Zapisz')
back = Button((255, 0, 100), 325, 645, 150, 50, 24, 'Menu')
check_b = Button((255, 0, 100), 150, 645, 150, 50, 24, 'Sprawdz')
pygame.display.quit()
main_singleplayer.play_game(save, back, check_b, 1)
if __name__ == "__main__":
pygame.init()
main()