all repos — Legends-RPG @ 771a9169fe092728fcd9519c5a9f76f2fd9cb035

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: 3,
 84                    c.DUNGEON4: 2,
 85                    c.DUNGEON5: 5}
 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)*enemy.level)
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            enemy.health = enemy.level * 7
161
162        enemy_list = [enemy for enemy in enemy_group]
163
164        return enemy_group, pos_list[0:len(enemy_group)], enemy_list
165
166    def make_player(self):
167        """
168        Make the sprite for the player's character.
169        """
170        player = person.Player('left', self.game_data, 630, 220, 'battle resting', 1)
171        player.image = pg.transform.scale2x(player.image)
172        return player
173
174    def make_selection_state_dict(self):
175        """
176        Make a dictionary of states with arrow coordinates as keys.
177        """
178        pos_list = self.arrow.make_select_action_pos_list()
179        state_list = [self.enter_select_enemy_state, self.enter_select_item_state,
180                      self.enter_select_magic_state, self.try_to_run_away]
181        return dict(izip(pos_list, state_list))
182
183    def update(self, surface, keys, current_time):
184        """
185        Update the battle state.
186        """
187        self.current_time = current_time
188        self.check_input(keys)
189        self.check_timed_events()
190        self.check_if_battle_won()
191        self.enemy_group.update(current_time)
192        self.player.update(keys, current_time)
193        self.attack_animations.update()
194        self.info_box.update()
195        self.arrow.update(keys)
196        self.sword.update(current_time)
197        self.damage_points.update()
198        self.execute_player_actions()
199
200        self.draw_battle(surface)
201
202    def check_input(self, keys):
203        """
204        Check user input to navigate GUI.
205        """
206        if self.allow_input:
207            if keys[pg.K_RETURN]:
208                self.end_battle()
209
210            elif keys[pg.K_SPACE]:
211
212                if self.state == c.SELECT_ACTION:
213                    self.notify(c.CLICK2)
214                    enter_state_function = self.select_action_state_dict[
215                        self.arrow.rect.topleft]
216                    enter_state_function()
217
218                elif self.state == c.SELECT_ENEMY:
219                    self.notify(c.CLICK2)
220                    self.player_actions.append(c.PLAYER_ATTACK)
221                    self.enemies_to_attack.append(self.get_enemy_to_attack())
222                    self.action_selected = True
223
224                elif self.state == c.SELECT_ITEM:
225                    self.notify(c.CLICK2)
226                    if self.arrow.index == (len(self.arrow.pos_list) - 1):
227                        self.enter_select_action_state()
228                    elif self.info_box.item_text_list[self.arrow.index][:14] == 'Healing Potion':
229                        self.player_actions.append(c.DRINK_HEALING_POTION)
230                        self.action_selected = True
231                    elif self.info_box.item_text_list[self.arrow.index][:5] == 'Ether':
232                        self.player_actions.append(c.DRINK_ETHER_POTION)
233                        self.action_selected = True
234                elif self.state == c.SELECT_MAGIC:
235                    self.notify(c.CLICK2)
236                    if self.arrow.index == (len(self.arrow.pos_list) - 1):
237                        self.enter_select_action_state()
238                    elif self.info_box.magic_text_list[self.arrow.index] == 'Cure':
239                        magic_points = self.game_data['player inventory']['Cure']['magic points']
240                        if self.game_data['player stats']['magic']['current'] >= magic_points:
241                            self.player_actions.append(c.CURE_SPELL)
242                            self.action_selected = True
243                    elif self.info_box.magic_text_list[self.arrow.index] == 'Fire Blast':
244                        magic_points = self.game_data['player inventory']['Fire Blast']['magic points']
245                        if self.game_data['player stats']['magic']['current'] >= magic_points:
246                            self.player_actions.append(c.FIRE_SPELL)
247                            self.action_selected = True
248
249            self.allow_input = False
250
251        if keys[pg.K_RETURN] == False and keys[pg.K_SPACE] == False:
252            self.allow_input = True
253
254    def check_timed_events(self):
255        """
256        Check if amount of time has passed for timed events.
257        """
258        timed_states = [c.PLAYER_DAMAGED,
259                        c.ENEMY_DAMAGED,
260                        c.ENEMY_DEAD,
261                        c.DRINK_HEALING_POTION,
262                        c.DRINK_ETHER_POTION]
263        long_delay = timed_states[1:]
264
265        if self.state in long_delay:
266            if (self.current_time - self.timer) > 1000:
267                if self.state == c.ENEMY_DAMAGED:
268                    if self.player_actions:
269                        self.player_action_dict[self.player_actions[0]]()
270                        self.player_actions.pop(0)
271                    else:
272                        if len(self.enemy_list):
273                            self.enter_enemy_attack_state()
274                        else:
275                            self.enter_battle_won_state()
276                elif (self.state == c.DRINK_HEALING_POTION or
277                      self.state == c.CURE_SPELL or
278                      self.state == c.DRINK_ETHER_POTION):
279                    if self.player_actions:
280                        self.player_action_dict[self.player_actions[0]]()
281                        self.player_actions.pop(0)
282                    else:
283                        if len(self.enemy_list):
284                            self.enter_enemy_attack_state()
285                        else:
286                            self.enter_battle_won_state()
287                self.timer = self.current_time
288
289        elif self.state == c.FIRE_SPELL or self.state == c.CURE_SPELL:
290            if (self.current_time - self.timer) > 1500:
291                if self.player_actions:
292                    self.player_action_dict[self.player_actions[0]]()
293                    self.player_actions.pop(0)
294                else:
295                    if len(self.enemy_list):
296                        self.enter_enemy_attack_state()
297                    else:
298                        self.enter_battle_won_state()
299                self.timer = self.current_time
300
301        elif self.state == c.RUN_AWAY:
302            if (self.current_time - self.timer) > 1500:
303                self.end_battle()
304
305        elif self.state == c.BATTLE_WON:
306            if (self.current_time - self.timer) > 1800:
307                self.enter_show_gold_state()
308
309        elif self.state == c.SHOW_GOLD:
310            if (self.current_time - self.timer) > 1800:
311                self.enter_show_experience_state()
312
313        elif self.state == c.LEVEL_UP:
314            if (self.current_time - self.timer) > 2200:
315                if self.game_data['player stats']['Level'] == 3:
316                    self.enter_two_actions_per_turn_state()
317                else:
318                    self.end_battle()
319
320        elif self.state == c.TWO_ACTIONS:
321            if (self.current_time - self.timer) > 3000:
322                self.end_battle()
323
324        elif self.state == c.SHOW_EXPERIENCE:
325            if (self.current_time - self.timer) > 2200:
326                player_stats = self.game_data['player stats']
327                player_stats['experience to next level'] -= self.experience_points
328                if player_stats['experience to next level'] <= 0:
329                    player_stats['Level'] += 1
330                    player_stats['health']['maximum'] += int(player_stats['health']['maximum']*.25)
331                    player_stats['magic']['maximum'] += int(player_stats['magic']['maximum']*.20)
332                    new_experience = int((player_stats['Level'] * 50) * .75)
333                    player_stats['experience to next level'] = new_experience
334                    self.enter_level_up_state()
335                    self.just_leveled_up = True
336                else:
337                    self.end_battle()
338
339        elif self.state == c.PLAYER_DAMAGED:
340            if (self.current_time - self.timer) > 600:
341                if self.enemy_index == (len(self.enemy_list) - 1):
342                    if self.run_away:
343                        self.enter_run_away_state()
344                    else:
345                        self.enter_select_action_state()
346                else:
347                    self.switch_enemy()
348                self.timer = self.current_time
349
350    def check_if_battle_won(self):
351        """
352        Check if state is SELECT_ACTION and there are no enemies left.
353        """
354        if self.state == c.SELECT_ACTION:
355            if len(self.enemy_group) == 0:
356                self.enter_battle_won_state()
357
358    def notify(self, event):
359        """
360        Notify observer of event.
361        """
362        for new_observer in self.observers:
363            new_observer.on_notify(event)
364
365    def end_battle(self):
366        """
367        End battle and flip back to previous state.
368        """
369        if self.game_data['battle type'] == 'evilwizard':
370            self.game_data['crown quest'] = True
371        self.game_data['last state'] = self.name
372        self.game_data['battle counter'] = random.randint(50, 255)
373        self.game_data['battle type'] = None
374        self.state = 'transition out'
375
376    def attack_enemy(self, enemy_damage):
377        enemy = self.player.attacked_enemy
378        enemy.health -= enemy_damage
379        self.set_enemy_indices()
380
381        if enemy:
382            enemy.enter_knock_back_state()
383            if enemy.health <= 0:
384                self.enemy_list.pop(enemy.index)
385                enemy.state = c.FADE_DEATH
386                self.arrow.remove_pos(self.player.attacked_enemy)
387            self.enemy_index = 0
388
389    def set_enemy_indices(self):
390        for i, enemy in enumerate(self.enemy_list):
391            enemy.index = i
392
393    def draw_battle(self, surface):
394        """Draw all elements of battle state"""
395        self.background.draw(surface)
396        self.enemy_group.draw(surface)
397        self.attack_animations.draw(surface)
398        self.sword.draw(surface)
399        surface.blit(self.player.image, self.player.rect)
400        surface.blit(self.info_box.image, self.info_box.rect)
401        surface.blit(self.select_box.image, self.select_box.rect)
402        surface.blit(self.arrow.image, self.arrow.rect)
403        self.player_health_box.draw(surface)
404        self.damage_points.draw(surface)
405        self.draw_transition(surface)
406
407    def draw_transition(self, surface):
408        """
409        Fade in and out of state.
410        """
411        if self.state == 'transition in':
412
413            transition_image = pg.Surface(self.transition_rect.size)
414            transition_image.fill(c.TRANSITION_COLOR)
415            transition_image.set_alpha(self.transition_alpha)
416            surface.blit(transition_image, self.transition_rect)
417            self.transition_alpha -= c.TRANSITION_SPEED 
418            if self.transition_alpha <= 0:
419                self.state = c.SELECT_ACTION
420                self.transition_alpha = 0
421
422        elif self.state == 'transition out':
423            transition_image = pg.Surface(self.transition_rect.size)
424            transition_image.fill(c.TRANSITION_COLOR)
425            transition_image.set_alpha(self.transition_alpha)
426            surface.blit(transition_image, self.transition_rect)
427            self.transition_alpha += c.TRANSITION_SPEED 
428            if self.transition_alpha >= 255:
429                self.done = True
430
431    def player_damaged(self, damage):
432        self.game_data['player stats']['health']['current'] -= damage
433
434    def player_healed(self, heal, magic_points=0):
435        """
436        Add health from potion to game data.
437        """
438        health = self.game_data['player stats']['health']
439
440        health['current'] += heal
441        if health['current'] > health['maximum']:
442            health['current'] = health['maximum']
443
444        if self.state == c.DRINK_HEALING_POTION:
445            self.game_data['player inventory']['Healing Potion']['quantity'] -= 1
446            if self.game_data['player inventory']['Healing Potion']['quantity'] == 0:
447                del self.game_data['player inventory']['Healing Potion']
448        elif self.state == c.CURE_SPELL:
449            self.game_data['player stats']['magic']['current'] -= magic_points
450
451    def magic_boost(self, magic_points):
452        """
453        Add magic from ether to game data.
454        """
455        magic = self.game_data['player stats']['magic']
456        magic['current'] += magic_points
457        if magic['current'] > magic['maximum']:
458            magic['current'] = magic['maximum']
459
460        self.game_data['player inventory']['Ether Potion']['quantity'] -= 1
461        if not self.game_data['player inventory']['Ether Potion']['quantity']:
462            del self.game_data['player inventory']['Ether Potion']
463
464    def set_timer_to_current_time(self):
465        """Set the timer to the current time."""
466        self.timer = self.current_time
467
468    def cast_fire_blast(self):
469        """
470        Cast fire blast on all enemies.
471        """
472        self.notify(c.FIRE)
473        self.state = self.info_box.state = c.FIRE_SPELL
474        POWER = self.inventory['Fire Blast']['power']
475        POWER += self.game_data['player stats']['Level'] * 5
476        MAGIC_POINTS = self.inventory['Fire Blast']['magic points']
477        self.game_data['player stats']['magic']['current'] -= MAGIC_POINTS
478        for enemy in self.enemy_list:
479            DAMAGE = random.randint(POWER//2, POWER)
480            self.damage_points.add(
481                attackitems.HealthPoints(DAMAGE, enemy.rect.topright))
482            enemy.health -= DAMAGE
483            posx = enemy.rect.x - 32
484            posy = enemy.rect.y - 64
485            fire_sprite = attack.Fire(posx, posy)
486            self.attack_animations.add(fire_sprite)
487            if enemy.health <= 0:
488                enemy.kill()
489                self.arrow.remove_pos(enemy)
490            else:
491                enemy.enter_knock_back_state()
492        self.enemy_list = [enemy for enemy in self.enemy_list if enemy.health > 0]
493        self.enemy_index = 0
494        self.arrow.index = 0
495        self.arrow.state = 'invisible'
496        self.set_timer_to_current_time()
497
498    def cast_cure(self):
499        """
500        Cast cure spell on player.
501        """
502        self.state = c.CURE_SPELL
503        HEAL_AMOUNT = self.inventory['Cure']['power']
504        MAGIC_POINTS = self.inventory['Cure']['magic points']
505        self.player.healing = True
506        self.set_timer_to_current_time()
507        self.arrow.state = 'invisible'
508        self.enemy_index = 0
509        self.damage_points.add(
510            attackitems.HealthPoints(HEAL_AMOUNT, self.player.rect.topright, False))
511        self.player_healed(HEAL_AMOUNT, MAGIC_POINTS)
512        self.info_box.state = c.DRINK_HEALING_POTION
513        self.notify(c.POWERUP)
514
515    def enter_select_enemy_state(self):
516        """
517        Transition battle into the select enemy state.
518        """
519        self.state = self.arrow.state = c.SELECT_ENEMY
520        self.arrow.index = 0
521
522    def enter_select_item_state(self):
523        """
524        Transition battle into the select item state.
525        """
526        self.state = self.info_box.state = c.SELECT_ITEM
527        self.arrow.become_select_item_state()
528
529    def enter_select_magic_state(self):
530        """
531        Transition battle into the select magic state.
532        """
533        self.state = self.info_box.state = c.SELECT_MAGIC
534        self.arrow.become_select_magic_state()
535
536    def try_to_run_away(self):
537        """
538        Transition battle into the run away state.
539        """
540        self.run_away = True
541        self.arrow.state = 'invisible'
542        self.enemy_index = 0
543        self.enter_enemy_attack_state()
544
545    def enter_enemy_attack_state(self):
546        """
547        Transition battle into the Enemy attack state.
548        """
549        self.state = self.info_box.state = c.ENEMY_ATTACK
550        enemy = self.enemy_list[self.enemy_index]
551        enemy.enter_enemy_attack_state()
552
553    def enter_player_attack_state(self):
554        """
555        Transition battle into the Player attack state.
556        """
557        self.state = self.info_box.state = c.PLAYER_ATTACK
558        enemy_to_attack = self.enemies_to_attack.pop(0)
559        if enemy_to_attack in self.enemy_list:
560            self.player.enter_attack_state(enemy_to_attack)
561        else:
562            if self.enemy_list:
563                self.player.enter_attack_state(self.enemy_list[0])
564            else:
565                self.enter_battle_won_state()
566        self.arrow.state = 'invisible'
567
568    def get_enemy_to_attack(self):
569        """
570        Get enemy for player to attack by arrow position.
571        """
572        enemy_posx = self.arrow.rect.x + 60
573        enemy_posy = self.arrow.rect.y - 20
574        enemy_pos = (enemy_posx, enemy_posy)
575        enemy_to_attack = None
576
577        for enemy in self.enemy_list:
578            if enemy.rect.topleft == enemy_pos:
579                enemy_to_attack = enemy
580
581        return enemy_to_attack
582
583
584    def enter_drink_healing_potion_state(self):
585        """
586        Transition battle into the Drink Healing Potion state.
587        """
588        self.state = self.info_box.state = c.DRINK_HEALING_POTION
589        self.player.healing = True
590        self.set_timer_to_current_time()
591        self.arrow.state = 'invisible'
592        self.enemy_index = 0
593        self.damage_points.add(
594            attackitems.HealthPoints(30,
595                                     self.player.rect.topright,
596                                     False))
597        self.player_healed(30)
598        self.notify(c.POWERUP)
599
600    def enter_drink_ether_potion_state(self):
601        """
602        Transition battle into the Drink Ether Potion state.
603        """
604        self.state = self.info_box.state = c.DRINK_ETHER_POTION
605        self.player.healing = True
606        self.arrow.state = 'invisible'
607        self.enemy_index = 0
608        self.damage_points.add(
609            attackitems.HealthPoints(30,
610                                     self.player.rect.topright,
611                                     False,
612                                     True))
613        self.magic_boost(30)
614        self.set_timer_to_current_time()
615        self.notify(c.POWERUP)
616
617    def enter_select_action_state(self):
618        """
619        Transition battle into the select action state
620        """
621        self.state = self.info_box.state = c.SELECT_ACTION
622        self.arrow.index = 0
623        self.arrow.state = self.state
624
625    def enter_player_damaged_state(self):
626        """
627        Transition battle into the player damaged state.
628        """
629        self.state = self.info_box.state = c.PLAYER_DAMAGED
630        if self.enemy_index > len(self.enemy_list) - 1:
631            self.enemy_index = 0
632        enemy = self.enemy_list[self.enemy_index]
633        player_damage = enemy.calculate_hit(self.inventory['equipped armor'],
634                                            self.inventory)
635        self.damage_points.add(
636            attackitems.HealthPoints(player_damage,
637                                     self.player.rect.topright))
638        self.info_box.set_player_damage(player_damage)
639        self.set_timer_to_current_time()
640        self.player_damaged(player_damage)
641        if player_damage:
642            sfx_num = random.randint(1,3)
643            self.notify('punch{}'.format(sfx_num))
644            self.player.damaged = True
645            self.player.enter_knock_back_state()
646
647    def enter_enemy_damaged_state(self):
648        """
649        Transition battle into the enemy damaged state.
650        """
651        self.state = self.info_box.state = c.ENEMY_DAMAGED
652        enemy_damage = self.player.calculate_hit()
653        self.damage_points.add(
654            attackitems.HealthPoints(enemy_damage,
655                                     self.player.attacked_enemy.rect.topright))
656
657        self.info_box.set_enemy_damage(enemy_damage)
658
659        self.arrow.index = 0
660        self.attack_enemy(enemy_damage)
661        self.set_timer_to_current_time()
662
663    def switch_enemy(self):
664        """
665        Switch which enemy the player is attacking.
666        """
667        if self.enemy_index < len(self.enemy_list) - 1:
668            self.enemy_index += 1
669            self.enter_enemy_attack_state()
670
671    def enter_run_away_state(self):
672        """
673        Transition battle into the run away state.
674        """
675        self.state = self.info_box.state = c.RUN_AWAY
676        self.arrow.state = 'invisible'
677        self.player.state = c.RUN_AWAY
678        self.set_timer_to_current_time()
679        self.notify(c.RUN_AWAY)
680
681    def enter_battle_won_state(self):
682        """
683        Transition battle into the battle won state.
684        """
685        self.notify(c.BATTLE_WON)
686        self.state = self.info_box.state = c.BATTLE_WON
687        self.player.state = c.VICTORY_DANCE
688        self.set_timer_to_current_time()
689
690    def enter_show_gold_state(self):
691        """
692        Transition battle into the show gold state.
693        """
694        self.inventory['GOLD']['quantity'] += self.new_gold
695        self.state = self.info_box.state = c.SHOW_GOLD
696        self.set_timer_to_current_time()
697
698    def enter_show_experience_state(self):
699        """
700        Transition battle into the show experience state.
701        """
702        self.state = self.info_box.state = c.SHOW_EXPERIENCE
703        self.set_timer_to_current_time()
704
705    def enter_level_up_state(self):
706        """
707        Transition battle into the LEVEL UP state.
708        """
709        self.state = self.info_box.state = c.LEVEL_UP
710        self.info_box.reset_level_up_message()
711        self.set_timer_to_current_time()
712
713    def enter_two_actions_per_turn_state(self):
714        self.state = self.info_box.state = c.TWO_ACTIONS
715        self.set_timer_to_current_time()
716
717    def execute_player_actions(self):
718        """
719        Execute the player actions.
720        """
721        if self.player_level < 3:
722            if self.player_actions:
723                enter_state = self.player_action_dict[self.player_actions[0]]
724                enter_state()
725                self.player_actions.pop(0)
726        else:
727            if len(self.player_actions) == 2:
728                enter_state = self.player_action_dict[self.player_actions[0]]
729                enter_state()
730                self.player_actions.pop(0)
731                self.action_selected = False
732            else:
733                if self.action_selected:
734                    self.enter_select_action_state()
735                    self.action_selected = False
736
737
738
739
740
741
742
743
744