Esempio n. 1
0
class GameController(object):
    """
    This abstract class contains the shared logic for all game controllers. It is not meant to be used in itself, but
    works as a back-bone for all types of game controller.
    """

    def __init__(self):
        """
        Ctor - Initialises game controller.
        """
        pass

    def set_up_game(self):
        """
        This method sets up the game to be played by this controller.
        """
        self._game = Game()

    def get_game(self):
        """
        This method retrieves the game currently being played by the game controller.

        @return The game currently being played.
        """
        return self._game

    def play_next_turn(self):
        """
        This method plays a single turn of the game.
        """
        self._game.next_turn()
Esempio n. 2
0
    def test_get_turn_count(self):
        '''
        Tests whether the get_turn_count() method functions correctly.
        '''
        g = Game()
        g.next_turn()

        assert g.get_turn_count() == 1
Esempio n. 3
0
    def test_next_turn(self):
        '''
        Tests whether the Game.next_turn() method functions correctly.
        '''
        g = Game()

        g.next_turn()
        assert g._turn_count == 1
Esempio n. 4
0
    def next_turn(self):
        """
        Runs the next turn in the Game of life.
        """
        # Takes the current generation and passes to calculator
        cur_gen = self.get_current_generation()
        nex_gen = self._calculate_next_generation(cur_gen)

        # Stores next generation in self._next_generation
        self._set_next_generation(nex_gen)

        # The state in of the next generation is stored as the current
        # generation
        self._current_generation.set_cells(nex_gen.get_cells())

        # Increment turn count
        Game.next_turn(self)
Esempio n. 5
0
    def next_turn(self):
        '''
        Runs the next turn in the Game of life.
        '''
        # Takes the current generation and passes to calculator
        cur_gen = self.get_current_generation()
        nex_gen = self._calculate_next_generation(cur_gen)

        # Stores next generation in self._next_generation
        self._set_next_generation(nex_gen)

        # Passes current generation back to Game Control to be shown on
        # the GUI.
        pass

        # The state in of the next generation is stored as the current
        # generation
        self._current_generation.set_cells(nex_gen.get_cells())

        # Increment turn count
        Game.next_turn(self)
Esempio n. 6
0
class GameController(object):
    '''
    This class represents a skeleton from which game controls
    can inherit. It contains all the shared functionality of
    all game controls.
    '''

    def __init__(self, time):
        '''
        Ctor - Initialises game controller.
        '''
        self._timer = Timer(time)

    def set_up_game(self):
        '''
        Sets up the game to be played by this controller.
        '''
        self._game = Game()

    def get_game(self):
        '''
        Returns the game currently being played.
        '''
        return self._game

    def get_time_remaining(self):
        '''
        Returns the timer being used on this game controller.
        '''
        return self._timer.get_time_remaining()

    def play_next_turn(self):
        '''
        Plays a single turn of the game.
        '''
        self._game.next_turn()