Example #1
0
def test_dungeon_build():
    """method to build a dungeon for testing and dev."""
    dungeon_name = "Test Dungeon"
    room_one_date =["Entry Room", "The first room in the test dungeon"]
    room_one = Room(room_one_date)
    roomtwo_data = ["second Room", "The second room of the test dungeon"]
    room_two = Room(roomtwo_data)
    exit1 = Exit("n", room_one, room_two)
    exit2 = Exit("s", room_two, room_one)
    room_one.add_exit(exit1)
    room_two.add_exit(exit2)
    test_dungeon = Dungeon(dungeon_name, room_one)
    test_dungeon.add_room(room_two)
    item_one_stats = ["Apple", "A red Fuji Apple", .2]
    item_one_actions = {"eat": "consume-You eat the apple", "examine": "It's a\
         red apple. It looks really tasty.", "throw": "destroy-You hurl the \
             apple agaisnt the wall. It smashes agaisnt it with a splat."}
    item_one_date = ["Apple", "A red Fuji Apple", 0.2,item_one_actions]
    item_one = item(item_one_date)
    item_two_stats = ["Spoon", "a metal spoon", .01]
    item_two_actions = {"examine": "examine-The spoon is made of some form of lite metal, perhaps tin.", "throw": "remove-You hurl the \
             spoon agaisnt the wall. It clashes against the wall with a clatter."}
    item_two_data = ["Spoon", "a metal spoon", 0.01,item_two_actions]
    item_two = item(item_two_data)
    room_one.add_item(item_one)
    room_one.add_item(item_two)
    return test_dungeon
Example #2
0
    "large metal kitchen door that seems to be blocked off from the other side",
    ["south", "s"])
kitchen.add_connection(ceo_office,
                       "office that belongs to the CEO of the building",
                       ["west", "w"])
ceo_office.add_connection(trapdoor, "You teleport back to the helipad",
                          ["east", "e"])
trapdoor.add_connection(living, "You are here boy", ["east", "e"])

current_room = helipad
inventory = Inventory()

inventory = Inventory()
current_room = helipad

kitchen.add_item(Flashlight())

while True:
    current_room.enter_room(inventory)
    command = raw_input("What would you like to do? ")
    if command in ["exit", "x", "quit", "q"]:
        break

    result = current_room.process_command(command, inventory)
    if isinstance(result, Room):
        current_room = result
        result.enter_room(inventory)
        continue
    elif isinstance(result, str):
        print result
        continue
