Exemplo n.º 1
0
 def testOutputOfUnknownObjectInMap(self, _mock_print):
     game_map = Map2D(1, 1)
     game_map.put('some_object', 0, 0)
     text_output = TextOutput()
     with self.assertRaises(RuntimeError) as context:
         text_output.draw_map(game_map)
     self.assertIn('Unknown object class', str(context.exception))
Exemplo n.º 2
0
 def testOutputOfFoodObjectInMap(self, mock_print):
     game_map = Map2D(1, 1)
     Food(game_map)
     text_output = TextOutput()
     text_output.draw_map(game_map)
     calls = [call('+-+'), call('|F|'), call('+-+')]
     mock_print.assert_has_calls(calls)
Exemplo n.º 3
0
 def testSnakeMoveDown(self, mock_print):
     game_map = Map2D(2, 2)
     snake = Snake(game_map, 0, 0, Direction.Y_POSITIVE)
     snake.move()
     text_output = TextOutput()
     text_output.draw_map(game_map)
     calls = [call('+-+-+'), call('|.|.|'), call('|O|.|'), call('+-+-+')]
     mock_print.assert_has_calls(calls)
Exemplo n.º 4
0
 def testOutputOfSnakeObjectInMap(self, mock_print):
     game_map = Map2D(1, 2)
     snake = Snake(game_map, 0, 0, Direction.Y_POSITIVE)
     Food(game_map)
     snake.move()
     text_output = TextOutput()
     text_output.draw_map(game_map)
     calls = [call('+-+'), call('|x|'), call('|O|'), call('+-+')]
     mock_print.assert_has_calls(calls)
Exemplo n.º 5
0
    def testGameResult(self, mock_print):
        text_output = TextOutput()
        text_output.show_game_result(True)
        text_output.show_game_result(False)

        calls = [call('Game won'), call('Game lost')]
        mock_print.assert_has_calls(calls)
Exemplo n.º 6
0
def main():
    if settings.input_interface == 'Keyboard':
        input_interface = Keyboard(settings.time_step_seconds)
    elif settings.input_interface == 'ML':
        input_interface = MLInput()
    else:
        raise RuntimeError(
            f'Unknown input interface {settings.input_interface}')

    if settings.output_interface == 'Text':
        output_interface = TextOutput()
    elif settings.output_interface == 'Pygame':
        output_interface = PygameOutput()
    else:
        raise RuntimeError(
            f'Unknown output interface {settings.output_interface}')

    SnakeGame.run(input_interface, output_interface, settings.dim_x,
                  settings.dim_y)
Exemplo n.º 7
0
 def testOutputOfEmptyMap(self, mock_print):
     game_map = Map2D(2, 2)
     text_output = TextOutput()
     text_output.draw_map(game_map)
     calls = [call('+-+-+'), call('|.|.|'), call('|.|.|'), call('+-+-+')]
     mock_print.assert_has_calls(calls)