diff --git a/logic/__tests__/knights_queue_test.py b/logic/__tests__/knights_queue_test.py index 0772a2c..782be15 100644 --- a/logic/__tests__/knights_queue_test.py +++ b/logic/__tests__/knights_queue_test.py @@ -5,6 +5,19 @@ from models.knight import Knight class KnightsQueueTest(unittest.TestCase): + def test_should_make_valid_next_turn(self): + knight1 = Knight(None) + knight1.health = 222 + knight2 = Knight(None) + knight2.health = 1 + + knights_queue = KnightsQueue([knight1], [knight2]) + previous_turn = knights_queue.team_idx_turn + knights_queue.dequeue_knight() + current_turn = knights_queue.team_idx_turn + + self.assertNotEqual(previous_turn, current_turn) + def test_should_raise_when_team_has_dead_knights(self): with self.assertRaises(Exception): knight1 = Knight(None) diff --git a/logic/game.py b/logic/game.py index bee0c6c..3545d8b 100644 --- a/logic/game.py +++ b/logic/game.py @@ -5,6 +5,7 @@ import pygame from common.colors import FONT_DARK, WHITE from common.constants import * from common.helpers import draw_text +from logic.knights_queue import KnightsQueue from models.castle import Castle from models.knight import Knight from models.monster import Monster @@ -87,7 +88,6 @@ class Game: stats = Stats() logs = Logs() - knights_sprite_group = pygame.sprite.Group() monsters_sprite_group = pygame.sprite.Group() castle_sprite_group = pygame.sprite.Group() @@ -95,6 +95,8 @@ class Game: knights_left = self.generate_knights_team(knights_sprite_group) knights_right = self.generate_knights_team(knights_sprite_group) + knights_queue = KnightsQueue(knights_left, knights_right) + spawn_left_team = Spawner(grid, knights_left, width=KNIGHTS_SPAWN_WIDTH, height=KNIGHTS_SPAWN_HEIGHT, pos_row=KNIGHTS_SPAWN_FIRST_ROW, pos_column=KNIGHTS_SPAWN_FIRST_COL) spawn_right_team = Spawner(grid, knights_right, width=KNIGHTS_SPAWN_WIDTH, height=KNIGHTS_SPAWN_HEIGHT, diff --git a/logic/knights_queue.py b/logic/knights_queue.py index 42960eb..cb3ba2c 100644 --- a/logic/knights_queue.py +++ b/logic/knights_queue.py @@ -14,12 +14,12 @@ class KnightsQueue: self.dequeue_knight() else: self.queues[self.team_idx_turn].append(knight) - self.next_round() + self.next_turn() return knight raise Exception('Game has just ended') def both_teams_alive(self): return len(self.queues[0]) > 0 and len(self.queues[1]) > 0 - def next_round(self): + def next_turn(self): self.team_idx_turn = (self.team_idx_turn + 1) % 2