예제 #1
0
class ConsoleController:
    def __init__(self: 'ConsoleController', number_of_cheeses: int,
                 number_of_stools: int) -> None:
        """
        Initialize a new 'ConsoleController'.
        """

        TOAHModel.__init__(self, number_of_stools)
        TOAHModel.fill_first_stool(self, number_of_cheeses)
        self.cheese_model = TOAHModel(number_of_stools)
        self.number_of_stools = number_of_stools
        self.cheese_model.fill_first_stool(number_of_cheeses)

    def play_loop(self: 'ConsoleController') -> None:
        '''    
        Console-based game. 
        TODO:
        -Start by giving instructions about how to enter moves (which is up to
        you). Be sure to provide some way of exiting the game, and indicate
        that in the instructions.
        -Use python's built-in function input() to read a potential move from
        the user/player. You should print an error message if the input does
        not meet the specifications given in your instruction or if it denotes
        an invalid move (e.g. moving a cheese onto a smaller cheese).
        You can print error messages from this method and/or from
        ConsoleController.move; it's up to you.
        -After each valid move, use the method TOAHModel.__str__ that we've 
        provided to print a representation of the current state of the game.
        '''
        instructions = input("In order to make a move, you must insert the \
initial_stool number and the final_stool number seperated by a comma. If you \
wish to exit the game, input 'exit' and answer'yes'. Press enter to begin!")

        prompt = input('Your move (initial_stool, final_stool):')
        while prompt != 'exit':
            new_list = prompt.split(sep=',')
            move_list = []
            try:
                int(new_list[0]) or int(new_list[1])
            except ValueError:
                print('Invalid entry! Try again')
                prompt = input('Your move (initial_stool, final_stool):')

            move_list.append(int(new_list[0]))
            move_list.append(int(new_list[1]))
            move(self.cheese_model, move_list[0], move_list[1])
            print(self.cheese_model.__str__())
            prompt = input('Your move (initial_stool, final_stool):')

        else:
            exit()