def test_character_movement(self): """ Test A Character moves, and the data of movement to disk """ self.reset_repo() locationJson = recordable.Recordable('mock-data', 'location') roomJson = recordable.Recordable('mock-data', 'worldRooms') recordables = [locationJson] testPlayer = character.Character(recordables) rooms = cavemap.Map(roomJson) testPlayer.move('north', rooms) self.assertEqual(testPlayer.location['location'], "Git Crystal") testPlayer.move('east', rooms) self.assertEqual(testPlayer.location['location'], "Mine Entrance") changedLocationJson = recordable.Recordable('mock-data', 'location') testPlayer.move('invalid Direction', rooms) self.assertEqual(testPlayer.location['location'], "Mine Entrance") testPlayer.move('west', rooms) testPlayer.move('south', rooms) originalLocationJson = recordable.Recordable('mock-data', 'location') self.assertNotEqual(locationJson, changedLocationJson) self.assertEqual(locationJson, originalLocationJson)
def test_non_player_character(self): aliveJson = recordable.Recordable('mock-data/characters', 'alive') statusJson = recordable.Recordable('mock-data/characters', 'status') relationshipJson = recordable.Recordable('mock-data/characters', 'relationship') recordables = [aliveJson, statusJson, relationshipJson] testNonPlayer = character.Character(recordables) # Values Based on Dragon NPC self.assertEqual(testNonPlayer.alive['alive'], True) self.assertEqual(testNonPlayer.status['asleep'], True) self.assertEqual(testNonPlayer.relationship['knows_player'], False) self.assertEqual(testNonPlayer.isPlayer, False)
def test_player_character(self): self.reset_repo() aliveJson = recordable.Recordable('mock-data', 'alive') statusJson = recordable.Recordable('mock-data', 'status') locationJson = recordable.Recordable('mock-data', 'location') inventoryJson = recordable.Recordable('mock-data', 'inventory') recordables = [aliveJson, statusJson, locationJson, inventoryJson] testPlayer = character.Character(recordables) self.assertEqual(testPlayer.inventory['weapons'][0], "Unarmed") self.assertEqual(testPlayer.alive['alive'], True) self.assertEqual(testPlayer.status['floating'], False) self.assertEqual(testPlayer.location['location'], "Mountain Gate")
def test_recordable_writes(self): """ I need to test that the recordable class properly writes files""" jsonFile = recordable.Recordable('mock-data') jsonFile.write() jsonFile.load() self.assertEqual(jsonFile.data['first'], "first") self.assertEqual(jsonFile.data['second'], "second")
def test_game_movement(self): """ Test Command Line Movement """ self.reset_repo() game = gitgame.GitGameCmd('mock-data') locationJson = recordable.Recordable('mock-data', 'location') game.do_north('') self.assertEqual(game.player.location['location'], "Git Crystal") game.do_east('') self.assertEqual(game.player.location['location'], "Mine Entrance") changedLocationJson = recordable.Recordable('mock-data', 'location') game.do_west('') game.do_south('') originalLocationJson = recordable.Recordable('mock-data', 'location') self.assertNotEqual(locationJson, changedLocationJson) self.assertEqual(locationJson, originalLocationJson)
def test_check_dangers(self): self.reset_repo() # Test Method on Map Object roomsJson = recordable.Recordable('mock-data', 'worldRooms') rooms = cavemap.Map(roomsJson) danger = rooms.getDanger('Bottomless Pit') self.assertEqual(danger, {'entry': 'floating'}) game = gitgame.GitGameCmd('mock-data') game.do_north('') game.do_north('') game.do_west('') game.do_west('') # Enter Bottomless Pit alive = game.player.alive status = game.player.status self.assertTrue(status['floating']) self.assertFalse(alive['alive']) self.assertTrue(game.postcmd('', '')) # True Exits The Game Playing Loop self.reset_repo()
def test_map_object(self): self.reset_repo() """ Test Map Returns Correct Room""" roomJson = recordable.Recordable('mock-data', 'worldRooms') rooms = cavemap.Map(roomJson) self.assertEqual(rooms.move('north', 'Mountain Gate'), 'Git Crystal')
def test_recordable_repr(self): """ I need to test the recordable test implments __repr__ as expected """ jsonFile = recordable.Recordable('mock-data') # Since dictionary keys can't be sorted, test with regex printed_regex = "The object base\nHas keys: \n(second|first), (first|second)" """
#!/usr/bin/env python3 import gamerepo, gitgame, recordable playing = True aliveJson = recordable.Recordable('saved-game', 'alive') gameIntro = """ Welcome to Git Crystals!') ========================') Type "help" for commands.' Press Ctrl-C to Quit at Any Time """ gitIntro = """ Welcome to Git Crystals! ========================') You are dead. Git Crystals is playing in Git Mode. Press Ctrl-C to Quit at Any Time """ while playing: if aliveJson.data['alive'] == True: game = gitgame.GitGameCmd('saved-game') print(gameIntro) print(game.displayPlayerLocation(game.map)) game.cmdloop() aliveJson.load() else: game = gamerepo.GitCmd('saved-game') print(gitIntro) game.cmdloop() aliveJson.load()