Example #3
0
class RoomTest(unittest.TestCase):
    ####################################################################
    def setUp(self):
        self.room = Room()
        self.room.type = RoomType.TRAINING_ROOM
        self.room.id = 3
        self.room.description = "Just a plain room"

    ####################################################################
    def test_deserialize_from_dict(self):
        short_sword = item.item_database.find(2)
        leather_armor = item.item_database.find(3)
        healing_potion = item.item_database.find(5)
        room_template_data = {
            "id": 50,
            "name": "Sewage Trench",
            "description":
            "You're in a sewage trench, filled with all sorts of liquid refuse, slowly flowing eastward into the town sewers.",
            "type": "PLAIN_ROOM",
            "data": 0,
            "north": 49,
            "east": 51,
            "south": 0,
            "west": 0,
            "spawn_which_enemy": 9,
            "max_enemies": 1,
            "starting_items": [2, 3],
            "starting_money": 30
        }
        this_room = Room.deserialize_from_dict(room_template_data, {})
        self.assertEqual(this_room.id, 50)
        self.assertEqual(this_room.name, "Sewage Trench")
        self.assertEqual(this_room.type, RoomType.PLAIN_ROOM)
        # self.assertEqual(this_room.data, 0)
        self.assertEqual(len(this_room.connecting_rooms), 2)
        self.assertEqual(this_room.connecting_rooms[Direction.NORTH], 49)
        self.assertEqual(this_room.connecting_rooms[Direction.EAST], 51)
        self.assertEqual(this_room.spawn_which_enemy, 9)
        self.assertEqual(this_room.max_enemies, 1)
        self.assertEqual(this_room.items, [short_sword, leather_armor])
        self.assertEqual(this_room.money, 30)

        room_dynamic_data = {"id": 50, "items": [5], "money": 2}

        this_room = Room.deserialize_from_dict(room_template_data,
                                               room_dynamic_data)
        self.assertEqual(this_room.id, 50)
        self.assertEqual(this_room.name, "Sewage Trench")
        self.assertEqual(this_room.type, RoomType.PLAIN_ROOM)
        # self.assertEqual(this_room.data, 0)
        self.assertEqual(len(this_room.connecting_rooms), 2)
        self.assertEqual(this_room.connecting_rooms[Direction.NORTH], 49)
        self.assertEqual(this_room.connecting_rooms[Direction.EAST], 51)
        self.assertEqual(this_room.spawn_which_enemy, 9)
        self.assertEqual(this_room.max_enemies, 1)
        self.assertEqual(this_room.items, [healing_potion])
        self.assertEqual(this_room.money, 2)

    ####################################################################
    def test_serialize_to_dict(self):
        power_armor = item.item_database.find(55)
        darkness_armor = item.item_database.find(54)
        self.room.add_item(power_armor)
        self.room.add_item(darkness_armor)
        self.room.money = 33

        expected = {"items": [55, 54], "money": 33}
        self.assertEqual(self.room.serialize_to_dict(), expected)

    ####################################################################
    def test_get_adjacent_room(self):
        first_room = room.room_database.find("Town Square")
        self.assertEqual(first_room.id, 1)
        second_room = first_room.get_adjacent_room(Direction.NORTH)
        self.assertEqual(second_room.id, 2)
        self.assertEqual(second_room.name, "Street")

    ####################################################################
    def test_add_player(self):
        self.assertEqual(self.room.players, set())
        p = player.Player(22)
        p.name = "jerry"
        player.player_database.add_player(p)
        self.room.add_player(p)
        self.assertEqual(self.room.players, {p})

    ####################################################################
    def test_remove_player(self):
        p = player.Player(22)
        p.name = "jerry"
        player.player_database.add_player(p)
        self.room.add_player(p)
        self.assertEqual(self.room.players, {p})

        self.room.remove_player(p)
        self.assertEqual(self.room.players, set())

    ####################################################################
    def test_find_item(self):
        power_armor = item.item_database.find(55)
        darkness_armor = item.item_database.find(54)
        self.room.add_item(power_armor)
        self.room.add_item(darkness_armor)
        self.assertEqual(self.room.find_item("darkness"), darkness_armor)
        self.assertEqual(self.room.find_item("power"), power_armor)
        self.assertEqual(self.room.find_item("armor"), power_armor)

    ####################################################################
    def test_add_item(self):
        armor = item.item_database.find(55)
        self.assertEqual(self.room.items, [])
        self.room.add_item(armor)
        self.assertEqual(self.room.items, [armor])

        self.room.remove_item(armor)

        # Test MAX_ITEMS limit
        for i in range(1, room.MAX_ITEMS + 3):
            self.room.add_item(item.item_database.find(i))

        items_ids_left = [x.id for x in self.room.items]
        self.assertEqual(items_ids_left, range(3, room.MAX_ITEMS + 3))

    ####################################################################
    def test_remove_item(self):
        armor = item.item_database.find(55)
        self.room.add_item(armor)
        self.assertEqual(self.room.items, [armor])
        self.room.remove_item(armor)
        self.assertEqual(self.room.items, [])

    ####################################################################
    def test_find_enemy(self):
        self.fail()
        # return utils.double_find_by_name(enemy_name, self.enemies)

    ####################################################################
    def test_add_enemy(self):
        self.fail()
        # self.enemies.add(enemy)

    ####################################################################
    def test_remove_enemy(self):
        self.fail()
Example #4
0
            # for item in room.items:
            try:
                Room.remove_item(current_room, command[1])
            except ValueError:
                print("\n!!! you cannot take what is not there !!!\n")
                error_message = True

            if error_message == True:
                next
            else:
                player.add_item(command[1])
                print(f"\n you picked up {command[1]}\n")
        elif command[0] == "drop" or command[0] == "leave":
            try:
                player.remove_item(command[1])
            except ValueError:
                print("\n!!! you cannot drop what you don't have !!!\n")
                error_message = True

            if error_message == True:
                next
            else:
                Room.add_item(current_room, command[1])
                print(f"\nyou dropped {command[1]}\n")
        else:
            print(f"\n\nunrecognized command, try again\n\n")

# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.