Example #1
0
 def new_game(string_board):
     """
     Create and return a new game with all the required components.
     :param board: Passed board in string form that contains players and pieces.
     :type string
     :return: A new game.
     :rtype: Game
     """
     board = Board()
     Parser.parse_board(string_board, board)
     console = Console(board)
     return Game(console)
Example #2
0
def main(argv):
    """
    Method that gets executed to run a game of colonies.
    :param argv: Passed argument list to program. File to parse.
    :type argv: list
    """
    if len(argv) < 2:
        logger.error("ERROR - Need to supply file as input.")
        return

    # Parse the provided file into a Board object.
    sample_game_board = Board()
    Parser.parse_file(argv[1], sample_game_board)

    # Play a game of Colonies with the newly created board.
    console = Console(sample_game_board)
    console.play()
Example #3
0
    def test_parse_file(self):
        """ 
        Test the parser by constructing a Board from a file.
        Validate that all expected Pieces and Players have been created. 
        """

        # Make input file directory location os-agnostic. 
        test_level_path = os.path.join('source', 'game', 'tests', 'resources', 'test_level_1')

        # Parse the test file into a Board object.
        sample_game_board = Board()
        Parser.parse_file(test_level_path, sample_game_board)

        # Validate that board is the correct size and all related objects are created.
        assert sample_game_board.width is 5
        assert sample_game_board.height is 5
        assert len(sample_game_board.pieces) is 5
        assert len(sample_game_board.players) is 4
        assert len(sample_game_board.zones) is 1