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 extra_experience = player_stats['experience to next level'] * -1
330 player_stats['Level'] += 1
331 player_stats['health']['maximum'] += int(player_stats['health']['maximum']*.25)
332 player_stats['magic']['maximum'] += int(player_stats['magic']['maximum']*.20)
333 new_experience = int((player_stats['Level'] * 50) * .75)
334 player_stats['experience to next level'] = new_experience - extra_experience
335 self.enter_level_up_state()
336 self.just_leveled_up = True
337 else:
338 self.end_battle()
339
340 elif self.state == c.PLAYER_DAMAGED:
341 if (self.current_time - self.timer) > 600:
342 if self.enemy_index == (len(self.enemy_list) - 1):
343 if self.run_away:
344 self.enter_run_away_state()
345 else:
346 self.enter_select_action_state()
347 else:
348 self.switch_enemy()
349 self.timer = self.current_time
350
351 def check_if_battle_won(self):
352 """
353 Check if state is SELECT_ACTION and there are no enemies left.
354 """
355 if self.state == c.SELECT_ACTION:
356 if len(self.enemy_group) == 0:
357 self.enter_battle_won_state()
358
359 def notify(self, event):
360 """
361 Notify observer of event.
362 """
363 for new_observer in self.observers:
364 new_observer.on_notify(event)
365
366 def end_battle(self):
367 """
368 End battle and flip back to previous state.
369 """
370 if self.game_data['battle type'] == 'evilwizard':
371 self.game_data['crown quest'] = True
372 self.game_data['last state'] = self.name
373 self.game_data['battle counter'] = random.randint(50, 255)
374 self.game_data['battle type'] = None
375 self.state = 'transition out'
376
377 def attack_enemy(self, enemy_damage):
378 enemy = self.player.attacked_enemy
379 enemy.health -= enemy_damage
380 self.set_enemy_indices()
381
382 if enemy:
383 enemy.enter_knock_back_state()
384 if enemy.health <= 0:
385 self.enemy_list.pop(enemy.index)
386 enemy.state = c.FADE_DEATH
387 self.arrow.remove_pos(self.player.attacked_enemy)
388 self.enemy_index = 0
389
390 def set_enemy_indices(self):
391 for i, enemy in enumerate(self.enemy_list):
392 enemy.index = i
393
394 def draw_battle(self, surface):
395 """Draw all elements of battle state"""
396 self.background.draw(surface)
397 self.enemy_group.draw(surface)
398 self.attack_animations.draw(surface)
399 self.sword.draw(surface)
400 surface.blit(self.player.image, self.player.rect)
401 surface.blit(self.info_box.image, self.info_box.rect)
402 surface.blit(self.select_box.image, self.select_box.rect)
403 surface.blit(self.arrow.image, self.arrow.rect)
404 self.player_health_box.draw(surface)
405 self.damage_points.draw(surface)
406 self.draw_transition(surface)
407
408 def draw_transition(self, surface):
409 """
410 Fade in and out of state.
411 """
412 if self.state == 'transition in':
413
414 transition_image = pg.Surface(self.transition_rect.size)
415 transition_image.fill(c.TRANSITION_COLOR)
416 transition_image.set_alpha(self.transition_alpha)
417 surface.blit(transition_image, self.transition_rect)
418 self.transition_alpha -= c.TRANSITION_SPEED
419 if self.transition_alpha <= 0:
420 self.state = c.SELECT_ACTION
421 self.transition_alpha = 0
422
423 elif self.state == 'transition out':
424 transition_image = pg.Surface(self.transition_rect.size)
425 transition_image.fill(c.TRANSITION_COLOR)
426 transition_image.set_alpha(self.transition_alpha)
427 surface.blit(transition_image, self.transition_rect)
428 self.transition_alpha += c.TRANSITION_SPEED
429 if self.transition_alpha >= 255:
430 self.done = True
431
432 def player_damaged(self, damage):
433 self.game_data['player stats']['health']['current'] -= damage
434
435 def player_healed(self, heal, magic_points=0):
436 """
437 Add health from potion to game data.
438 """
439 health = self.game_data['player stats']['health']
440
441 health['current'] += heal
442 if health['current'] > health['maximum']:
443 health['current'] = health['maximum']
444
445 if self.state == c.DRINK_HEALING_POTION:
446 self.game_data['player inventory']['Healing Potion']['quantity'] -= 1
447 if self.game_data['player inventory']['Healing Potion']['quantity'] == 0:
448 del self.game_data['player inventory']['Healing Potion']
449 elif self.state == c.CURE_SPELL:
450 self.game_data['player stats']['magic']['current'] -= magic_points
451
452 def magic_boost(self, magic_points):
453 """
454 Add magic from ether to game data.
455 """
456 magic = self.game_data['player stats']['magic']
457 magic['current'] += magic_points
458 if magic['current'] > magic['maximum']:
459 magic['current'] = magic['maximum']
460
461 self.game_data['player inventory']['Ether Potion']['quantity'] -= 1
462 if not self.game_data['player inventory']['Ether Potion']['quantity']:
463 del self.game_data['player inventory']['Ether Potion']
464
465 def set_timer_to_current_time(self):
466 """Set the timer to the current time."""
467 self.timer = self.current_time
468
469 def cast_fire_blast(self):
470 """
471 Cast fire blast on all enemies.
472 """
473 self.notify(c.FIRE)
474 self.state = self.info_box.state = c.FIRE_SPELL
475 POWER = self.inventory['Fire Blast']['power']
476 POWER += self.game_data['player stats']['Level'] * 5
477 MAGIC_POINTS = self.inventory['Fire Blast']['magic points']
478 self.game_data['player stats']['magic']['current'] -= MAGIC_POINTS
479 for enemy in self.enemy_list:
480 DAMAGE = random.randint(POWER//2, POWER)
481 self.damage_points.add(
482 attackitems.HealthPoints(DAMAGE, enemy.rect.topright))
483 enemy.health -= DAMAGE
484 posx = enemy.rect.x - 32
485 posy = enemy.rect.y - 64
486 fire_sprite = attack.Fire(posx, posy)
487 self.attack_animations.add(fire_sprite)
488 if enemy.health <= 0:
489 enemy.kill()
490 self.arrow.remove_pos(enemy)
491 else:
492 enemy.enter_knock_back_state()
493 self.enemy_list = [enemy for enemy in self.enemy_list if enemy.health > 0]
494 self.enemy_index = 0
495 self.arrow.index = 0
496 self.arrow.state = 'invisible'
497 self.set_timer_to_current_time()
498
499 def cast_cure(self):
500 """
501 Cast cure spell on player.
502 """
503 self.state = c.CURE_SPELL
504 HEAL_AMOUNT = self.inventory['Cure']['power']
505 MAGIC_POINTS = self.inventory['Cure']['magic points']
506 self.player.healing = True
507 self.set_timer_to_current_time()
508 self.arrow.state = 'invisible'
509 self.enemy_index = 0
510 self.damage_points.add(
511 attackitems.HealthPoints(HEAL_AMOUNT, self.player.rect.topright, False))
512 self.player_healed(HEAL_AMOUNT, MAGIC_POINTS)
513 self.info_box.state = c.DRINK_HEALING_POTION
514 self.notify(c.POWERUP)
515
516 def enter_select_enemy_state(self):
517 """
518 Transition battle into the select enemy state.
519 """
520 self.state = self.arrow.state = c.SELECT_ENEMY
521 self.arrow.index = 0
522
523 def enter_select_item_state(self):
524 """
525 Transition battle into the select item state.
526 """
527 self.state = self.info_box.state = c.SELECT_ITEM
528 self.arrow.become_select_item_state()
529
530 def enter_select_magic_state(self):
531 """
532 Transition battle into the select magic state.
533 """
534 self.state = self.info_box.state = c.SELECT_MAGIC
535 self.arrow.become_select_magic_state()
536
537 def try_to_run_away(self):
538 """
539 Transition battle into the run away state.
540 """
541 self.run_away = True
542 self.arrow.state = 'invisible'
543 self.enemy_index = 0
544 self.enter_enemy_attack_state()
545
546 def enter_enemy_attack_state(self):
547 """
548 Transition battle into the Enemy attack state.
549 """
550 self.state = self.info_box.state = c.ENEMY_ATTACK
551 enemy = self.enemy_list[self.enemy_index]
552 enemy.enter_enemy_attack_state()
553
554 def enter_player_attack_state(self):
555 """
556 Transition battle into the Player attack state.
557 """
558 self.state = self.info_box.state = c.PLAYER_ATTACK
559 enemy_to_attack = self.enemies_to_attack.pop(0)
560 if enemy_to_attack in self.enemy_list:
561 self.player.enter_attack_state(enemy_to_attack)
562 else:
563 if self.enemy_list:
564 self.player.enter_attack_state(self.enemy_list[0])
565 else:
566 self.enter_battle_won_state()
567 self.arrow.state = 'invisible'
568
569 def get_enemy_to_attack(self):
570 """
571 Get enemy for player to attack by arrow position.
572 """
573 enemy_posx = self.arrow.rect.x + 60
574 enemy_posy = self.arrow.rect.y - 20
575 enemy_pos = (enemy_posx, enemy_posy)
576 enemy_to_attack = None
577
578 for enemy in self.enemy_list:
579 if enemy.rect.topleft == enemy_pos:
580 enemy_to_attack = enemy
581
582 return enemy_to_attack
583
584
585 def enter_drink_healing_potion_state(self):
586 """
587 Transition battle into the Drink Healing Potion state.
588 """
589 self.state = self.info_box.state = c.DRINK_HEALING_POTION
590 self.player.healing = True
591 self.set_timer_to_current_time()
592 self.arrow.state = 'invisible'
593 self.enemy_index = 0
594 self.damage_points.add(
595 attackitems.HealthPoints(30,
596 self.player.rect.topright,
597 False))
598 self.player_healed(30)
599 self.notify(c.POWERUP)
600
601 def enter_drink_ether_potion_state(self):
602 """
603 Transition battle into the Drink Ether Potion state.
604 """
605 self.state = self.info_box.state = c.DRINK_ETHER_POTION
606 self.player.healing = True
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 True))
614 self.magic_boost(30)
615 self.set_timer_to_current_time()
616 self.notify(c.POWERUP)
617
618 def enter_select_action_state(self):
619 """
620 Transition battle into the select action state
621 """
622 self.state = self.info_box.state = c.SELECT_ACTION
623 self.arrow.index = 0
624 self.arrow.state = self.state
625
626 def enter_player_damaged_state(self):
627 """
628 Transition battle into the player damaged state.
629 """
630 self.state = self.info_box.state = c.PLAYER_DAMAGED
631 if self.enemy_index > len(self.enemy_list) - 1:
632 self.enemy_index = 0
633 enemy = self.enemy_list[self.enemy_index]
634 player_damage = enemy.calculate_hit(self.inventory['equipped armor'],
635 self.inventory)
636 self.damage_points.add(
637 attackitems.HealthPoints(player_damage,
638 self.player.rect.topright))
639 self.info_box.set_player_damage(player_damage)
640 self.set_timer_to_current_time()
641 self.player_damaged(player_damage)
642 if player_damage:
643 sfx_num = random.randint(1,3)
644 self.notify('punch{}'.format(sfx_num))
645 self.player.damaged = True
646 self.player.enter_knock_back_state()
647
648 def enter_enemy_damaged_state(self):
649 """
650 Transition battle into the enemy damaged state.
651 """
652 self.state = self.info_box.state = c.ENEMY_DAMAGED
653 enemy_damage = self.player.calculate_hit()
654 self.damage_points.add(
655 attackitems.HealthPoints(enemy_damage,
656 self.player.attacked_enemy.rect.topright))
657
658 self.info_box.set_enemy_damage(enemy_damage)
659
660 self.arrow.index = 0
661 self.attack_enemy(enemy_damage)
662 self.set_timer_to_current_time()
663
664 def switch_enemy(self):
665 """
666 Switch which enemy the player is attacking.
667 """
668 if self.enemy_index < len(self.enemy_list) - 1:
669 self.enemy_index += 1
670 self.enter_enemy_attack_state()
671
672 def enter_run_away_state(self):
673 """
674 Transition battle into the run away state.
675 """
676 self.state = self.info_box.state = c.RUN_AWAY
677 self.arrow.state = 'invisible'
678 self.player.state = c.RUN_AWAY
679 self.set_timer_to_current_time()
680 self.notify(c.RUN_AWAY)
681
682 def enter_battle_won_state(self):
683 """
684 Transition battle into the battle won state.
685 """
686 self.notify(c.BATTLE_WON)
687 self.state = self.info_box.state = c.BATTLE_WON
688 self.player.state = c.VICTORY_DANCE
689 self.set_timer_to_current_time()
690
691 def enter_show_gold_state(self):
692 """
693 Transition battle into the show gold state.
694 """
695 self.inventory['GOLD']['quantity'] += self.new_gold
696 self.state = self.info_box.state = c.SHOW_GOLD
697 self.set_timer_to_current_time()
698
699 def enter_show_experience_state(self):
700 """
701 Transition battle into the show experience state.
702 """
703 self.state = self.info_box.state = c.SHOW_EXPERIENCE
704 self.set_timer_to_current_time()
705
706 def enter_level_up_state(self):
707 """
708 Transition battle into the LEVEL UP state.
709 """
710 self.state = self.info_box.state = c.LEVEL_UP
711 self.info_box.reset_level_up_message()
712 self.set_timer_to_current_time()
713
714 def enter_two_actions_per_turn_state(self):
715 self.state = self.info_box.state = c.TWO_ACTIONS
716 self.set_timer_to_current_time()
717
718 def execute_player_actions(self):
719 """
720 Execute the player actions.
721 """
722 if self.player_level < 3:
723 if self.player_actions:
724 enter_state = self.player_action_dict[self.player_actions[0]]
725 enter_state()
726 self.player_actions.pop(0)
727 else:
728 if len(self.player_actions) == 2:
729 enter_state = self.player_action_dict[self.player_actions[0]]
730 enter_state()
731 self.player_actions.pop(0)
732 self.action_selected = False
733 else:
734 if self.action_selected:
735 self.enter_select_action_state()
736 self.action_selected = False
737
738
739
740
741
742
743
744
745