diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Intro-Python-II.iml b/.idea/Intro-Python-II.iml new file mode 100644 index 0000000000..8dc09e5476 --- /dev/null +++ b/.idea/Intro-Python-II.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000000..d9edd77e40 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,30 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000..105ce2da2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..a2e120dcc8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..b5c5fcd85b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..94a25f7f4c --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..b0dcf3cf7a 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,27 +1,31 @@ from room import Room +from player import Player +from item import Item # Declare all the rooms +sword = Item("Sword", "Sharp and dangerous!") +gold = Item("Gold", "Shiny!") + room = { - 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons"), + 'outside': Room("Outside Cave Entrance", + "North of you, the cave mount beckons", [sword]), - 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty -passages run north and east."""), + 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty +passages run north and east.""", []), 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm."""), +the distance, but there is no way across the chasm.""", []), - 'narrow': Room("Narrow Passage", """The narrow passage bends here from west -to north. The smell of gold permeates the air."""), + 'narrow': Room("Narrow Passage", """The narrow passage bends here from west +to north. The smell of gold permeates the air.""", [gold]), 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south."""), +earlier adventurers. The only exit is to the south.""", [sword, gold]), } - # Link rooms together room['outside'].n_to = room['foyer'] @@ -36,16 +40,61 @@ # # Main # - +username = input("Please put in your name: ") # Make a new player object that is currently in the 'outside' room. - +player = Player(username, room['outside'], []) # Write a loop that: -# -# * Prints the current room name -# * Prints the current description (the textwrap module might be useful here). -# * Waits for user input and decides what to do. -# -# If the user enters a cardinal direction, attempt to move to the room there. -# Print an error message if the movement isn't allowed. -# + +while player.current_room: + # * Prints the current room name + print(f"Current room: {player.current_room.name}") + # * Prints the current description (the textwrap module might be useful here). + print(f"{player.current_room.description}") + ret = f"What's in the room? \n" + for i in player.current_room.storage: + ret += f"{i.name}\n" + names = i.name + if len(player.current_room.storage) == 0: + print("There's nothing in the room!\n") + else: + print(ret) + print("-------------------------------------------------------------------------") + # * Waits for user input and decides what to do. + if len(player.current_room.storage) != 0: + print("There's something in the room. Why not try to pick it up or drop whatever if you want to.") + selection = input("Please pick a direction to go in (North = n, South = s, West = w, East = e): ") + print('-------------------------------------------------------------------------') + # If the user enters a cardinal direction, attempt to move to the room there. + if selection == 'n': + if player.current_room.n_to is None: + print(f"There is nothing north of {player.current_room.name}. Please pick another direction.") + else: + player.current_room = player.current_room.n_to + elif selection == 's': + if player.current_room.s_to is None: + print(f"There is nothing south of {player.current_room.name}. Please pick another direction.") + else: + player.current_room = player.current_room.s_to + elif selection == 'w': + if player.current_room.w_to is None: + print(f"There is nothing west of {player.current_room.name}. Please pick another direction.") + else: + player.current_room = player.current_room.w_to + elif selection == 'e': + if player.current_room.e_to is None: + print(f"\nThere is nothing east of {player.current_room.name}. Please pick another direction.") + else: + player.current_room = player.current_room.e_to + # elif len(selection) == 2: + # verb = selection[0] + # item_name = selection[1] + # if (verb == 'get' or verb == 'take') and (item_name == names): + # player.current_room.pick_item(item_name) + + elif selection == 'q': + print("Thank you for playing!") + player.current_room = False # Get out of game + # Print an error message if the movement isn't allowed. + else: + print(selection + " wasn't allowed. Please pick another valid direction.") # If the user enters "q", quit the game. diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..a798f63458 --- /dev/null +++ b/src/item.py @@ -0,0 +1,8 @@ +class Item: + def __init__(self, name, description): + self.name = name + self.description = description + + def __str__(self): + return f"Name of item: {self.name}\n" \ + f"Description of item: {self.description}" \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..a7050029a4 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,19 @@ # Write a class to hold player information, e.g. what room they are in # currently. + + +class Player: + def __init__(self, name, current_room, storage): + self.name = name + self.current_room = current_room + self.storage = storage + + def __str__(self): + return f"Name: {self.name}\n" \ + f"Current room: {self.current_room}\n" \ + f"Stuff on player: {self.storage}" + + +if __name__ == "__main__": + a = Player("Bob", "Bob's Room") # __repr__ works + print(a) diff --git a/src/room.py b/src/room.py index 24c07ad4c8..75111f2f54 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,40 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. +from player import Player + +class Room: + def __init__(self, name, description, storage=[], n_to=None, w_to=None, e_to=None, s_to=None): + self.n_to = n_to + self.w_to = w_to + self.e_to = e_to + self.s_to = s_to + self.name = name + self.description = description + self.storage = storage + + def + + + # def pick_item(self, item): + # for i in self.storage: + # if item == i: + # self.storage.remove(i) + # print(f"You picked up {item}") + # return self.storage + # else: + # print(f"There's no such thing as {item}.") + + + + def __str__(self): + return f"Name of room: {self.name}\n" \ + f"Description: {self.description}\n" \ + f"Stuff that room has: {self.storage}\n" \ + f"North: {self.n_to}\n" \ + f"West: {self.w_to}\n" \ + f"East: {self.e_to}\n" \ + f"South: {self.s_to}" + +if __name__ == "__main__": + a = Room("asdf", "asjd;kl;") # __str__ works + print(a) \ No newline at end of file