def test_set_energy(self):
        test_player = Player()
        self.assertEqual(100, test_player.get_energy())

        test_player.set_energy(80)
        self.assertEqual(80, test_player.get_energy())

        test_player.set_energy(-15)
        self.assertEqual(0, test_player.get_energy())
    def test_set_alive(self):
        test_player = Player()
        self.assertTrue(test_player.get_alive())

        test_player.set_alive(False)
        self.assertFalse(test_player.get_alive())

        test_player.set_alive(True)
        self.assertTrue(test_player.get_alive())
    def test_set_location(self):
        test_player = Player()
        test_game = Auriga(test_player)

        test_player.set_location(test_game.assembly_room)
        self.assertEqual(test_player.get_location(), test_game.assembly_room)

        test_player.set_location(test_game.clean_room)
        self.assertEqual(test_player.get_location(), test_game.clean_room)
    def test_listen(self):
        test_player = Player()
        test_game = Auriga(test_player)
        test_game_player = test_game.player
        test_room = test_game.assembly_room
        test_game_player.set_location(test_room)

        test_game_player.set_energy(80)
        energy_before = test_game_player.get_energy()
        test_game_player.listen()
        self.assertEqual(test_game_player.get_energy(), energy_before + 1)
Esempio n. 5
0
def main():
    parser = ArgumentParser()
    parser.add_argument("name", help="The name of the game instance to create")
    args = parser.parse_args()

    # Create Player
    player = Player(name="Auriga-7B", energy=400)

    # # Create an instance of the Auriga game with the player and maze
    auriga = GenerateAuriga(player)
    auriga.save(args.name)
    def test_look(self):
        test_player = Player()
        test_game = Auriga(test_player)
        test_game_player = test_game.player
        test_room = test_game.assembly_room
        test_game_player.set_location(test_room)

        energy_before = test_game_player.get_energy()
        test_game_player.look(0)
        self.assertEqual(test_game_player.get_energy(), energy_before - 1)

        energy_before = test_game_player.get_energy()
        test_game_player.look(1)
        self.assertNotEqual(test_game_player.get_energy(), energy_before)
    def test_talk(self):
        test_player = Player()
        test_game = Auriga(test_player)
        test_game_player = test_game.player
        test_game_player.set_location(test_game.assembly_room)

        test_character = "pr-2"
        energy_before = test_game_player.get_energy()
        test_game_player.talk(test_character, 0)
        self.assertEqual(test_game_player.get_energy(), energy_before - 1)

        test_character = "c-3po"
        energy_before = test_game_player.get_energy()
        test_game_player.talk(test_character, 0)
        self.assertEqual(test_game_player.get_energy(), energy_before)
    def test_go_exit(self):
        test_player = Player()
        test_game = Auriga(test_player)
        test_game_player = test_game.player
        test_game_player.set_location(test_game.assembly_room)

        previous_location = test_game_player.get_location().name
        test_game_player.go_exit(0, direction="east", exit_name="sliding_door")
        current_location = test_game_player.get_location().name
        self.assertEqual(previous_location, current_location)

        test_game.push("button")
        previous_location = test_game_player.get_location().name
        test_game_player.go_exit(0, direction="east", exit_name="sliding_door")
        current_location = test_game_player.get_location().name
        self.assertNotEqual(previous_location, current_location)
    def test_look_at(self):
        test_player = Player()
        test_game = Auriga(test_player)
        test_game_player = test_game.player
        test_room = test_game.assembly_room
        test_game_player.set_location(test_room)

        test_item = "screwdriver"
        energy_before = test_game_player.get_energy()
        test_game_player.look_at(test_item)
        self.assertEqual(test_game_player.get_energy(), energy_before - 1)

        test_item = "cables"
        energy_before = test_game_player.get_energy()
        test_game_player.look_at(test_item)
        self.assertEqual(test_game_player.get_energy(), energy_before)
    def test_charge(self):
        test_player = Player()
        test_game = Auriga(test_player)
        test_game_player = test_game.player

        test_room = test_game.assembly_room
        test_game_player.set_location(test_room)
        test_game_player.set_energy(80)
        test_game_player.charge()
        self.assertEqual(test_game_player.get_energy(),
                         test_game_player.max_energy)

        test_room = test_game.testing_hangar
        test_game_player.set_location(test_room)
        test_game_player.set_energy(80)
        test_game_player.charge()
        self.assertNotEqual(test_game_player.get_energy(),
                            test_game_player.max_energy)
    def test_take(self):
        test_player = Player()
        test_game = Auriga(test_player)
        test_game_player = test_game.player
        test_game_player.set_location(test_game.assembly_room)

        test_item = "screwdriver"
        bad_item = "charger"
        energy_before = test_game_player.get_energy()
        test_game_player.take(test_item)
        test_player_inventory = [i.name for i in test_game_player.get_items()]
        self.assertIn(test_item, test_player_inventory)
        self.assertNotIn(bad_item, test_player_inventory)
        self.assertEqual(test_game_player.get_energy(), energy_before - 2)

        test_item = "drive"
        energy_before = test_game_player.get_energy()
        test_game_player.take(test_item)
        test_player_inventory = [i.name for i in test_game_player.get_items()]
        self.assertNotIn(test_item, test_player_inventory)
