def test_level_over_but_not_game_over_when_player_beats_level(self): state = create_two_level_game_state(num_players=1) self.assertFalse(RuleChecker.is_game_over(state)) self.assertFalse(RuleChecker.is_level_over(state)) RuleChecker.validate_game_state(state) # move player to key state.update("p0", (7, 12)) # move player to exit state.update("p0", (7, 13)) self.assertFalse(RuleChecker.is_game_over(state))
def test_game_not_over_when_one_player_dies(self): state = create_two_level_game_state() self.assertFalse(RuleChecker.is_game_over(state)) self.assertFalse(RuleChecker.is_level_over(state)) RuleChecker.validate_game_state(state) a1_location = state.occupants["a1"].current_location with self.assertRaises(InvalidOccupantTurnOrder): RuleChecker.validate_move(state, "p1", a1_location) state.update("p1", a1_location) self.assertFalse(RuleChecker.is_game_over(state)) self.assertFalse(RuleChecker.is_level_over(state))
def test_game_over_players_die(self): actual = create_two_level_game_state(4, False) self.assertEqual(actual.current_level, 0, "Unexpected current level.") self.assertEqual(actual.current_turn, "p0", "Unexpected current turn") self.assertFalse(actual.is_exit_unlocked, "Level should be locked") self.assertFalse(actual.is_game_over, "Game should not be over") # move adversary to all players player_locations = [p.current_location for p in actual.players] for _ in range(5): for location in player_locations: actual.update("a1", location) self.assertEqual(actual.current_level, 0, "Unexpected current level.") self.assertEqual(actual.current_turn, "a0", "Unexpected current turn") self.assertFalse(actual.is_exit_unlocked, "Level should be locked") self.assertTrue(actual.is_game_over, "Game should be over")
def test_progress_to_next_level(self): actual = create_two_level_game_state(num_players=1) self.assertEqual(actual.current_level, 0, "Unexpected current level.") self.assertEqual(actual.current_turn, "p0", "Unexpected current turn") self.assertFalse(actual.is_exit_unlocked, "Level should be locked") self.assertFalse(actual.is_game_over, "Game should not be over") # move player to key actual.update("p0", (7, 12)) self.assertEqual(actual.current_level, 0, "Unexpected current level.") self.assertEqual(actual.current_turn, "a0", "Unexpected current turn") self.assertTrue(actual.is_exit_unlocked, "Level should be unlocked") self.assertFalse(actual.is_game_over, "Game should not be over") # move player to exit actual.update("p0", (7, 13)) self.assertEqual(actual.current_level, 1, "Unexpected current level.") self.assertEqual(actual.current_turn, "p0", "Unexpected current turn") self.assertFalse(actual.is_exit_unlocked, "Level should not be unlocked") self.assertFalse(actual.is_game_over, "Game should not be over")
import sys sys.path.append('.') from src.Game.models.state_exporter import StateExporter from src.Game.views.colorful_textual_view import ColorfulTextualView from tests.Game.examples import create_two_level_game_state view = ColorfulTextualView() state = create_two_level_game_state() def observer_view(): view.render_observer_state(StateExporter.create_observer_game_state(state)) def player_update(): view.render_player_update(StateExporter.create_player_update(state, "p0")) def adversary_update(): update = StateExporter.create_adversary_game_state(state, "a0") print(update) def end_level(): view.render_level_over(StateExporter.create_end_level_state(state, 0)) def end_game(): view.render_game_over(StateExporter.create_end_game_state(state))
def create_two_level_game_state(self): create_two_level_game_state()