Esempio n. 1
0
    def test_navigation(self):
        # Use declaratively defined game but could just as easily be
        # created procedurally
        game = vengeance.create_game({
            'directions': [
                {'name': 'up', 'opposite': 'down'},
                {'name': 'in', 'opposite': 'out'},
                {'name': 'west', 'opposite': 'east'}
            ],
            'rooms': [
                {'name': 'A Church',
                 'description': 'Tiny place of worship',
                 'exits': [
                     {'to': 'The Crypt', 'direction': 'down'}
                 ]},
                {'name': 'The Crypt',
                 'description': 'Dusty tomb filled with empty sarcophagi',
                 'exits': [
                     {'to': 'A Coffin', 'direction': 'in', 'one_way': True},
                     {'to': 'A Cave', 'direction': 'west'}
                 ]},
                {'name': 'A Coffin',
                 'description': 'A tight squeeze and pitch dark'},
                {'name': 'A Cave',
                 'description': 'A dark and dingy place'}
            ],
        })

        commands = ['d', 'w', 'e', 'i']

        for command in commands:
            game.process_input(command)

        self.assertEquals('A Coffin', game.character.current_location.name)
Esempio n. 2
0
    def test_exit_direction(self):
        exit_direction = 'down'

        game = vengeance.create_game({
            'directions': [
                {'name': 'up', 'opposite': exit_direction},
            ],
            'rooms': [
                {'name': 'Room A',
                 'description': 'A',
                 'exits': [
                     {'to': 'Room B', 'direction': exit_direction}
                 ]},
                {'name': 'Room B',
                 'description': 'B'}
            ]
        })

        exit = game.find_location('Room A').exits[0]
        self.assertEqual(exit_direction, exit.direction.name)
Esempio n. 3
0
    def test_two_way_exit(self):
        game = vengeance.create_game({
            'directions': [
                {'name': 'up', 'opposite': 'down'},
            ],
            'rooms': [
                {'name': 'Room A',
                 'description': 'A',
                 'exits': [
                     {'to': 'Room B', 'direction': 'down'}
                 ]},
                {'name': 'Room B',
                 'description': 'B'}
            ]
        })

        room_a = game.find_location('Room A')
        self.assertEqual(1, len(room_a.exits))
        room_b = game.find_location('Room B')
        self.assertEqual(1, len(room_b.exits))
Esempio n. 4
0
    def test_directions_have_initials_as_synonyms(self):
        exit_direction = 'down'

        game = vengeance.create_game({
            'directions': [
                {'name': 'up', 'opposite': exit_direction},
            ],
            'rooms': [
                {'name': 'Room A',
                 'description': 'A',
                 'exits': [
                     {'to': 'Room B', 'direction': exit_direction}
                 ]},
                {'name': 'Room B',
                 'description': 'B'}
            ]
        })

        game.process_input(exit_direction[0])

        self.assertEqual('Room B', game.character.current_location.name)
Esempio n. 5
0
import vengeance

# Use declaratively defined game but could just as easily be
# created procedurally
game = vengeance.create_game({
    'directions': [
        {'name': 'up', 'opposite': 'down'},
        {'name': 'in', 'opposite': 'out'},
        {'name': 'west', 'opposite': 'east'}
    ],
    'rooms': [
        {'name': 'A Church',
         'description': 'Tiny place of worship',
         'exits': [
             {'to': 'The Crypt', 'direction': 'down'}
         ]},
        {'name': 'The Crypt',
         'description': 'Dusty tomb filled with empty sarcophagi',
         'exits': [
             {'to': 'A Coffin', 'direction': 'in', 'one_way': True},
             {'to': 'A Cave', 'direction': 'west'}
         ]},
        {'name': 'A Coffin',
         'description': 'A tight squeeze and pitch dark'},
        {'name': 'A Cave',
         'description': 'A dark and dingy place'}
    ],
})

# Add a prompt to indicate when the game is waiting for user input
def prompt_for_input():
    return raw_input('> ')