data/states/battle.py (view raw)
1"""This is the state that handles battles against
2monsters"""
3import random, sys
4from itertools import izip
5import pygame as pg
6from .. import tools, battlegui, observer, setup
7from .. components import person, attack, attackitems
8from .. import constants as c
9
10
11#Python 2/3 compatibility.
12if sys.version_info[0] == 2:
13 range = xrange
14
15
16class Battle(tools._State):
17 def __init__(self):
18 super(Battle, self).__init__()
19 self.name = 'battle'
20 self.music = setup.MUSIC['high_action']
21 self.volume = 0.4
22
23 def startup(self, current_time, game_data):
24 """
25 Initialize state attributes.
26 """
27 self.current_time = current_time
28 self.timer = current_time
29 self.allow_input = False
30 self.game_data = game_data
31 self.inventory = game_data['player inventory']
32 self.state = 'transition in'
33 self.next = game_data['last state']
34 self.run_away = False
35
36 self.player = self.make_player()
37 self.attack_animations = pg.sprite.Group()
38 self.sword = attackitems.Sword(self.player)
39 self.enemy_group, self.enemy_pos_list, self.enemy_list = self.make_enemies()
40 self.experience_points = self.get_experience_points()
41 self.new_gold = self.get_new_gold()
42 self.background = self.make_background()
43 self.info_box = battlegui.InfoBox(game_data,
44 self.experience_points,
45 self.new_gold)
46 self.arrow = battlegui.SelectArrow(self.enemy_pos_list,
47 self.info_box)
48 self.select_box = battlegui.SelectBox()
49 self.player_health_box = battlegui.PlayerHealth(self.select_box.rect,
50 self.game_data)
51
52 self.select_action_state_dict = self.make_selection_state_dict()
53 self.observers = [observer.Battle(self),
54 observer.MusicChange()]
55 self.player.observers.extend(self.observers)
56 self.observers.append(observer.SoundEffects())
57 self.damage_points = pg.sprite.Group()
58 self.player_actions = []
59 self.player_action_dict = self.make_player_action_dict()
60 self.player_level = self.game_data['player stats']['Level']
61 self.enemies_to_attack = []
62 self.action_selected = False
63 self.just_leveled_up = False
64 self.transition_rect = setup.SCREEN.get_rect()
65 self.transition_alpha = 255
66
67 def make_player_action_dict(self):
68 """
69 Make the dict to execute player actions.
70 """
71 action_dict = {c.PLAYER_ATTACK: self.enter_player_attack_state,
72 c.CURE_SPELL: self.cast_cure,
73 c.FIRE_SPELL: self.cast_fire_blast,
74 c.DRINK_HEALING_POTION: self.enter_drink_healing_potion_state,
75 c.DRINK_ETHER_POTION: self.enter_drink_ether_potion_state}
76
77 return action_dict
78
79 def make_enemy_level_dict(self):
80 new_dict = {c.OVERWORLD: 1,
81 c.DUNGEON: 2,
82 c.DUNGEON2: 2,
83 c.DUNGEON3: 2,
84 c.DUNGEON4: 2,
85 c.DUNGEON5: 4}
86
87 return new_dict
88
89 def set_enemy_level(self, enemy_list):
90 dungeon_level_dict = self.make_enemy_level_dict()
91
92 for enemy in enemy_list:
93 enemy.level = dungeon_level_dict[self.previous]
94
95 def get_experience_points(self):
96 """
97 Calculate experience points based on number of enemies
98 and their levels.
99 """
100 experience_total = 0
101
102 for enemy in self.enemy_list:
103 experience_total += (random.randint(5,10))
104
105 return experience_total
106
107 def get_new_gold(self):
108 """
109 Calculate the gold collected at the end of the battle.
110 """
111 gold = 0
112
113 for enemy in self.enemy_list:
114 max_gold = enemy.level * 20
115 gold += (random.randint(1, max_gold))
116
117 return gold
118
119 def make_background(self):
120 """
121 Make the blue/black background.
122 """
123 background = pg.sprite.Sprite()
124 surface = pg.Surface(c.SCREEN_SIZE).convert()
125 surface.fill(c.BLACK_BLUE)
126 background.image = surface
127 background.rect = background.image.get_rect()
128 background_group = pg.sprite.Group(background)
129
130 return background_group
131
132 def make_enemies(self):
133 """
134 Make the enemies for the battle. Return sprite group.
135 """
136 pos_list = []
137
138 for column in range(3):
139 for row in range(3):
140 x = (column * 100) + 100
141 y = (row * 100) + 100
142 pos_list.append([x, y])
143
144 enemy_group = pg.sprite.Group()
145
146 if self.game_data['battle type']:
147 enemy = person.Enemy('evilwizard', 0, 0,
148 'down', 'battle resting')
149 enemy_group.add(enemy)
150 else:
151 for enemy in range(random.randint(1, 6)):
152 enemy_group.add(person.Enemy('devil', 0, 0,
153 'down', 'battle resting'))
154
155 for i, enemy in enumerate(enemy_group):
156 enemy.rect.topleft = pos_list[i]
157 enemy.image = pg.transform.scale2x(enemy.image)
158 enemy.index = i
159 enemy.level = self.make_enemy_level_dict()[self.previous]
160 if enemy.name == 'evilwizard':
161 enemy.health = 100
162 else:
163 enemy.health = enemy.level * 4
164
165 enemy_list = [enemy for enemy in enemy_group]
166
167 return enemy_group, pos_list[0:len(enemy_group)], enemy_list
168
169 def make_player(self):
170 """
171 Make the sprite for the player's character.
172 """
173 player = person.Player('left', self.game_data, 630, 220, 'battle resting', 1)
174 player.image = pg.transform.scale2x(player.image)
175 return player
176
177 def make_selection_state_dict(self):
178 """
179 Make a dictionary of states with arrow coordinates as keys.
180 """
181 pos_list = self.arrow.make_select_action_pos_list()
182 state_list = [self.enter_select_enemy_state, self.enter_select_item_state,
183 self.enter_select_magic_state, self.try_to_run_away]
184 return dict(izip(pos_list, state_list))
185
186 def update(self, surface, keys, current_time):
187 """
188 Update the battle state.
189 """
190 self.current_time = current_time
191 self.check_input(keys)
192 self.check_timed_events()
193 self.check_if_battle_won()
194 self.enemy_group.update(current_time)
195 self.player.update(keys, current_time)
196 self.attack_animations.update()
197 self.info_box.update()
198 self.arrow.update(keys)
199 self.sword.update(current_time)
200 self.damage_points.update()
201 self.execute_player_actions()
202
203 self.draw_battle(surface)
204
205 def check_input(self, keys):
206 """
207 Check user input to navigate GUI.
208 """
209 if self.allow_input:
210 if keys[pg.K_RETURN]:
211 self.end_battle()
212
213 elif keys[pg.K_SPACE]:
214
215 if self.state == c.SELECT_ACTION:
216 self.notify(c.CLICK2)
217 enter_state_function = self.select_action_state_dict[
218 self.arrow.rect.topleft]
219 enter_state_function()
220
221 elif self.state == c.SELECT_ENEMY:
222 self.notify(c.CLICK2)
223 self.player_actions.append(c.PLAYER_ATTACK)
224 self.enemies_to_attack.append(self.get_enemy_to_attack())
225 self.action_selected = True
226
227 elif self.state == c.SELECT_ITEM:
228 self.notify(c.CLICK2)
229 if self.arrow.index == (len(self.arrow.pos_list) - 1):
230 self.enter_select_action_state()
231 elif self.info_box.item_text_list[self.arrow.index][:14] == 'Healing Potion':
232 self.player_actions.append(c.DRINK_HEALING_POTION)
233 self.action_selected = True
234 elif self.info_box.item_text_list[self.arrow.index][:5] == 'Ether':
235 self.player_actions.append(c.DRINK_ETHER_POTION)
236 self.action_selected = True
237 elif self.state == c.SELECT_MAGIC:
238 self.notify(c.CLICK2)
239 if self.arrow.index == (len(self.arrow.pos_list) - 1):
240 self.enter_select_action_state()
241 elif self.info_box.magic_text_list[self.arrow.index] == 'Cure':
242 magic_points = self.game_data['player inventory']['Cure']['magic points']
243 if self.game_data['player stats']['magic']['current'] >= magic_points:
244 self.player_actions.append(c.CURE_SPELL)
245 self.action_selected = True
246 elif self.info_box.magic_text_list[self.arrow.index] == 'Fire Blast':
247 magic_points = self.game_data['player inventory']['Fire Blast']['magic points']
248 if self.game_data['player stats']['magic']['current'] >= magic_points:
249 self.player_actions.append(c.FIRE_SPELL)
250 self.action_selected = True
251
252 self.allow_input = False
253
254 if keys[pg.K_RETURN] == False and keys[pg.K_SPACE] == False:
255 self.allow_input = True
256
257 def check_timed_events(self):
258 """
259 Check if amount of time has passed for timed events.
260 """
261 timed_states = [c.PLAYER_DAMAGED,
262 c.ENEMY_DAMAGED,
263 c.ENEMY_DEAD,
264 c.DRINK_HEALING_POTION,
265 c.DRINK_ETHER_POTION]
266 long_delay = timed_states[1:]
267
268 if self.state in long_delay:
269 if (self.current_time - self.timer) > 1000:
270 if self.state == c.ENEMY_DAMAGED:
271 if self.player_actions:
272 self.player_action_dict[self.player_actions[0]]()
273 self.player_actions.pop(0)
274 else:
275 if len(self.enemy_list):
276 self.enter_enemy_attack_state()
277 else:
278 self.enter_battle_won_state()
279 elif (self.state == c.DRINK_HEALING_POTION or
280 self.state == c.CURE_SPELL or
281 self.state == c.DRINK_ETHER_POTION):
282 if self.player_actions:
283 self.player_action_dict[self.player_actions[0]]()
284 self.player_actions.pop(0)
285 else:
286 if len(self.enemy_list):
287 self.enter_enemy_attack_state()
288 else:
289 self.enter_battle_won_state()
290 self.timer = self.current_time
291
292 elif self.state == c.FIRE_SPELL or self.state == c.CURE_SPELL:
293 if (self.current_time - self.timer) > 1500:
294 if self.player_actions:
295 self.player_action_dict[self.player_actions[0]]()
296 self.player_actions.pop(0)
297 else:
298 if len(self.enemy_list):
299 self.enter_enemy_attack_state()
300 else:
301 self.enter_battle_won_state()
302 self.timer = self.current_time
303
304 elif self.state == c.RUN_AWAY:
305 if (self.current_time - self.timer) > 1500:
306 self.end_battle()
307
308 elif self.state == c.BATTLE_WON:
309 if (self.current_time - self.timer) > 1800:
310 self.enter_show_gold_state()
311
312 elif self.state == c.SHOW_GOLD:
313 if (self.current_time - self.timer) > 1800:
314 self.enter_show_experience_state()
315
316 elif self.state == c.LEVEL_UP:
317 if (self.current_time - self.timer) > 2200:
318 if self.game_data['player stats']['Level'] == 3:
319 self.enter_two_actions_per_turn_state()
320 else:
321 self.end_battle()
322
323 elif self.state == c.TWO_ACTIONS:
324 if (self.current_time - self.timer) > 3000:
325 self.end_battle()
326
327 elif self.state == c.SHOW_EXPERIENCE:
328 if (self.current_time - self.timer) > 2200:
329 player_stats = self.game_data['player stats']
330 player_stats['experience to next level'] -= self.experience_points
331 if player_stats['experience to next level'] <= 0:
332 extra_experience = player_stats['experience to next level'] * -1
333 player_stats['Level'] += 1
334 player_stats['health']['maximum'] += int(player_stats['health']['maximum']*.25)
335 player_stats['magic']['maximum'] += int(player_stats['magic']['maximum']*.20)
336 new_experience = int((player_stats['Level'] * 50) * .75)
337 player_stats['experience to next level'] = new_experience - extra_experience
338 self.enter_level_up_state()
339 self.just_leveled_up = True
340 else:
341 self.end_battle()
342
343 elif self.state == c.PLAYER_DAMAGED:
344 if (self.current_time - self.timer) > 600:
345 if self.enemy_index == (len(self.enemy_list) - 1):
346 if self.run_away:
347 self.enter_run_away_state()
348 else:
349 self.enter_select_action_state()
350 else:
351 self.switch_enemy()
352 self.timer = self.current_time
353
354 def check_if_battle_won(self):
355 """
356 Check if state is SELECT_ACTION and there are no enemies left.
357 """
358 if self.state == c.SELECT_ACTION:
359 if len(self.enemy_group) == 0:
360 self.enter_battle_won_state()
361
362 def notify(self, event):
363 """
364 Notify observer of event.
365 """
366 for new_observer in self.observers:
367 new_observer.on_notify(event)
368
369 def end_battle(self):
370 """
371 End battle and flip back to previous state.
372 """
373 if self.game_data['battle type'] == 'evilwizard':
374 self.game_data['crown quest'] = True
375 self.game_data['last state'] = self.name
376 self.game_data['battle counter'] = random.randint(50, 255)
377 self.game_data['battle type'] = None
378 self.state = 'transition out'
379
380 def attack_enemy(self, enemy_damage):
381 enemy = self.player.attacked_enemy
382 enemy.health -= enemy_damage
383 self.set_enemy_indices()
384
385 if enemy:
386 enemy.enter_knock_back_state()
387 if enemy.health <= 0:
388 self.enemy_list.pop(enemy.index)
389 enemy.state = c.FADE_DEATH
390 self.arrow.remove_pos(self.player.attacked_enemy)
391 self.enemy_index = 0
392
393 def set_enemy_indices(self):
394 for i, enemy in enumerate(self.enemy_list):
395 enemy.index = i
396
397 def draw_battle(self, surface):
398 """Draw all elements of battle state"""
399 self.background.draw(surface)
400 self.enemy_group.draw(surface)
401 self.attack_animations.draw(surface)
402 self.sword.draw(surface)
403 surface.blit(self.player.image, self.player.rect)
404 surface.blit(self.info_box.image, self.info_box.rect)
405 surface.blit(self.select_box.image, self.select_box.rect)
406 surface.blit(self.arrow.image, self.arrow.rect)
407 self.player_health_box.draw(surface)
408 self.damage_points.draw(surface)
409 self.draw_transition(surface)
410
411 def draw_transition(self, surface):
412 """
413 Fade in and out of state.
414 """
415 if self.state == 'transition in':
416
417 transition_image = pg.Surface(self.transition_rect.size)
418 transition_image.fill(c.TRANSITION_COLOR)
419 transition_image.set_alpha(self.transition_alpha)
420 surface.blit(transition_image, self.transition_rect)
421 self.transition_alpha -= c.TRANSITION_SPEED
422 if self.transition_alpha <= 0:
423 self.state = c.SELECT_ACTION
424 self.transition_alpha = 0
425
426 elif self.state == 'transition out':
427 transition_image = pg.Surface(self.transition_rect.size)
428 transition_image.fill(c.TRANSITION_COLOR)
429 transition_image.set_alpha(self.transition_alpha)
430 surface.blit(transition_image, self.transition_rect)
431 self.transition_alpha += c.TRANSITION_SPEED
432 if self.transition_alpha >= 255:
433 self.done = True
434
435 elif self.state == c.DEATH_FADE:
436 transition_image = pg.Surface(self.transition_rect.size)
437 transition_image.fill(c.TRANSITION_COLOR)
438 transition_image.set_alpha(self.transition_alpha)
439 surface.blit(transition_image, self.transition_rect)
440 self.transition_alpha += c.DEATH_TRANSITION_SPEED
441 if self.transition_alpha >= 255:
442 self.done = True
443 self.next = c.DEATH_SCENE
444
445 def player_damaged(self, damage):
446 self.game_data['player stats']['health']['current'] -= damage
447 if self.game_data['player stats']['health']['current'] <= 0:
448 self.game_data['player stats']['health']['current'] = 0
449 self.state = c.DEATH_FADE
450
451 def player_healed(self, heal, magic_points=0):
452 """
453 Add health from potion to game data.
454 """
455 health = self.game_data['player stats']['health']
456
457 health['current'] += heal
458 if health['current'] > health['maximum']:
459 health['current'] = health['maximum']
460
461 if self.state == c.DRINK_HEALING_POTION:
462 self.game_data['player inventory']['Healing Potion']['quantity'] -= 1
463 if self.game_data['player inventory']['Healing Potion']['quantity'] == 0:
464 del self.game_data['player inventory']['Healing Potion']
465 elif self.state == c.CURE_SPELL:
466 self.game_data['player stats']['magic']['current'] -= magic_points
467
468 def magic_boost(self, magic_points):
469 """
470 Add magic from ether to game data.
471 """
472 magic = self.game_data['player stats']['magic']
473 magic['current'] += magic_points
474 if magic['current'] > magic['maximum']:
475 magic['current'] = magic['maximum']
476
477 self.game_data['player inventory']['Ether Potion']['quantity'] -= 1
478 if not self.game_data['player inventory']['Ether Potion']['quantity']:
479 del self.game_data['player inventory']['Ether Potion']
480
481 def set_timer_to_current_time(self):
482 """Set the timer to the current time."""
483 self.timer = self.current_time
484
485 def cast_fire_blast(self):
486 """
487 Cast fire blast on all enemies.
488 """
489 self.notify(c.FIRE)
490 self.state = self.info_box.state = c.FIRE_SPELL
491 POWER = self.inventory['Fire Blast']['power']
492 POWER += self.game_data['player stats']['Level'] * 5
493 MAGIC_POINTS = self.inventory['Fire Blast']['magic points']
494 self.game_data['player stats']['magic']['current'] -= MAGIC_POINTS
495 for enemy in self.enemy_list:
496 DAMAGE = random.randint(POWER//2, POWER)
497 self.damage_points.add(
498 attackitems.HealthPoints(DAMAGE, enemy.rect.topright))
499 enemy.health -= DAMAGE
500 posx = enemy.rect.x - 32
501 posy = enemy.rect.y - 64
502 fire_sprite = attack.Fire(posx, posy)
503 self.attack_animations.add(fire_sprite)
504 if enemy.health <= 0:
505 enemy.kill()
506 self.arrow.remove_pos(enemy)
507 else:
508 enemy.enter_knock_back_state()
509 self.enemy_list = [enemy for enemy in self.enemy_list if enemy.health > 0]
510 self.enemy_index = 0
511 self.arrow.index = 0
512 self.arrow.state = 'invisible'
513 self.set_timer_to_current_time()
514
515 def cast_cure(self):
516 """
517 Cast cure spell on player.
518 """
519 self.state = c.CURE_SPELL
520 HEAL_AMOUNT = self.inventory['Cure']['power']
521 MAGIC_POINTS = self.inventory['Cure']['magic points']
522 self.player.healing = True
523 self.set_timer_to_current_time()
524 self.arrow.state = 'invisible'
525 self.enemy_index = 0
526 self.damage_points.add(
527 attackitems.HealthPoints(HEAL_AMOUNT, self.player.rect.topright, False))
528 self.player_healed(HEAL_AMOUNT, MAGIC_POINTS)
529 self.info_box.state = c.DRINK_HEALING_POTION
530 self.notify(c.POWERUP)
531
532 def enter_select_enemy_state(self):
533 """
534 Transition battle into the select enemy state.
535 """
536 self.state = self.arrow.state = c.SELECT_ENEMY
537 self.arrow.index = 0
538
539 def enter_select_item_state(self):
540 """
541 Transition battle into the select item state.
542 """
543 self.state = self.info_box.state = c.SELECT_ITEM
544 self.arrow.become_select_item_state()
545
546 def enter_select_magic_state(self):
547 """
548 Transition battle into the select magic state.
549 """
550 self.state = self.info_box.state = c.SELECT_MAGIC
551 self.arrow.become_select_magic_state()
552
553 def try_to_run_away(self):
554 """
555 Transition battle into the run away state.
556 """
557 self.run_away = True
558 self.arrow.state = 'invisible'
559 self.enemy_index = 0
560 self.enter_enemy_attack_state()
561
562 def enter_enemy_attack_state(self):
563 """
564 Transition battle into the Enemy attack state.
565 """
566 self.state = self.info_box.state = c.ENEMY_ATTACK
567 enemy = self.enemy_list[self.enemy_index]
568 enemy.enter_enemy_attack_state()
569
570 def enter_player_attack_state(self):
571 """
572 Transition battle into the Player attack state.
573 """
574 self.state = self.info_box.state = c.PLAYER_ATTACK
575 enemy_to_attack = self.enemies_to_attack.pop(0)
576 if enemy_to_attack in self.enemy_list:
577 self.player.enter_attack_state(enemy_to_attack)
578 else:
579 if self.enemy_list:
580 self.player.enter_attack_state(self.enemy_list[0])
581 else:
582 self.enter_battle_won_state()
583 self.arrow.state = 'invisible'
584
585 def get_enemy_to_attack(self):
586 """
587 Get enemy for player to attack by arrow position.
588 """
589 enemy_posx = self.arrow.rect.x + 60
590 enemy_posy = self.arrow.rect.y - 20
591 enemy_pos = (enemy_posx, enemy_posy)
592 enemy_to_attack = None
593
594 for enemy in self.enemy_list:
595 if enemy.rect.topleft == enemy_pos:
596 enemy_to_attack = enemy
597
598 return enemy_to_attack
599
600
601 def enter_drink_healing_potion_state(self):
602 """
603 Transition battle into the Drink Healing Potion state.
604 """
605 self.state = self.info_box.state = c.DRINK_HEALING_POTION
606 self.player.healing = True
607 self.set_timer_to_current_time()
608 self.arrow.state = 'invisible'
609 self.enemy_index = 0
610 self.damage_points.add(
611 attackitems.HealthPoints(30,
612 self.player.rect.topright,
613 False))
614 self.player_healed(30)
615 self.notify(c.POWERUP)
616
617 def enter_drink_ether_potion_state(self):
618 """
619 Transition battle into the Drink Ether Potion state.
620 """
621 self.state = self.info_box.state = c.DRINK_ETHER_POTION
622 self.player.healing = True
623 self.arrow.state = 'invisible'
624 self.enemy_index = 0
625 self.damage_points.add(
626 attackitems.HealthPoints(30,
627 self.player.rect.topright,
628 False,
629 True))
630 self.magic_boost(30)
631 self.set_timer_to_current_time()
632 self.notify(c.POWERUP)
633
634 def enter_select_action_state(self):
635 """
636 Transition battle into the select action state
637 """
638 self.state = self.info_box.state = c.SELECT_ACTION
639 self.arrow.index = 0
640 self.arrow.state = self.state
641
642 def enter_player_damaged_state(self):
643 """
644 Transition battle into the player damaged state.
645 """
646 self.state = self.info_box.state = c.PLAYER_DAMAGED
647 if self.enemy_index > len(self.enemy_list) - 1:
648 self.enemy_index = 0
649 enemy = self.enemy_list[self.enemy_index]
650 player_damage = enemy.calculate_hit(self.inventory['equipped armor'],
651 self.inventory)
652 self.damage_points.add(
653 attackitems.HealthPoints(player_damage,
654 self.player.rect.topright))
655 self.info_box.set_player_damage(player_damage)
656 self.set_timer_to_current_time()
657 self.player_damaged(player_damage)
658 if player_damage:
659 sfx_num = random.randint(1,3)
660 self.notify('punch{}'.format(sfx_num))
661 self.player.damaged = True
662 self.player.enter_knock_back_state()
663
664 def enter_enemy_damaged_state(self):
665 """
666 Transition battle into the enemy damaged state.
667 """
668 self.state = self.info_box.state = c.ENEMY_DAMAGED
669 enemy_damage = self.player.calculate_hit()
670 self.damage_points.add(
671 attackitems.HealthPoints(enemy_damage,
672 self.player.attacked_enemy.rect.topright))
673
674 self.info_box.set_enemy_damage(enemy_damage)
675
676 self.arrow.index = 0
677 self.attack_enemy(enemy_damage)
678 self.set_timer_to_current_time()
679
680 def switch_enemy(self):
681 """
682 Switch which enemy the player is attacking.
683 """
684 if self.enemy_index < len(self.enemy_list) - 1:
685 self.enemy_index += 1
686 self.enter_enemy_attack_state()
687
688 def enter_run_away_state(self):
689 """
690 Transition battle into the run away state.
691 """
692 self.state = self.info_box.state = c.RUN_AWAY
693 self.arrow.state = 'invisible'
694 self.player.state = c.RUN_AWAY
695 self.set_timer_to_current_time()
696 self.notify(c.RUN_AWAY)
697
698 def enter_battle_won_state(self):
699 """
700 Transition battle into the battle won state.
701 """
702 self.notify(c.BATTLE_WON)
703 self.state = self.info_box.state = c.BATTLE_WON
704 self.player.state = c.VICTORY_DANCE
705 self.set_timer_to_current_time()
706
707 def enter_show_gold_state(self):
708 """
709 Transition battle into the show gold state.
710 """
711 self.inventory['GOLD']['quantity'] += self.new_gold
712 self.state = self.info_box.state = c.SHOW_GOLD
713 self.set_timer_to_current_time()
714
715 def enter_show_experience_state(self):
716 """
717 Transition battle into the show experience state.
718 """
719 self.state = self.info_box.state = c.SHOW_EXPERIENCE
720 self.set_timer_to_current_time()
721
722 def enter_level_up_state(self):
723 """
724 Transition battle into the LEVEL UP state.
725 """
726 self.state = self.info_box.state = c.LEVEL_UP
727 self.info_box.reset_level_up_message()
728 self.set_timer_to_current_time()
729
730 def enter_two_actions_per_turn_state(self):
731 self.state = self.info_box.state = c.TWO_ACTIONS
732 self.set_timer_to_current_time()
733
734 def execute_player_actions(self):
735 """
736 Execute the player actions.
737 """
738 if self.player_level < 3:
739 if self.player_actions:
740 enter_state = self.player_action_dict[self.player_actions[0]]
741 enter_state()
742 self.player_actions.pop(0)
743 else:
744 if len(self.player_actions) == 2:
745 enter_state = self.player_action_dict[self.player_actions[0]]
746 enter_state()
747 self.player_actions.pop(0)
748 self.action_selected = False
749 else:
750 if self.action_selected:
751 self.enter_select_action_state()
752 self.action_selected = False
753
754
755
756
757
758
759
760
761