-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameGUI.py
197 lines (166 loc) · 7.88 KB
/
GameGUI.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
import pygame
from PauseMenu import PauseMenu
class GameGUI:
def __init__(self, game_logic):
pygame.font.init()
self.lengthOrWidth = 72
self.logic = game_logic
self.board = pygame.image.load('pic/Board.gif')
self.i_hb = pygame.image.load('pic/HBlack.gif')
self.i_hw = pygame.image.load('pic/HWhite.gif')
self.i_db = pygame.image.load('pic/DBlack.gif')
self.i_dw = pygame.image.load('pic/DWhite.gif')
self.i_menu = pygame.image.load('pic/menu.png')
self.i_last_step = pygame.image.load('pic/LastStep.png')
self.i_access_step = pygame.image.load('pic/AccessStep.png')
self.i_hb.set_colorkey((255, 255, 255))
self.i_hw.set_colorkey((255, 255, 255))
self.i_db.set_colorkey((255, 255, 255))
self.i_dw.set_colorkey((255, 255, 255))
self.i_last_step.set_colorkey((255, 255, 255))
self.i_access_step.set_colorkey((255, 255, 255))
self.font = pygame.font.SysFont("monospace", 50)
self.fontLittle = pygame.font.SysFont("monospace", 25)
self.labelWhiteChess = self.font.render("Белые", 1, (255, 255, 255))
self.labelBlackChess = self.font.render("Черные", 1, (0, 0, 0))
self.labelGoChess = self.font.render("Ходят", 1, (78, 226, 14))
self.i_rightscreen = pygame.image.load('pic/rightscreen.png')
self.window = pygame.display.set_mode((920, 720))
pygame.display.set_caption(u"Hahki")
pygame.display.set_icon(pygame.image.load('pic/DBlack.gif').convert())
self.mainscreen = pygame.Surface((720, 720))
self.rightscreen = pygame.Surface((280, 720))
def mouse_event_check(self):
"""
обрабатывает движение мыши
:return: True или False если пользователь закрыл игру
"""
mp = pygame.mouse.get_pos()
done = True
for e in pygame.event.get():
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
punkts = [(365, 200, u'Continue',
(123, 15, 34), (235, 75, 156), 0),
(400, 300, u'Save', (123, 15, 34),
(235, 75, 156), 1),
(400, 400, u'Exit', (123, 15, 34),
(235, 75, 156), 2)]
pause = PauseMenu(punkts, self.logic.save_game)
pause.run()
if e.type == pygame.QUIT:
done = False
if e.type == pygame.MOUSEBUTTONDOWN and e.button == 1:
self.logic.without_net(mp)
return done
def set_start_position(self):
"""
устонавливет сартовую позицию
"""
if self.logic.playerDraughts == "b":
self.logic.set_start_playing_field("up")
else:
self.logic.set_start_playing_field("down")
def change_number_render(self):
"""
Отображает количество шашек на поле
"""
label_white = self.font.render(str(self.logic.numberOfWhite), 1,
(255, 255, 255))
label_black = self.font.render(str(self.logic.numberOfBlack), 1,
(0, 0, 0))
self.rightscreen.blit(label_white, (70, 20))
self.rightscreen.blit(label_black, (70, 120))
def step_history(self):
n = len(self.logic.stepArray)
for i in range(n):
if self.logic.stepArray.get_color(i) == 'b':
for_label_one = str(self.logic.stepArray.get_first(i))
for_label_two = str(self.logic.stepArray.get_second(i))
label_one = self.fontLittle.render(for_label_one, 1, (0, 0, 0))
label_two = self.fontLittle.render(for_label_two, 1, (0, 0, 0))
else:
for_label_one = str(self.logic.stepArray.get_first(i))
for_label_two = str(self.logic.stepArray.get_second(i))
label_one = self.fontLittle.render(for_label_one, 1,
(188, 22, 22))
label_two = self.fontLittle.render(for_label_two, 1,
(188, 22, 22))
self.rightscreen.blit(label_one, (5, 370 + (n - i) * 35))
self.rightscreen.blit(label_two, (100, 370 + (n - i) * 35))
def render_last_step(self):
try:
length = len(self.logic.stepArray) - 1
step_first = self.logic.stepArray.get_first(length)
step_second = self.logic.stepArray.get_second(length)
exp_one = (step_first[1] - 1) * self.lengthOrWidth
exp_two = (step_first[0] - 1) * self.lengthOrWidth
self.mainscreen.blit(self.i_last_step, (exp_one, exp_two))
exp_one = (step_second[1] - 1) * self.lengthOrWidth
exp_two = (step_second[0] - 1) * self.lengthOrWidth
self.mainscreen.blit(self.i_last_step, (exp_one, exp_two))
for i in range(1, 4):
step_f = self.logic.stepArray.get_first(length - i)
if self.logic.stepArray.get_color(length - i) == \
self.logic.stepArray.get_color(length - i + 1):
self.mainscreen.blit(self.i_last_step, (
(step_f[1] - 1) * self.lengthOrWidth,
(step_f[0] - 1) * self.lengthOrWidth))
else:
break
except:
None
def render_success_step(self):
for step in self.logic.check_chess_with_enemy():
self.mainscreen.blit(self.i_access_step,
(step[1] * self.lengthOrWidth,
step[0] * self.lengthOrWidth))
def who_go_render(self):
"""
Отображает кто должен ходить
"""
if self.logic.playDraughts == "w":
self.rightscreen.blit(self.labelWhiteChess, (25, 300))
else:
self.rightscreen.blit(self.labelBlackChess, (15, 300))
def render_game_field(self):
"""
отрисовывает игровое поле
"""
for i in range(10):
for j in range(10):
try:
if self.logic.gameField[i][j] == 'b':
self.mainscreen.blit(self.i_hb, (
j * self.lengthOrWidth, i * self.lengthOrWidth))
elif self.logic.gameField[i][j] == 'w':
self.mainscreen.blit(self.i_hw, (
j * self.lengthOrWidth, i * self.lengthOrWidth))
elif self.logic.gameField[i][j] == 'q':
self.mainscreen.blit(self.i_dw, (
j * self.lengthOrWidth, i * self.lengthOrWidth))
elif self.logic.gameField[i][j] == 'v':
self.mainscreen.blit(self.i_db, (
j * self.lengthOrWidth, i * self.lengthOrWidth))
self.logic.gameField[i][j].render(self.mainscreen)
except AttributeError:
None
except Exception as e:
print(e)
print(str(i) + " " + str(j))
def render(self):
"""
отрисовка всего
"""
self.window.blit(self.mainscreen, (0, 0))
self.window.blit(self.rightscreen, (720, 0))
self.rightscreen.blit(self.i_rightscreen, (0, 0))
self.mainscreen.blit(self.board, (0, 0))
self.rightscreen.blit(self.labelGoChess, (25, 220))
self.change_number_render()
self.who_go_render()
self.step_history()
self.render_last_step()
self.render_success_step()
self.render_game_field()
pygame.display.flip()