Ejemplo n.º 1
0
    def test_setting_opposite_also_sets_reverse(self):
        east = Direction('east')
        west = Direction('west')

        east.opposite = west

        self.assertEquals(east.name, west.opposite.name)
Ejemplo n.º 2
0
    def test_setting_opposite(self):
        east = Direction('east')
        west = Direction('west')

        east.opposite = west

        self.assertEquals(west.name, east.opposite.name)
Ejemplo n.º 3
0
def _create_directions(direction_data):
    """
    Creates the directions in the game.

    direction_data: Details of the directions in the game
    """
    directions = []
    for datum in direction_data:
        _check_direction_well_formed(datum)

        # Disable 'Used * or ** magic
        # pylint: disable=W0142
        direction = _Struct(**datum)
        direction_names = [d.name for d in directions]
        _check_direction_valid(direction, direction_names)

        # Disable 'Instance of '_Struct' has no 'name' member
        # Disable 'Instance of '_Struct' has no 'opposite' member
        # pylint: disable=E1101
        name = direction.name
        opposite = direction.opposite

        reserved_word = 'quit'
        name_key = _direction_name_key()
        _check_if_direction_is_reserved(reserved_word, name, name_key)
        opposite_key = _direction_opposite_key()
        _check_if_direction_is_reserved(reserved_word, opposite, opposite_key)

        direction = Direction(name)
        opposite_direction = Direction(opposite)
        direction.opposite = opposite_direction
        opposite_direction.opposite = direction
        directions.append(direction)
        directions.append(opposite_direction)

    return directions
Ejemplo n.º 4
0
 def __init__(self, direction_name, opposite_name):
     direction = Direction(direction_name)
     opposite = Direction(opposite_name)
     direction.opposite = opposite
     self._direction = direction