diff --git a/README.md b/README.md index 5cc2cbf2a2..c306b4a13e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Intro to Python II +..... Up to this point, you've gotten your feet wet by working on a bunch of small Python programs. In this module, we're going to continue to solidify your Python chops by implementing a full-featured project according to a provided specification. diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..486745f44e 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,10 +1,14 @@ from room import Room +from player import Player +from item import Item +import sys + -# Declare all the rooms +# Declare all the rooms room = { 'outside': Room("Outside Cave Entrance", - "North of you, the cave mount beckons"), + "North of you, the cave mount beckons"), 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty passages run north and east."""), @@ -33,19 +37,73 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] + +#Items +item = { + 'coins': Item("Item: ~~[Money", "--Just a few lose coins to take to the tavern]~~"), + 'tools': Item("Item: ~~[Grappling hook", "--This might come in handy. It is very heavy]~~"), + 'jewel': Item("Item: ~~[Gem", "--Next time you ask that stranger for information. He might be willing to help for this type of payment]~~"), + 'torch': Item("Item: ~~[Torch", "--Let there be light. Is someone sneaking around? Why is this on the floor?!?]~~"), + 'trap': Item("Item: ~~[Tripped Trap", "--An abandoned trap that has been tripped. If cleaned up it could be useful.]~~"), + 'medallion': Item("Item: ~~[Medallion", "--It reflects light and glows slightly orange it may be magical. There is an inscription in an unknown language. Inscription:Hul werud ezes ulud egembelu owog. Kyul buol engumet ullyetuk.]~~ "), +} + + + +room['foyer'].items = [str(item['coins']), str(item['trap'])] +room['overlook'].items = [str(item['jewel']),str(item['medallion']),str(item['trap'])] +room['narrow'].items = [str(item['jewel']), str(item['coins']), str(item['torch'])] +room['treasure'].items = [str(item['tools'])] + +options = "\nOptions:\nInventory:[View]\nItem:[Take][Drop]\nDirections:[N][S][E][W]\nSystem:[Q] to Quit\n\n" +directions={"n", "s", "e", "w"} # # Main # # Make a new player object that is currently in the 'outside' room. +def text_game(): + name = "Endless Treasure Hunt" + player = Player(name, room['outside']) + print("\nWelcome to Endless Treasure Hunt. Would you like to play?") + + user_input = input("\nEnter [P] to Play or [Q] to Quit: ").lower().strip() + if user_input == "p": + name = input("\nWhat shall I call you Adventurer?:").upper().strip() + if name != '': + player.name = name + print(f"\nTime to start your journey Adventurer {player.name}:\n\nAt present you are at the {player.current_room.name}\nInfo: {player.current_room.description}\n\nOptions:\nDirections:[N][S][E][W]\nSystem:[Q] to Quit\n\nTo start your journey choose a direction...") + elif user_input != "p": + print("\nThanks for Playing! GoodBye UnKnown Adventurer!") # 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 user_input == 'p': + choice = input("Please choose an option:").lower().strip() + if choice in directions: + player.move(choice) + elif choice == 'h': + print(f"{options}") + elif choice == 'q': + print(f"\nThanks for Playing! GoodBye Adventurer {player.name}!") + sys.exit() + + """ if choice.lower().strip()=='view': + return player.inventory() + if choice.lower().strip() =='take': + return player.take() + if choice.lower().strip() == 'drop' + return player.item.drop() """ + + + # If the user enters "q", quit the game. + + + +text_game() \ No newline at end of file diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..94148700bb --- /dev/null +++ b/src/item.py @@ -0,0 +1,7 @@ +class Item(): + def __init__(self, name, description): + self.name = name + self.description = description + + def __str__(self): + return f'{self.name}{self.description}' diff --git a/src/player.py b/src/player.py index d79a175029..8b6df2b924 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): + self.name = name + self.current_room = current_room + self.inventory = [] + + def move(self, direction): + linked_room = self.current_room.other_rooms(direction) + if linked_room is not None and len(linked_room.items) < 0: + self.current_room = linked_room + print(f"\nAdventurer {self.name}:\nYou have entered the {linked_room.name}\n\nInfo:{linked_room.description}\n\n") + elif linked_room is not None and len(linked_room.items) > 0: + self.current_room = linked_room + print(f"\nAdventurer {self.name}:\nYou have entered the {linked_room.name}\n\nInfo:{linked_room.description}\nUpon further inspection your notice a few items scattered about:\n{linked_room.items}\n\n") + else: + print(f"\nThat direction is not available. Try Again!!\n") \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..b68314a225 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,24 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. +class Room(): + def __init__(self, name, description): + self.name = name + self.description = description + self.items = [] + self.n_to = None + self.e_to = None + self.w_to = None + self.s_to = None + + + def other_rooms(self, direction): + if direction == 'n': + return self.n_to + elif direction == 'e': + return self.e_to + elif direction =='s': + return self.s_to + elif direction == 'w': + return self.w_to + else: + return None \ No newline at end of file