tests: added test case
This commit is contained in:
parent
bef17bccd1
commit
f06ea9e5b0
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user