Example #1
0
    def test_initialization_enables_score(self):
        """
        Tests, that calling GameController.initialize() allows to acces GameCon-
        troller.score afterwards. Before, it raises a GameNotInitializedError.
        """
        self.game_field = GameField.basic_field(self.tile_collection)
        self.game_controller = GameController(
            self.game_field,
            self.tile_collection
        )

        with self.assertRaises(GameNotInitializedError):
            score = self.game_controller.score
        self.game_controller.initialize()
        self.assertEqual(0, self.game_controller.score)
Example #2
0
 def __init__(
         self,
         input_stream: ConsoleInput,
         output_stream: ConsoleOutput
 ):
     self.input = input_stream
     self.output = output_stream
     self.tile_collection = TileCollection()
     self.game_field = GameField.basic_field(self.tile_collection)
     self.game_controller = GameController(
         self.game_field,
         self.tile_collection
     )
     self.game_controller.initialize()
     self.renderer = ConsoleRenderer(output_stream)  # type: Renderer
     self.prompt_counter = 0
Example #3
0
from controller.game_controller import GameController
from gamefield.gamefield import GameField
from gamefield.tilecollection import TileCollection
from exceptions import GameLostError, InvalidActionError, \
    GameNotInitializedError

tile_collection = TileCollection()
game_field = GameField.basic_field(tile_collection)
game_controller = GameController(game_field, tile_collection)

# If the game was not initialized yet, the score is not accessible
try:
    game_controller.score
except GameNotInitializedError as e:
    print(e)

game_controller.initialize()

# score is returned after each action and each action can raise an
# InvalidActionError if the called action can't be executed:
try:
    score = game_controller.swipe_north_action()
    score = game_controller.swipe_east_action()
    score = game_controller.swipe_south_action()
    score = game_controller.swipe_west_action()
except InvalidActionError as e:
    print(e)
# score can be accessed at any time:
score = game_controller.score

# when there is no move left, a GameLostError is raised:
Example #4
0
 def setUp(self):
     # basic_field instantiates a GameField and fills it with TileContainers
     # and empty Tiles
     self.tile_collection = TileCollection()
     self.game_field = GameField.basic_field(self.tile_collection)