Esempio n. 12
0
    def test_get_object_by_name(self):
        rdm_player = Player(name="Rick")
        rdm_item = Item(name="Portal Gun")
        rdm_space = Space(name="Garage")
        rdm_exit = Exit(name="Portal")
        rdm_character = Character(name="Morty")
        rdm_test_objects = [
            rdm_player, rdm_item, rdm_space, rdm_exit, rdm_character
        ]
        test_game = Game(rdm_player)

        test_result = test_game.get_object_by_name(rdm_test_objects,
                                                   rdm_player.name)
        self.assertEqual(test_result, rdm_player)

        test_result = test_game.get_object_by_name(rdm_test_objects, "Portal")
        self.assertEqual(test_result, rdm_exit)
        self.assertNotEqual(test_result, rdm_item)

        test_result = test_game.get_object_by_name(rdm_test_objects, "Portal ")
        self.assertNotEqual(test_result, rdm_item)
        self.assertNotEqual(test_result, rdm_exit)
    def test_drop(self):
        test_player = Player()
        test_game = Auriga(test_player)
        test_game_player = test_game.player
        test_room = test_game.assembly_room
        test_game_player.set_location(test_room)

        test_item = "screwdriver"
        test_game_player.take(test_item)
        energy_before = test_game_player.get_energy()
        test_game_player.drop(test_item)
        room_items = [i.name for i in test_room.get_items()]
        player_items = [i.name for i in test_game_player.get_items()]
        self.assertIn(test_item, room_items)
        self.assertNotIn(test_item, player_items)
        self.assertEqual(test_game_player.get_energy(), energy_before - 1)

        test_item = "cables"
        energy_before = test_game_player.get_energy()
        test_game_player.drop(test_item)
        room_items = [i.name for i in test_room.get_items()]
        player_items = [i.name for i in test_game_player.get_items()]
        self.assertNotIn(test_item, room_items)
        self.assertEqual(test_game_player.get_energy(), energy_before)
