all repos — Legends-RPG @ 680235e09a98538dcc6f7165b3f8186889ed6ba5

A fantasy mini-RPG built with Python and Pygame.

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    def player_damaged(self, damage):
436        self.game_data['player stats']['health']['current'] -= damage
437
438    def player_healed(self, heal, magic_points=0):
439        """
440        Add health from potion to game data.
441        """
442        health = self.game_data['player stats']['health']
443
444        health['current'] += heal
445        if health['current'] > health['maximum']:
446            health['current'] = health['maximum']
447
448        if self.state == c.DRINK_HEALING_POTION:
449            self.game_data['player inventory']['Healing Potion']['quantity'] -= 1
450            if self.game_data['player inventory']['Healing Potion']['quantity'] == 0:
451                del self.game_data['player inventory']['Healing Potion']
452        elif self.state == c.CURE_SPELL:
453            self.game_data['player stats']['magic']['current'] -= magic_points
454
455    def magic_boost(self, magic_points):
456        """
457        Add magic from ether to game data.
458        """
459        magic = self.game_data['player stats']['magic']
460        magic['current'] += magic_points
461        if magic['current'] > magic['maximum']:
462            magic['current'] = magic['maximum']
463
464        self.game_data['player inventory']['Ether Potion']['quantity'] -= 1
465        if not self.game_data['player inventory']['Ether Potion']['quantity']:
466            del self.game_data['player inventory']['Ether Potion']
467
468    def set_timer_to_current_time(self):
469        """Set the timer to the current time."""
470        self.timer = self.current_time
471
472    def cast_fire_blast(self):
473        """
474        Cast fire blast on all enemies.
475        """
476        self.notify(c.FIRE)
477        self.state = self.info_box.state = c.FIRE_SPELL
478        POWER = self.inventory['Fire Blast']['power']
479        POWER += self.game_data['player stats']['Level'] * 5
480        MAGIC_POINTS = self.inventory['Fire Blast']['magic points']
481        self.game_data['player stats']['magic']['current'] -= MAGIC_POINTS
482        for enemy in self.enemy_list:
483            DAMAGE = random.randint(POWER//2, POWER)
484            self.damage_points.add(
485                attackitems.HealthPoints(DAMAGE, enemy.rect.topright))
486            enemy.health -= DAMAGE
487            posx = enemy.rect.x - 32
488            posy = enemy.rect.y - 64
489            fire_sprite = attack.Fire(posx, posy)
490            self.attack_animations.add(fire_sprite)
491            if enemy.health <= 0:
492                enemy.kill()
493                self.arrow.remove_pos(enemy)
494            else:
495                enemy.enter_knock_back_state()
496        self.enemy_list = [enemy for enemy in self.enemy_list if enemy.health > 0]
497        self.enemy_index = 0
498        self.arrow.index = 0
499        self.arrow.state = 'invisible'
500        self.set_timer_to_current_time()
501
502    def cast_cure(self):
503        """
504        Cast cure spell on player.
505        """
506        self.state = c.CURE_SPELL
507        HEAL_AMOUNT = self.inventory['Cure']['power']
508        MAGIC_POINTS = self.inventory['Cure']['magic points']
509        self.player.healing = True
510        self.set_timer_to_current_time()
511        self.arrow.state = 'invisible'
512        self.enemy_index = 0
513        self.damage_points.add(
514            attackitems.HealthPoints(HEAL_AMOUNT, self.player.rect.topright, False))
515        self.player_healed(HEAL_AMOUNT, MAGIC_POINTS)
516        self.info_box.state = c.DRINK_HEALING_POTION
517        self.notify(c.POWERUP)
518
519    def enter_select_enemy_state(self):
520        """
521        Transition battle into the select enemy state.
522        """
523        self.state = self.arrow.state = c.SELECT_ENEMY
524        self.arrow.index = 0
525
526    def enter_select_item_state(self):
527        """
528        Transition battle into the select item state.
529        """
530        self.state = self.info_box.state = c.SELECT_ITEM
531        self.arrow.become_select_item_state()
532
533    def enter_select_magic_state(self):
534        """
535        Transition battle into the select magic state.
536        """
537        self.state = self.info_box.state = c.SELECT_MAGIC
538        self.arrow.become_select_magic_state()
539
540    def try_to_run_away(self):
541        """
542        Transition battle into the run away state.
543        """
544        self.run_away = True
545        self.arrow.state = 'invisible'
546        self.enemy_index = 0
547        self.enter_enemy_attack_state()
548
549    def enter_enemy_attack_state(self):
550        """
551        Transition battle into the Enemy attack state.
552        """
553        self.state = self.info_box.state = c.ENEMY_ATTACK
554        enemy = self.enemy_list[self.enemy_index]
555        enemy.enter_enemy_attack_state()
556
557    def enter_player_attack_state(self):
558        """
559        Transition battle into the Player attack state.
560        """
561        self.state = self.info_box.state = c.PLAYER_ATTACK
562        enemy_to_attack = self.enemies_to_attack.pop(0)
563        if enemy_to_attack in self.enemy_list:
564            self.player.enter_attack_state(enemy_to_attack)
565        else:
566            if self.enemy_list:
567                self.player.enter_attack_state(self.enemy_list[0])
568            else:
569                self.enter_battle_won_state()
570        self.arrow.state = 'invisible'
571
572    def get_enemy_to_attack(self):
573        """
574        Get enemy for player to attack by arrow position.
575        """
576        enemy_posx = self.arrow.rect.x + 60
577        enemy_posy = self.arrow.rect.y - 20
578        enemy_pos = (enemy_posx, enemy_posy)
579        enemy_to_attack = None
580
581        for enemy in self.enemy_list:
582            if enemy.rect.topleft == enemy_pos:
583                enemy_to_attack = enemy
584
585        return enemy_to_attack
586
587
588    def enter_drink_healing_potion_state(self):
589        """
590        Transition battle into the Drink Healing Potion state.
591        """
592        self.state = self.info_box.state = c.DRINK_HEALING_POTION
593        self.player.healing = True
594        self.set_timer_to_current_time()
595        self.arrow.state = 'invisible'
596        self.enemy_index = 0
597        self.damage_points.add(
598            attackitems.HealthPoints(30,
599                                     self.player.rect.topright,
600                                     False))
601        self.player_healed(30)
602        self.notify(c.POWERUP)
603
604    def enter_drink_ether_potion_state(self):
605        """
606        Transition battle into the Drink Ether Potion state.
607        """
608        self.state = self.info_box.state = c.DRINK_ETHER_POTION
609        self.player.healing = True
610        self.arrow.state = 'invisible'
611        self.enemy_index = 0
612        self.damage_points.add(
613            attackitems.HealthPoints(30,
614                                     self.player.rect.topright,
615                                     False,
616                                     True))
617        self.magic_boost(30)
618        self.set_timer_to_current_time()
619        self.notify(c.POWERUP)
620
621    def enter_select_action_state(self):
622        """
623        Transition battle into the select action state
624        """
625        self.state = self.info_box.state = c.SELECT_ACTION
626        self.arrow.index = 0
627        self.arrow.state = self.state
628
629    def enter_player_damaged_state(self):
630        """
631        Transition battle into the player damaged state.
632        """
633        self.state = self.info_box.state = c.PLAYER_DAMAGED
634        if self.enemy_index > len(self.enemy_list) - 1:
635            self.enemy_index = 0
636        enemy = self.enemy_list[self.enemy_index]
637        player_damage = enemy.calculate_hit(self.inventory['equipped armor'],
638                                            self.inventory)
639        self.damage_points.add(
640            attackitems.HealthPoints(player_damage,
641                                     self.player.rect.topright))
642        self.info_box.set_player_damage(player_damage)
643        self.set_timer_to_current_time()
644        self.player_damaged(player_damage)
645        if player_damage:
646            sfx_num = random.randint(1,3)
647            self.notify('punch{}'.format(sfx_num))
648            self.player.damaged = True
649            self.player.enter_knock_back_state()
650
651    def enter_enemy_damaged_state(self):
652        """
653        Transition battle into the enemy damaged state.
654        """
655        self.state = self.info_box.state = c.ENEMY_DAMAGED
656        enemy_damage = self.player.calculate_hit()
657        self.damage_points.add(
658            attackitems.HealthPoints(enemy_damage,
659                                     self.player.attacked_enemy.rect.topright))
660
661        self.info_box.set_enemy_damage(enemy_damage)
662
663        self.arrow.index = 0
664        self.attack_enemy(enemy_damage)
665        self.set_timer_to_current_time()
666
667    def switch_enemy(self):
668        """
669        Switch which enemy the player is attacking.
670        """
671        if self.enemy_index < len(self.enemy_list) - 1:
672            self.enemy_index += 1
673            self.enter_enemy_attack_state()
674
675    def enter_run_away_state(self):
676        """
677        Transition battle into the run away state.
678        """
679        self.state = self.info_box.state = c.RUN_AWAY
680        self.arrow.state = 'invisible'
681        self.player.state = c.RUN_AWAY
682        self.set_timer_to_current_time()
683        self.notify(c.RUN_AWAY)
684
685    def enter_battle_won_state(self):
686        """
687        Transition battle into the battle won state.
688        """
689        self.notify(c.BATTLE_WON)
690        self.state = self.info_box.state = c.BATTLE_WON
691        self.player.state = c.VICTORY_DANCE
692        self.set_timer_to_current_time()
693
694    def enter_show_gold_state(self):
695        """
696        Transition battle into the show gold state.
697        """
698        self.inventory['GOLD']['quantity'] += self.new_gold
699        self.state = self.info_box.state = c.SHOW_GOLD
700        self.set_timer_to_current_time()
701
702    def enter_show_experience_state(self):
703        """
704        Transition battle into the show experience state.
705        """
706        self.state = self.info_box.state = c.SHOW_EXPERIENCE
707        self.set_timer_to_current_time()
708
709    def enter_level_up_state(self):
710        """
711        Transition battle into the LEVEL UP state.
712        """
713        self.state = self.info_box.state = c.LEVEL_UP
714        self.info_box.reset_level_up_message()
715        self.set_timer_to_current_time()
716
717    def enter_two_actions_per_turn_state(self):
718        self.state = self.info_box.state = c.TWO_ACTIONS
719        self.set_timer_to_current_time()
720
721    def execute_player_actions(self):
722        """
723        Execute the player actions.
724        """
725        if self.player_level < 3:
726            if self.player_actions:
727                enter_state = self.player_action_dict[self.player_actions[0]]
728                enter_state()
729                self.player_actions.pop(0)
730        else:
731            if len(self.player_actions) == 2:
732                enter_state = self.player_action_dict[self.player_actions[0]]
733                enter_state()
734                self.player_actions.pop(0)
735                self.action_selected = False
736            else:
737                if self.action_selected:
738                    self.enter_select_action_state()
739                    self.action_selected = False
740
741
742
743
744
745
746
747
748