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)
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)
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))
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)
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('> ')