-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game_Driver.py
370 lines (316 loc) · 15 KB
/
Game_Driver.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import pygame
import pygame.math
import os
import importlib
import functions, Pokemon
import tcp_client
from pygame.locals import *
SCREENSIZE_X = 1000
SCREENSIZE_Y = 618
CONVERSION_FACTOR = 50
BACKPACK_SIZE = 6
# these coordinates are bounding points
# Giant search bar for screen 3
# screen 3 consists of a single search button
# jumps to external terminal
# name becomes input
# search for name within pokemon pool
#
class game_Pokemon(pygame.sprite.Sprite):
def __init__(self, x, y, x2, y2, Pokemon):
self.locationX = x
self.locationY = y
self.locationX2 = x2
self.locationY2 = y2
self.image = Pokemon.BackPIc
self.pokemon = Pokemon
def show_image(self, screen):
display_Image(screen, self.image, self.locationX, self.locationY, self.locationX2, self.locationY2)
def show_imageE(self, screen):
display_Image(screen, self.pokemon.FrontPic, self.locationX, self.locationY, self.locationX2, self.locationY2)
def show_status(self, screen, font):
draw_box(screen, font, 0 , 0, self.locationX2 + 100, self.locationY2 - 400, self.pokemon.name, self.pokemon.level, self.pokemon.HP, self.pokemon.totalHP)
def show_statusE(self, screen, font):
draw_box(screen, font, self.locationX, self.locationY + 200, SCREENSIZE_X, self.locationY2 + 200, self.pokemon.name, self.pokemon.level, self.pokemon.HP, self.pokemon.totalHP)
class button:
def __init__(self, image, x1, y1, x2, y2):
self.image = image
self.x1 = x1
self.x2 = x2
self.y1 = y1
self.y2 = y2
def show_button(self, screen):
new_image = pygame.transform.scale(pygame.image.load(self.image), (abs(self.x2 - self.x1), abs(self.y2 - self.y1)))
screen.blit(new_image, (self.x1, self.y1))
pygame.display.update()
def show_text(self, screen, font):
new_text = self.image
text = font.render(self.image, True, [0,0,0])
screen.blit(text, [(self.x1 + self.x2)//2, (self.y1 + self.y2)//2])
pygame.display.update()
'''
def interaction(self, screen):
if(pygame.mouse.get_pressed()[0]):
if(pygame.mouse.get_pos()[0] < self.x2 and pygame.mouse.get_pos()[0] > self.x1 and pygame.mouse.get_pos()[1] > self.y1 and pygame.mouse.get_pos()[1] < self.y2):
return True
return False
'''
def coordinates(self):
return[self.x1,self.y1,self.x2,self.y2]
def main():
#os.chdir(r'C:\Users\jeffr\OneDrive\Desktop\VS2020\BattleSimulation\Pokemon-Battle-Simulation')
user_IP = '10.102.79.104'
user_Port = 7788
client = tcp_client.client(user_IP, user_Port)
client.connect()
pokemon_lst = functions.poke_lst()
choice_lst = []
screen = pygame.display.set_mode((SCREENSIZE_X, SCREENSIZE_Y))
pygame.display.set_caption('home screen')
#booleans for disabling screen functions
active_Screen = True
active_Screen2 = False
active_Screen3 = False
active_Screen4 = False
active_forloop = True
#booleans for button functions
active_start = False
active_help = False
active_server = False
active_client = False
active_enter = False
active_search = False
active_startgame = True
finished_choice = False
active_ability1 = False
active_ability2 = False
active_ability3 = False
active_ability4 = False
screen.fill((255, 255, 255))
pygame.font.init()
font = pygame.font.SysFont("arial", 24)
user_choice = ''
running = True
display_Homescreen(screen)
current_Pokemon = None
enemy_Pokemon = None
#start_button = button('C:\\Users\\jeffr\\OneDrive\\Desktop\\VS2020\\BattleSimulation\\Pokemon-Battle-Simulation\\asset\\image\\start.png', 700, 490, 900, 615)
start_button = button('asset\\image\\start.png', 700, 490, 900, 615)
start_button.show_button(screen)
help_button = button('asset\\image\\help.png', 200, 500, 400, 600)
help_button.show_button(screen)
lst = start_button.coordinates()
alst = help_button.coordinates()
server_button = button('asset\\image\\server.png', 600, 50, 700, 300)
#server_button.show_button(screen2)
client_button = button('asset\\image\\client.png', 750, 50, 900, 300)
#client_button.show_button(screen2)
#display_Image(screen2, 'Pokemon-Battle-Simulation\\asset\\image\\selection.png', 200, 50, 550, 150)
enter_button = button('asset\\image\\enter.jpg', 800, 525, 950, 600)
slst = server_button.coordinates()
clst = client_button.coordinates()
elst = enter_button.coordinates()
search_button = button('asset\\image\\Magnify.png', SCREENSIZE_X//2 - 200, SCREENSIZE_Y//2 - 150, SCREENSIZE_X//2 + 200, SCREENSIZE_Y//2 + 150)
srchLst = search_button.coordinates()
startgame_button = button('asset\\image\\play.jpg', 850, 490, 1000, 615)
sglst = startgame_button.coordinates()
display_Image(screen, 'asset\\image\\Pokemon\\Pikachu.png', 0, 100, 400, 500)
display_Image(screen, 'asset\\image\\Pokemon\\Charmander.png', 600, 100, 1000, 500)
ab1lst = []
ab2lst = []
ab3lst = []
ab4lst = []
while running:
#Creation of homescreen and a couple buttons
#one screen, button booleans
if active_start == True:
#screen = pygame.display.set_mode((SCREENSIZE_X, SCREENSIZE_Y))
#pygame.display.set_caption('index screen')
display_Background(screen, 'asset\\image\\white.png')
server_button.show_button(screen)
client_button.show_button(screen)
enter_button.show_button(screen)
mts(screen, font, "Ash", (0, 0, 0), 625, 320)
mts(screen, font, "Serena", (0, 0, 0), 765, 320)
mts(screen, font, "Please choose your character", (0,0,0), slst[0] - 400, slst[1])
active_start = False
active_Screen = False
if active_server == True:
display_Image(screen, 'asset\\image\\art.jpg',slst[0] - 10, slst[3] + 10, slst[2] + 10, slst[3] + 50)
active_server = False
elif active_client == True:
display_Image(screen, 'asset\\image\\art.jpg',clst[0] - 10, clst[3] + 10, clst[2] - 10, clst[3] + 50)
active_client = False
if active_enter == True:
display_Background(screen, 'asset\\image\\white.png')
search_button.show_button(screen)
mts(screen, font, "Search For a Pokemon to Make Your Deck", (0,0,0), srchLst[0] - 20, srchLst[1] - 50)
startgame_button.show_button(screen)
active_Screen2 == False
if active_search == True:
count = 0
mts(screen, font, "BACKPACK", (0, 0, 255), 800, 50)
if active_forloop:
for x in range(BACKPACK_SIZE):
user_choice = input1(screen, font)
while(not check_lst(user_choice, pokemon_lst)):
print("Please enter a valid pokemon")
user_choice = input1(screen, font)
choice_lst.append(Pokemon.Pokemon(user_choice))
mts(screen, font, user_choice, (0, 0, 0), 800, (x + 2) * CONVERSION_FACTOR)
if(len(choice_lst) == BACKPACK_SIZE):
finished_choice = True
active_forloop = False
if finished_choice == True:
active_Screen3 = False
active_search = False
active_enter = False
screen.fill((255,255,255))
mts(screen, font, "Waiting for server to respond", (0,0,0), SCREENSIZE_X//2, 100)
if finished_choice and active_startgame:
client.press_start()
active_startgame = False
display_Background(screen, 'asset\\image\\background.png')
current_Pokemon = game_Pokemon(100,150, 400, 500, choice_lst[0])
enemy_Pokemon = game_Pokemon(700, 0, 900, 200, choice_lst[0])
current_Pokemon.show_image(screen)
current_Pokemon.show_status(screen, font)
ability1 = button(current_Pokemon.pokemon.move_lst[0].name, 20, 440, 120, 450)
ability2 = button(current_Pokemon.pokemon.move_lst[1].name, 20, 480, 120, 490)
ability3 = button(current_Pokemon.pokemon.move_lst[2].name, 200, 440, 300, 450)
ability4 = button(current_Pokemon.pokemon.move_lst[3].name, 200, 480, 300, 490)
ability1.show_text(screen, font)
ability2.show_text(screen, font)
ability3.show_text(screen, font)
ability4.show_text(screen, font)
ab1lst = ability1.coordinates()
ab2lst = ability2.coordinates()
ab3lst = ability3.coordinates()
ab4lst = ability4.coordinates()
if(active_ability1):
received_dict = client.battle(current_Pokemon.pokemon, current_Pokemon.pokemon.move_lst[0])
change(current_Pokemon.pokemon, received_dict['my_pkmn'])
change(enemy_Pokemon.pokemon, received_dict['op_pkmn'])
elif(active_ability2):
received_dict = client.battle(current_Pokemon.pokemon, current_Pokemon.pokemon.move_lst[1])
change(current_Pokemon.pokemon, received_dict['my_pkmn'])
change(enemy_Pokemon.pokemon, received_dict['op_pkmn'])
elif(active_ability3):
received_dict = client.battle(current_Pokemon.pokemon, current_Pokemon.pokemon.move_lst[2])
change(current_Pokemon.pokemon, received_dict['my_pkmn'])
change(enemy_Pokemon.pokemon, received_dict['op_pkmn'])
elif(active_ability4):
received_dict = client.battle(current_Pokemon.pokemon, current_Pokemon.pokemon.move_lst[3])
change(current_Pokemon.pokemon, received_dict['my_pkmn'])
change(enemy_Pokemon.pokemon, received_dict['op_pkmn'])
enemy_Pokemon.show_imageE(screen)
enemy_Pokemon.show_statusE(screen, font)
#client.battle(pokemon, move) references
# received_dict = client.battle(pokemon, move)
# one boolean in dict will control attack order
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if check_Bounds(lst) and active_Screen:
active_start = True
active_Screen2 = True
if(check_Bounds(slst) and active_Screen2):
active_server = True
#display_Line(screen2, (255,0,0), slst[0] - 10, slst[3] + 10, slst[2] + 10, slst[3] + 50)
elif(check_Bounds(clst) and active_Screen2):
active_client = True
elif(check_Bounds(elst) and active_Screen2):
active_enter = True
active_Screen3 = True
if check_Bounds(srchLst) and active_Screen3:
active_search = True
if finished_choice:
if check_Bounds(ab1lst) and active_Screen4:
active_ability1 = True
elif check_Bounds(ab2lst) and active_Screen4:
active_ability2 = True
elif check_Bounds(ab3lst) and active_Screen4:
active_ability3 = True
elif check_Bounds(ab4lst) and active_Screen4:
active_ability4 = True
pygame.display.update()
def check_lst(name, lst):
return name in lst
def input1(screen, font, name = ''):
while True:
for evt in pygame.event.get():
if evt.type == KEYDOWN:
if evt.unicode.isalpha():
name += evt.unicode
elif evt.key == K_BACKSPACE:
name = name[:-1]
elif evt.key == K_RETURN:
name = ""
elif evt.key == K_SPACE:
return name
if evt.type == MOUSEBUTTONDOWN:
break
elif evt.type == QUIT:
break
display_Image(screen, 'asset\\image\\textbox.png', 250, 518, 800, 618)
block = font.render(name, True, (255, 255, 255))
rect = block.get_rect()
rect.center = (550, 568)
screen.blit(block, rect)
pygame.display.flip()
def get_Pokemon(screen):
user_input = input("Please enter your wanted pokemon")
return user_input
def mts(screen, font, text, textcolor, x, y):
text = font.render(text, True, textcolor)
screen.blit(text, [x, y])
#pygame.display.update()
def display_Image(screen, file_abspath, x1, y1, x2, y2 ):
image = pygame.transform.scale(pygame.image.load(file_abspath), (abs(x2 - x1), abs(y2 - y1)))
screen.blit(image, (x1, y1))
#pygame.display.update()
def display_Homescreen(screen):
homescreen = pygame.transform.scale(pygame.image.load('asset\\image\\colorscreen.jpg'), (SCREENSIZE_X, SCREENSIZE_Y))
screen.blit(homescreen, (0, 0))
#pygame.display.update()
def check_Bounds(lst):
if pygame.mouse.get_pos()[0] > lst[0] and pygame.mouse.get_pos()[0] < lst[2] and pygame.mouse.get_pos()[1] > lst[1] and pygame.mouse.get_pos()[1] < lst[3]:
return True
return False
def display_Background(screen, file_abspath):
background = pygame.transform.scale(pygame.image.load(file_abspath), (SCREENSIZE_X, SCREENSIZE_Y))
screen.blit(background, (0, 0))
#pygame.display.update()
def draw_box(screen, font,x1,y1,x2,y2,name,level,hp, total_hp):
display_Image(screen, 'asset\\image\\box.png', x1,y1,x2,y2)
mts(screen, font, name, (0,0,255), x1 + (x2-x1)//3, y1 + (y2-y1)//3)
mts(screen, font, "lv " + str(level), (0,0,255),x1 + (x2-x1)//3*2 , y1 + (y2-y1)//3)
mts(screen, font, "HP: " + str(hp) + "/" + str(total_hp), (0,0,255), x1 + 5, y2 - 50)
hp_outline = pygame.Rect(x1 + (x2-x1)//3, y1 + (y2 - y1)//3 * 2, int((x2 - x1)//3) + 50, y1 + (y2 - y1)//3 - 5)
hp_box = pygame.Rect(x1 + (x2-x1)//3, y1 + (y2 - y1)//3 * 2, int(((x2 - x1)//3 + 50) * hp/total_hp), y1 + (y2 - y1)//3 - 5)
pygame.draw.rect(screen, [0,0,0], hp_outline, 2)
pygame.draw.rect(screen, [255, 0, 0], hp_box)
def change(pokemon, ls):
pokemon.name = ls[0]
pokemon.FrontPic = ls[20]
pokemon.HP = ls[1]
pokemon.Attack = ls[2]
pokemon.Defense = ls[3]
pokemon.SpAttack = ls[4]
pokemon.SpDefense = ls[5]
pokemon.Speed = ls[6]
pokemon.level = ls[7]
pokemon.critical = ls[8]
pokemon.accuracy = ls[9]
pokemon.evasion = ls[10]
pokemon.atk_mod = ls[11]
pokemon.def_mod = ls[12]
pokemon.spatk_mod = ls[13]
pokemon.spdef_mod = ls[14]
pokemon.spd_mod = ls[15]
pokemon.stat = ls[16]
pokemon.type = ls[17]
pokemon.acc_mod = ls[18]
pokemon.eva_mod = ls[19]
main()