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