Esempio n. 14
0
    def load_game(self, load_dir):
        """Load a game instance from json files.

        :param load_dir - str: The full filepath to the game instance's top level
                        directory.
        """
        self.reset_game_fields()
        # Set Game data
        game_space_ids = []
        game_character_ids = []
        game_item_ids = []
        game_exit_ids = []
        with open(os.path.join(load_dir, "game/game.json")) as file_handle:
            game_data = json.load(file_handle)
            self.event_status = game_data['event_status']
            self.event_status_list = game_data['event_status_list']
            game_space_ids = game_data['spaces']
            game_character_ids = game_data['characters']
            game_exit_ids = game_data['exits']
            game_item_ids = game_data['items']

        # Create Player
        player_item_ids = []
        with open(os.path.join(load_dir, "player/player.json")) as file_handle:
            player_data = json.load(file_handle)
            player_name = player_data['name']
            player_alive = player_data['alive']
            player_energy = player_data['energy']
            player_capacity = player_data['capacity']
            player_description = player_data['description']
            player_items = player_data['items']
            player_location = player_data['location']
            new_player = Player(name=player_name,
                                description=player_description,
                                capacity=player_capacity,
                                alive=player_alive,
                                energy=player_energy,
                                items=player_items,
                                location=player_location)
            # Add player to Game
            self.player = new_player

        # Create Items
        item_files = os.listdir(os.path.join(load_dir, "items"))
        for file in item_files:
            if file[-1] is not '~':
                with open(os.path.join(load_dir, "items",
                                       file)) as file_handle:
                    item_data = json.load(file_handle)
                    item_name = item_data['name']
                    item_visible = item_data['visible']
                    item_locked = item_data['locked']
                    item_weight = item_data['weight']
                    item_description = item_data['description']
                    item_id = item_data['id']

                    i = Item(new_id=item_id,
                             name=item_name,
                             visible=item_visible,
                             locked=item_locked,
                             weight=item_weight,
                             description=item_description)
                    self.items.append(i)

        # Create Characters
        character_files = os.listdir(os.path.join(load_dir, "characters"))
        for file in character_files:
            if file[-1] is not '~':
                with open(os.path.join(load_dir, "characters",
                                       file)) as file_handle:
                    char_data = json.load(file_handle)
                    char_name = char_data['name']
                    char_response = char_data['response']
                    char_description = char_data['description']
                    char_id = char_data['id']

                    c = Character(new_id=char_id,
                                  name=char_name,
                                  description=char_description,
                                  response=char_response)
                    self.characters.append(c)

        # Create Spaces
        space_files = os.listdir(os.path.join(load_dir, "spaces"))
        for file in space_files:
            if file[-1] is not '~':
                with open(os.path.join(load_dir, "spaces",
                                       file)) as file_handle:
                    space_data = json.load(file_handle)
                    space_name = space_data['name']
                    space_long_description = space_data['long_description']
                    space_short_description = space_data['short_description']
                    space_visited = space_data['visited']
                    space_id = space_data['id']
                    space_characters = space_data['characters']
                    space_exits = space_data['exits']
                    space_items = space_data['items']

                    s = Space(new_id=space_id,
                              name=space_name,
                              long_description=space_long_description,
                              short_description=space_short_description,
                              visited=space_visited,
                              items=space_items,
                              characters=space_characters,
                              exits=space_exits)
                    self.spaces.append(s)

        # Create Exits
        exit_files = os.listdir(os.path.join(load_dir, "exits"))
        for file in exit_files:
            if file[-1] is not '~':
                with open(os.path.join(load_dir, "exits",
                                       file)) as file_handle:
                    exit_data = json.load(file_handle)
                    exit_space = exit_data['space']
                    exit_name = exit_data['name']
                    exit_direction = exit_data['direction']
                    exit_unlock_item = exit_data['unlock_item']
                    exit_visible = exit_data['visible']
                    exit_id = exit_data['id']
                    exit_locked = exit_data['locked']
                    exit_description = exit_data['description']

                    e = Exit(new_id=exit_id,
                             space=exit_space,
                             name=exit_name,
                             direction=exit_direction,
                             unlock_item=exit_unlock_item,
                             visible=exit_visible,
                             locked=exit_locked,
                             description=exit_description)
                    self.exits.append(e)

        # Set player location
        loc_id = self.player.location
        self.player.location = self.get_object_by_id(self.spaces, loc_id)

        # Set player items
        player_item_ids = self.player.items
        new_player_items = []
        for item_id in player_item_ids:
            cur_item = self.get_object_by_id(self.items, item_id)
            new_player_items.append(cur_item)
        self.player.items = new_player_items

        # Place items, characters, and exits in spaces
        for space in self.spaces:
            item_ids = space.items
            character_ids = space.characters
            exit_ids = space.exits
            space.items = []
            space.characters = []
            space.exits = []
            # items
            for item_id in item_ids:
                item_obj = self.get_object_by_id(self.items, item_id)
                space.items.append(item_obj)
            # characters
            for character_id in character_ids:
                character_obj = self.get_object_by_id(self.characters,
                                                      character_id)
                space.characters.append(character_obj)
            # exits
            for exit_id in exit_ids:
                exit_obj = self.get_object_by_id(self.exits, exit_id)
                space.exits.append(exit_obj)

        # Link spaces to exits, and add unlock items
        for exit in self.exits:
            space_id = exit.space
            item_id = exit.unlock_item
            exit.space = None
            exit.unlock_item = None
            exit.space = self.get_object_by_id(self.spaces, space_id)
            exit.unlock_item = self.get_object_by_id(self.items, item_id)

        self.print_all_items_in_all_spaces()
    def test_get_item_names(self):
        test_item_one = Item(name="Test_Item_One", weight=2)
        test_item_two = Item(name="Test_Item_Two", weight=4)

        test_inventory = []
        test_player = Player(items=test_inventory)

        test_list = [test_item_one.name]
        test_player.add_item(test_item_one)
        self.assertEqual(test_player.get_item_names(), test_list)

        test_list = [test_item_one.name, test_item_two.name]
        test_player.add_item(test_item_two)
        self.assertEqual(test_player.get_item_names(), test_list)

        test_list = [test_item_two.name]
        test_player.remove_item(test_item_one)
        self.assertEqual(test_player.get_item_names(), test_list)
 def test_set_name(self):
     test_string = "R2-D2"
     test_player = Player()
     test_player.set_name(test_string)
     self.assertEqual(test_player.get_name(), test_string)
    def test_remove_item(self):
        test_item_one = Item(name="Test_Item_One", weight=2)
        test_item_two = Item(name="Test_Item_Two", weight=4)
        test_item_three = Item(name="Test_Item_Three", weight=8)

        test_inventory = [test_item_one, test_item_two, test_item_three]
        test_player = Player(items=test_inventory)
        self.assertEqual(test_player.get_items(), test_inventory)

        test_player.remove_item(test_item_one)
        self.assertNotIn(test_item_one, test_player.get_items())

        test_player.remove_item(test_item_two)
        self.assertNotIn(test_item_two, test_player.get_items())

        test_player.remove_item(test_item_three)
        self.assertNotIn(test_item_three, test_player.get_items())
    def test_set_items(self):
        test_item_one = Item(name="Test_Item_One", weight=2)
        test_item_two = Item(name="Test_Item_Two", weight=4)
        test_item_three = Item(name="Test_Item_Three", weight=8)
        test_player = Player()

        test_list = [test_item_one]
        test_player.set_items(test_list)
        self.assertEqual(test_player.get_items(), test_list)

        test_list = [test_item_one, test_item_two]
        test_player.set_items(test_list)
        self.assertEqual(test_player.get_items(), test_list)

        test_list = [test_item_one, test_item_two, test_item_three]
        test_player.set_items(test_list)
        self.assertEqual(test_player.get_items(), test_list)
 def test_set_description(self):
     test_string = "Adorable spunky droid"
     test_player = Player()
     test_player.set_description(test_string)
     self.assertEqual(test_player.get_description(), test_string)
    def test_get_items_total_weight(self):
        test_item_one = Item(name="Test_Item_One", weight=2)
        test_item_two = Item(name="Test_Item_Two", weight=4)
        test_item_three = Item(name="Test_Item_Three", weight=8)
        test_inventory = []

        test_player = Player(items=test_inventory)
        self.assertEqual(0, test_player.get_items_total_weight())

        test_player.add_item(test_item_one)
        self.assertEqual(2, test_player.get_items_total_weight())

        test_player.add_item(test_item_three)
        self.assertEqual(10, test_player.get_items_total_weight())

        test_player.remove_item(test_item_one)
        self.assertEqual(8, test_player.get_items_total_weight())
 def test_set_capacity(self):
     test_int = 69
     test_player = Player()
     test_player.set_capacity(test_int)
     self.assertEqual(test_player.get_capacity(), test_int)