From 51987f431560e34e1b5f0cc27dafecd7b5f6091d Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 8 Apr 2020 13:47:47 +0100 Subject: [PATCH 01/19] copying master --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 182debf5ff..0af7a45c9a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # 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. From 335409fa28bd5b214105a806f69b708ccaa1d606 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 8 Apr 2020 13:55:43 +0100 Subject: [PATCH 02/19] trying to write loop --- src/adv.py | 5 +++++ src/player.py | 12 ++++++++++++ src/room.py | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..984886ee42 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,5 @@ from room import Room +from player import Player # Declare all the rooms @@ -38,10 +39,14 @@ # # Make a new player object that is currently in the 'outside' room. +new_player = Player("Jayne", room['outside']) # Write a loop that: +while True: + # # * Prints the current room name + print(room) # * Prints the current description (the textwrap module might be useful here). # * Waits for user input and decides what to do. # diff --git a/src/player.py b/src/player.py index d79a175029..7f5fcc7e2d 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,14 @@ # Write a class to hold player information, e.g. what room they are in # currently. + +class Player: + # constructor function + def __init__(self, name, room): + self.name = name + self.current_room = room + + # string value + def __str__(self): + return f"{self.name} is in {self.current_room.name}" + pass + diff --git a/src/room.py b/src/room.py index 24c07ad4c8..003842b2d6 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,15 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. + +class Room: + # construction function + def __init__(self, name, description): + self.name = name + self.description = description + + def __str__(self): + return f"room name is {self.name}" + + def add_item(self, item): + self.item = item + pass From 770bfe5a7af7b9cc605a428c57ed83779ef01b7a Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 8 Apr 2020 14:08:11 +0100 Subject: [PATCH 03/19] included textwrap --- src/adv.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/adv.py b/src/adv.py index 984886ee42..99580cd1f9 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,6 @@ from room import Room from player import Player +import textwrap # Declare all the rooms @@ -41,13 +42,25 @@ # Make a new player object that is currently in the 'outside' room. new_player = Player("Jayne", room['outside']) +directions = ['n', 's', 'e', 'w'] + # Write a loop that: -while True: + # # * Prints the current room name - print(room) +print(new_player) + # * Prints the current description (the textwrap module might be useful here). +room_description = new_player.current_room.description + +wrapper = textwrap.TextWrapper(width=15) + +word_list = wrapper.wrap(text=room_description) + +for element in word_list: + print(element) + # * Waits for user input and decides what to do. # # If the user enters a cardinal direction, attempt to move to the room there. From 8303fc38e12a1ab664dab93843de11e6fe6084a4 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 8 Apr 2020 15:09:15 +0100 Subject: [PATCH 04/19] working on dealing with user prompt --- src/adv.py | 43 +++++++++++++++++++++++++++---------------- src/player.py | 2 +- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/adv.py b/src/adv.py index 99580cd1f9..21cc452962 100644 --- a/src/adv.py +++ b/src/adv.py @@ -41,29 +41,40 @@ # Make a new player object that is currently in the 'outside' room. new_player = Player("Jayne", room['outside']) - directions = ['n', 's', 'e', 'w'] # Write a loop that: +user_prompt = None + +while user_prompt != "q": -# -# * Prints the current room name -print(new_player) + # * Prints the current room name + print(new_player) + + # * Prints the current description (the textwrap module might be useful here). + room_description = new_player.current_room.description + wrapper = textwrap.TextWrapper(width=15) + word_list = wrapper.wrap(text=room_description) + for element in word_list: + print(element) + + # * Waits for user input and decides what to do + user_prompt = (input("Where do you want to go? Type n, s, e or w OR quit (q): ")) + + # JAYNE: USER_PROMPT IS A STRING + print(user_prompt) -# * Prints the current description (the textwrap module might be useful here). -room_description = new_player.current_room.description + + + # print(user_prompt.lower()) + + # If the user enters a cardinal direction, attempt to move to the room there. + + # if user_prompt.lower() == 'n': + -wrapper = textwrap.TextWrapper(width=15) - -word_list = wrapper.wrap(text=room_description) - -for element in word_list: - print(element) -# * 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. # -# If the user enters "q", quit the game. +# If the user enters "q", quit the game. \ No newline at end of file diff --git a/src/player.py b/src/player.py index 7f5fcc7e2d..7d838e03c2 100644 --- a/src/player.py +++ b/src/player.py @@ -9,6 +9,6 @@ def __init__(self, name, room): # string value def __str__(self): - return f"{self.name} is in {self.current_room.name}" + return f"{self.name} is currently located: {self.current_room.name}" pass From fcbdbfc76eb2af860695524c2180efb21bb35b11 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 8 Apr 2020 15:19:34 +0100 Subject: [PATCH 05/19] working on how to control direction prompts --- src/adv.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/adv.py b/src/adv.py index 21cc452962..4166cc6c57 100644 --- a/src/adv.py +++ b/src/adv.py @@ -63,15 +63,15 @@ user_prompt = (input("Where do you want to go? Type n, s, e or w OR quit (q): ")) # JAYNE: USER_PROMPT IS A STRING - print(user_prompt) + print(user_prompt.lower()) - - # print(user_prompt.lower()) - # If the user enters a cardinal direction, attempt to move to the room there. - # if user_prompt.lower() == 'n': + if user_prompt.lower() == 'n': + print("We shall go NORTH") + new_player = Player("Jayne", room['foyer']) + print(new_player.current_room) From 4e92ae23fc8fa402d167f9ca832bb7caa5fd753f Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 8 Apr 2020 15:57:06 +0100 Subject: [PATCH 06/19] mapped out game --- src/adv.py | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 122 insertions(+), 3 deletions(-) diff --git a/src/adv.py b/src/adv.py index 4166cc6c57..73a51879db 100644 --- a/src/adv.py +++ b/src/adv.py @@ -69,9 +69,128 @@ # If the user enters a cardinal direction, attempt to move to the room there. if user_prompt.lower() == 'n': - print("We shall go NORTH") - new_player = Player("Jayne", room['foyer']) - print(new_player.current_room) + #OUTSIDE + if new_player.current_room.name == 'Outside Cave Entrance': + print("---- LET US GO NORTH ----") + new_player = Player("Jayne", room['foyer']) + print(new_player.current_room) + #FOYER + elif new_player.current_room.name == 'Foyer': + print("---- LET US GO NORTH ----") + new_player = Player("Jayne", room['overlook']) + print(new_player.current_room) + #OVERLOOK + elif new_player.current_room.name == 'Grand Overlook': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['overlook']) + print(new_player.current_room) + #NARROW + elif new_player.current_room.name == 'Narrow Passage': + print("---- LET US GO NORTH ----") + new_player = Player("Jayne", room['treasure']) + print(new_player.current_room) + #TREASURE + elif new_player.current_room.name == 'Treasure Chamber': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['treasure']) + print(new_player.current_room) + elif user_prompt.lower() == 's': + #OUTSIDE + if new_player.current_room.name == 'Outside Cave Entrance': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['outside']) + print(new_player.current_room) + #FOYER + elif new_player.current_room.name == 'Foyer': + print("---- LET US GO SOUTH ----") + new_player = Player("Jayne", room['outside']) + print(new_player.current_room) + #OVERLOOK + elif new_player.current_room.name == 'Grand Overlook': + print("---- LET US GO SOUTH ----") + new_player = Player("Jayne", room['foyer']) + print(new_player.current_room) + #NARROW + elif new_player.current_room.name == 'Narrow Passage': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['narrow']) + print(new_player.current_room) + #TREASURE + elif new_player.current_room.name == 'Treasure Chamber': + print("---- LET US GO SOUTH ----") + new_player = Player("Jayne", room['narrow']) + print(new_player.current_room) + elif user_prompt.lower() == 'e': + #OUTSIDE + if new_player.current_room.name == 'Outside Cave Entrance': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['outside']) + print(new_player.current_room) + #FOYER + elif new_player.current_room.name == 'Foyer': + print("---- LET US GO EAST ----") + new_player = Player("Jayne", room['narrow']) + print(new_player.current_room) + #OVERLOOK + elif new_player.current_room.name == 'Grand Overlook': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['overlook']) + print(new_player.current_room) + #NARROW + elif new_player.current_room.name == 'Narrow Passage': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['narrow']) + print(new_player.current_room) + #TREASURE + elif new_player.current_room.name == 'Treasure Chamber': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['treasure']) + print(new_player.current_room) + elif user_prompt.lower() == 'w': + #OUTSIDE + if new_player.current_room.name == 'Outside Cave Entrance': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['outside']) + print(new_player.current_room) + #FOYER + elif new_player.current_room.name == 'Foyer': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['foyer']) + print(new_player.current_room) + #OVERLOOK + elif new_player.current_room.name == 'Grand Overlook': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['overlook']) + print(new_player.current_room) + #NARROW + elif new_player.current_room.name == 'Narrow Passage': + print("---- LET US GO WEST ----") + new_player = Player("Jayne", room['foyer']) + print(new_player.current_room) + #TREASURE + elif new_player.current_room.name == 'Treasure Chamber': + print("---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----") + new_player = Player("Jayne", room['treasure']) + print(new_player.current_room) + elif user_prompt.lower() == 'q': + print("Goodbye!") + break + else: + print("I do not understand that command") + print("Please select from n, s, e, w or q") + From 8bfe24f5960d2e1c7cefd5ff05b311e3266681c7 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 8 Apr 2020 16:01:04 +0100 Subject: [PATCH 07/19] update to prompts --- src/adv.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/adv.py b/src/adv.py index 73a51879db..9f64547965 100644 --- a/src/adv.py +++ b/src/adv.py @@ -60,11 +60,9 @@ print(element) # * Waits for user input and decides what to do - user_prompt = (input("Where do you want to go? Type n, s, e or w OR quit (q): ")) + user_prompt = (input("---- WHERE DO YOU WANT TO GO ? ---- \n Type n, s, e or w OR quit (q): ")) # JAYNE: USER_PROMPT IS A STRING - print(user_prompt.lower()) - # If the user enters a cardinal direction, attempt to move to the room there. @@ -188,8 +186,8 @@ print("Goodbye!") break else: - print("I do not understand that command") - print("Please select from n, s, e, w or q") + print("---- INVALID COMMAND ----") + print("PLEASE SELECT FROM: n, s, e, w or q") From f5d652bfaa6b139d4d7500f822ecdc99df972beb Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 8 Apr 2020 16:11:17 +0100 Subject: [PATCH 08/19] updating prompts when quit --- src/adv.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/adv.py b/src/adv.py index 9f64547965..f2bddf124b 100644 --- a/src/adv.py +++ b/src/adv.py @@ -182,16 +182,11 @@ print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['treasure']) print(new_player.current_room) + # If the user enters "q", quit the game elif user_prompt.lower() == 'q': - print("Goodbye!") + print("Thank you for playing \nGoodbye!") break + # Print an error message if the movement isn't allowed. else: print("---- INVALID COMMAND ----") print("PLEASE SELECT FROM: n, s, e, w or q") - - - - -# Print an error message if the movement isn't allowed. -# -# If the user enters "q", quit the game. \ No newline at end of file From 74b3913239e39d0f338b8930a0b447dc87dd4d33 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Thu, 9 Apr 2020 13:03:07 +0100 Subject: [PATCH 09/19] updated styling for room description --- src/adv.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/adv.py b/src/adv.py index f2bddf124b..22e7e28960 100644 --- a/src/adv.py +++ b/src/adv.py @@ -57,7 +57,7 @@ wrapper = textwrap.TextWrapper(width=15) word_list = wrapper.wrap(text=room_description) for element in word_list: - print(element) + print(" > " + element) # * Waits for user input and decides what to do user_prompt = (input("---- WHERE DO YOU WANT TO GO ? ---- \n Type n, s, e or w OR quit (q): ")) @@ -79,7 +79,7 @@ print(new_player.current_room) #OVERLOOK elif new_player.current_room.name == 'Grand Overlook': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['overlook']) print(new_player.current_room) @@ -90,14 +90,14 @@ print(new_player.current_room) #TREASURE elif new_player.current_room.name == 'Treasure Chamber': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['treasure']) print(new_player.current_room) elif user_prompt.lower() == 's': #OUTSIDE if new_player.current_room.name == 'Outside Cave Entrance': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['outside']) print(new_player.current_room) @@ -113,7 +113,7 @@ print(new_player.current_room) #NARROW elif new_player.current_room.name == 'Narrow Passage': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['narrow']) print(new_player.current_room) @@ -125,7 +125,7 @@ elif user_prompt.lower() == 'e': #OUTSIDE if new_player.current_room.name == 'Outside Cave Entrance': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['outside']) print(new_player.current_room) @@ -136,38 +136,38 @@ print(new_player.current_room) #OVERLOOK elif new_player.current_room.name == 'Grand Overlook': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['overlook']) print(new_player.current_room) #NARROW elif new_player.current_room.name == 'Narrow Passage': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['narrow']) print(new_player.current_room) #TREASURE elif new_player.current_room.name == 'Treasure Chamber': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['treasure']) print(new_player.current_room) elif user_prompt.lower() == 'w': #OUTSIDE if new_player.current_room.name == 'Outside Cave Entrance': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['outside']) print(new_player.current_room) #FOYER elif new_player.current_room.name == 'Foyer': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['foyer']) print(new_player.current_room) #OVERLOOK elif new_player.current_room.name == 'Grand Overlook': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['overlook']) print(new_player.current_room) @@ -178,7 +178,7 @@ print(new_player.current_room) #TREASURE elif new_player.current_room.name == 'Treasure Chamber': - print("---- YOU SHALL NOT PASS ----") + print("---- YOU SHALL NOT PASS ----") print("---- CHOOSE ANOTHER DIRECTION ----") new_player = Player("Jayne", room['treasure']) print(new_player.current_room) From 76a8da1b73a4063611dee2715ea219dc0d121d98 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Thu, 9 Apr 2020 19:55:47 +0100 Subject: [PATCH 10/19] refactored code. Added items to each room. --- src/adv.py | 182 +++++++++++++++++++++++++++++++--------------------- src/item.py | 7 ++ src/room.py | 28 +++++++- 3 files changed, 141 insertions(+), 76 deletions(-) create mode 100644 src/item.py diff --git a/src/adv.py b/src/adv.py index 22e7e28960..032232ce68 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,6 @@ from room import Room from player import Player +from item import Item import textwrap # Declare all the rooms @@ -41,7 +42,40 @@ # Make a new player object that is currently in the 'outside' room. new_player = Player("Jayne", room['outside']) -directions = ['n', 's', 'e', 'w'] + +# print(len(room['outside'].room_items)) + +# CREATE VARIABLES FOR ROOMS +outside = room['outside'] +foyer = room['foyer'] +overlook = room['overlook'] +narrow = room['narrow'] +treasure = room['treasure'] + + +# ADD ITEMS TO ROOMS +axe = Item("AXE", "by jove, it is sharp") +compass = Item("Compass", "weathered, but still works") +outside.stealthy_add(axe) +outside.stealthy_add(compass) + +foyer.stealthy_add(compass) + +binoculars = Item("Binoculars", "handy for spying") +overlook.stealthy_add(binoculars) + +torch = Item("Torch", "batteries running low") +narrow.stealthy_add(torch) + +gold = Item("Gold coins", "they are worth a fortune!") +treasure.stealthy_add(gold) + +print("\n------- WELCOME TO JAYNE'S GAME ---------\n") + + + + + # Write a loop that: @@ -60,7 +94,7 @@ print(" > " + element) # * Waits for user input and decides what to do - user_prompt = (input("---- WHERE DO YOU WANT TO GO ? ---- \n Type n, s, e or w OR quit (q): ")) + user_prompt = (input("\n---- WHERE DO YOU WANT TO GO ? ---- \n Type [n], [s], [e] or [w]\n OR [look]\n OR quit:(q): ")) # JAYNE: USER_PROMPT IS A STRING @@ -68,119 +102,119 @@ if user_prompt.lower() == 'n': #OUTSIDE - if new_player.current_room.name == 'Outside Cave Entrance': - print("---- LET US GO NORTH ----") - new_player = Player("Jayne", room['foyer']) + if new_player.current_room == outside: + print("\n---- LET US GO NORTH ----\n") + new_player.current_room = foyer print(new_player.current_room) #FOYER - elif new_player.current_room.name == 'Foyer': - print("---- LET US GO NORTH ----") - new_player = Player("Jayne", room['overlook']) + elif new_player.current_room == foyer: + print("\n---- LET US GO NORTH ----\n") + new_player.current_room = overlook print(new_player.current_room) #OVERLOOK - elif new_player.current_room.name == 'Grand Overlook': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['overlook']) + elif new_player.current_room == overlook: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = overlook print(new_player.current_room) #NARROW - elif new_player.current_room.name == 'Narrow Passage': - print("---- LET US GO NORTH ----") - new_player = Player("Jayne", room['treasure']) + elif new_player.current_room == narrow: + print("\n---- LET US GO NORTH ----\n") + new_player.current_room = treasure print(new_player.current_room) #TREASURE - elif new_player.current_room.name == 'Treasure Chamber': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['treasure']) + elif new_player.current_room == treasure: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = treasure print(new_player.current_room) elif user_prompt.lower() == 's': #OUTSIDE - if new_player.current_room.name == 'Outside Cave Entrance': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['outside']) + if new_player.current_room == outside: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = outside print(new_player.current_room) #FOYER - elif new_player.current_room.name == 'Foyer': - print("---- LET US GO SOUTH ----") - new_player = Player("Jayne", room['outside']) + elif new_player.current_room == foyer: + print("\n---- LET US GO SOUTH ----\n") + new_player.current_room = outside print(new_player.current_room) #OVERLOOK - elif new_player.current_room.name == 'Grand Overlook': - print("---- LET US GO SOUTH ----") - new_player = Player("Jayne", room['foyer']) + elif new_player.current_room == overlook: + print("\n---- LET US GO SOUTH ----\n") + new_player.current_room = foyer print(new_player.current_room) #NARROW - elif new_player.current_room.name == 'Narrow Passage': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['narrow']) + elif new_player.current_room == narrow: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = narrow print(new_player.current_room) #TREASURE - elif new_player.current_room.name == 'Treasure Chamber': - print("---- LET US GO SOUTH ----") - new_player = Player("Jayne", room['narrow']) + elif new_player.current_room == treasure: + print("\n---- LET US GO SOUTH ----\n") + new_player.current_room = narrow print(new_player.current_room) elif user_prompt.lower() == 'e': #OUTSIDE - if new_player.current_room.name == 'Outside Cave Entrance': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['outside']) + if new_player.current_room == outside: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = outside print(new_player.current_room) #FOYER - elif new_player.current_room.name == 'Foyer': - print("---- LET US GO EAST ----") - new_player = Player("Jayne", room['narrow']) + elif new_player.current_room == foyer: + print("\n---- LET US GO EAST ----\n") + new_player.current_room = narrow print(new_player.current_room) #OVERLOOK - elif new_player.current_room.name == 'Grand Overlook': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['overlook']) + elif new_player.current_room == overlook: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = overlook print(new_player.current_room) #NARROW - elif new_player.current_room.name == 'Narrow Passage': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['narrow']) + elif new_player.current_room == narrow: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = narrow print(new_player.current_room) #TREASURE - elif new_player.current_room.name == 'Treasure Chamber': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['treasure']) + elif new_player.current_room == treasure: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = treasure print(new_player.current_room) elif user_prompt.lower() == 'w': #OUTSIDE - if new_player.current_room.name == 'Outside Cave Entrance': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['outside']) + if new_player.current_room == outside: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = outside print(new_player.current_room) #FOYER - elif new_player.current_room.name == 'Foyer': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['foyer']) + elif new_player.current_room == foyer: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = foyer print(new_player.current_room) #OVERLOOK - elif new_player.current_room.name == 'Grand Overlook': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['overlook']) + elif new_player.current_room == overlook: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = overlook print(new_player.current_room) #NARROW - elif new_player.current_room.name == 'Narrow Passage': - print("---- LET US GO WEST ----") - new_player = Player("Jayne", room['foyer']) + elif new_player.current_room == narrow: + print("\n---- LET US GO WEST ----\n") + new_player.current_room = foyer print(new_player.current_room) #TREASURE - elif new_player.current_room.name == 'Treasure Chamber': - print("---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----") - new_player = Player("Jayne", room['treasure']) + elif new_player.current_room == treasure: + print("\n---- YOU SHALL NOT PASS ----") + print("---- CHOOSE ANOTHER DIRECTION ----\n") + new_player.current_room = treasure print(new_player.current_room) # If the user enters "q", quit the game elif user_prompt.lower() == 'q': diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..46fe928f4e --- /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}" \ No newline at end of file diff --git a/src/room.py b/src/room.py index 003842b2d6..8b16b88207 100644 --- a/src/room.py +++ b/src/room.py @@ -1,15 +1,39 @@ # Implement a class to hold room information. This should have name and # description attributes. +from item import Item class Room: # construction function def __init__(self, name, description): self.name = name self.description = description + self.room_items = [] def __str__(self): - return f"room name is {self.name}" + return f"room name is {self.name}" - def add_item(self, item): + def stealthy_add(self, item): self.item = item + # seitem = Item(item_name, item_description) + self.room_items.append(item) + + def add_room_item(self, item): + self.item = item + self.room_items.append(item) + for i in self.room_items: + print(f"{i.name} added to {self.name}") + + def room_inventory(self): + if (len(self.room_items) == 0): + return f"There's nothing in this room. That sucks. Search other rooms!" + elif (len(self.room_items) > 0): + print(f"\nLook what you found in the {self.name}:\n") + for i in self.room_items: + print(f"{i}") + + + + + # def add_item(self, item): + # self.item = item pass From d5eb23f8cda4a2c6025ff3f097fc4ee5a2228b17 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Thu, 9 Apr 2020 23:02:49 +0100 Subject: [PATCH 11/19] added [look] and [inv] to game --- src/adv.py | 39 +++++++++++++++++++++++++++++++-------- src/player.py | 19 +++++++++++++++++++ src/room.py | 6 +++--- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/adv.py b/src/adv.py index 032232ce68..bab7b337a0 100644 --- a/src/adv.py +++ b/src/adv.py @@ -43,7 +43,6 @@ # Make a new player object that is currently in the 'outside' room. new_player = Player("Jayne", room['outside']) -# print(len(room['outside'].room_items)) # CREATE VARIABLES FOR ROOMS outside = room['outside'] @@ -70,12 +69,10 @@ gold = Item("Gold coins", "they are worth a fortune!") treasure.stealthy_add(gold) -print("\n------- WELCOME TO JAYNE'S GAME ---------\n") - - - - +# knife = Item("Knife", "pocket knife, hidden in your socks") +# new_player.add_player_item(knife) +print("\n------- WELCOME TO JAYNE'S GAME ---------\n") # Write a loop that: @@ -94,12 +91,12 @@ print(" > " + element) # * Waits for user input and decides what to do - user_prompt = (input("\n---- WHERE DO YOU WANT TO GO ? ---- \n Type [n], [s], [e] or [w]\n OR [look]\n OR quit:(q): ")) + user_prompt = (input("\n---- WHAT NOW ? ---- \n[n], [s], [e] or [w] to move\n[look] to search rooms\n[inv] to see your stash\n[q] to quit: ")) - # JAYNE: USER_PROMPT IS A STRING # If the user enters a cardinal direction, attempt to move to the room there. + # NORTH if user_prompt.lower() == 'n': #OUTSIDE if new_player.current_room == outside: @@ -128,6 +125,7 @@ print("---- CHOOSE ANOTHER DIRECTION ----\n") new_player.current_room = treasure print(new_player.current_room) + # SOUTH elif user_prompt.lower() == 's': #OUTSIDE if new_player.current_room == outside: @@ -156,6 +154,7 @@ print("\n---- LET US GO SOUTH ----\n") new_player.current_room = narrow print(new_player.current_room) + # EAST elif user_prompt.lower() == 'e': #OUTSIDE if new_player.current_room == outside: @@ -186,6 +185,7 @@ print("---- CHOOSE ANOTHER DIRECTION ----\n") new_player.current_room = treasure print(new_player.current_room) + # WEST elif user_prompt.lower() == 'w': #OUTSIDE if new_player.current_room == outside: @@ -216,6 +216,29 @@ print("---- CHOOSE ANOTHER DIRECTION ----\n") new_player.current_room = treasure print(new_player.current_room) + # LOOK + elif user_prompt.lower() == 'look': + #OUTSIDE + if new_player.current_room == outside: + outside.room_inventory() + # FOYER + elif new_player.current_room == foyer: + foyer.room_inventory() + # OVERLOOK + elif new_player.current_room == overlook: + overlook.room_inventory() + # NARROW + elif new_player.current_room == narrow: + narrow.room_inventory() + # TREASURE + elif new_player.current_room == treasure: + treasure.room_inventory() + # INV + elif user_prompt.lower() == 'inv': + new_player.player_inventory() + # GRAB + # IF PROMPT IS EQUAL TO NAME OF ITEM IN ROOM INVENTORY, DROP FROM ROOM INVENTORY AND ADD TO PLAYERS STASH + # If the user enters "q", quit the game elif user_prompt.lower() == 'q': print("Thank you for playing \nGoodbye!") diff --git a/src/player.py b/src/player.py index 7d838e03c2..394929e4ac 100644 --- a/src/player.py +++ b/src/player.py @@ -1,14 +1,33 @@ # Write a class to hold player information, e.g. what room they are in # currently. +from item import Item class Player: # constructor function def __init__(self, name, room): self.name = name self.current_room = room + self.player_items = [] # string value def __str__(self): return f"{self.name} is currently located: {self.current_room.name}" + + def add_player_item(self, item): + self.item = item + self.player_items.append(item) + for i in self.player_items: + print(f"{i.name} added to {self.name}'s stash") + + def player_inventory(self): + if (len(self.player_items) >= 1): + print(f"\n>> Here is what you have on your person:") + for i in self.player_items: + print(f"\t{i}") + else: + print(f"\n>> You dont have anything on your person.\nLook in rooms!\n") + pass + + diff --git a/src/room.py b/src/room.py index 8b16b88207..7747f38019 100644 --- a/src/room.py +++ b/src/room.py @@ -14,7 +14,6 @@ def __str__(self): def stealthy_add(self, item): self.item = item - # seitem = Item(item_name, item_description) self.room_items.append(item) def add_room_item(self, item): @@ -27,9 +26,10 @@ def room_inventory(self): if (len(self.room_items) == 0): return f"There's nothing in this room. That sucks. Search other rooms!" elif (len(self.room_items) > 0): - print(f"\nLook what you found in the {self.name}:\n") + print(f"\n>> Look what you found at {self.name}:") for i in self.room_items: - print(f"{i}") + print(f"\t{i}") + print(f"\n") From 1d2d30d847d10637a0988ae94223eb1ba9f26ca4 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Thu, 9 Apr 2020 23:21:50 +0100 Subject: [PATCH 12/19] working on GRAB and DROP functionality --- src/adv.py | 14 +++++++++++--- src/player.py | 7 +++++++ src/room.py | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/adv.py b/src/adv.py index bab7b337a0..2275b74f30 100644 --- a/src/adv.py +++ b/src/adv.py @@ -69,8 +69,8 @@ gold = Item("Gold coins", "they are worth a fortune!") treasure.stealthy_add(gold) -# knife = Item("Knife", "pocket knife, hidden in your socks") -# new_player.add_player_item(knife) +knife = Item("Knife", "pocket knife, hidden in your socks") +new_player.add_player_item(knife) print("\n------- WELCOME TO JAYNE'S GAME ---------\n") @@ -236,8 +236,16 @@ # INV elif user_prompt.lower() == 'inv': new_player.player_inventory() - # GRAB + # VERB NOUN + elif user_prompt.lower()[:4] == 'grab': + print("Grab!") + # GRAB + # IF PROMPT IS EQUAL TO NAME OF ITEM IN ROOM INVENTORY, DROP FROM ROOM INVENTORY AND ADD TO PLAYERS STASH + # DROP + elif user_prompt.lower()[:4] == 'drop': + print("Drop!") + new_player.drop_player_item(knife) # If the user enters "q", quit the game elif user_prompt.lower() == 'q': diff --git a/src/player.py b/src/player.py index 394929e4ac..369a0d1f84 100644 --- a/src/player.py +++ b/src/player.py @@ -19,6 +19,13 @@ def add_player_item(self, item): for i in self.player_items: print(f"{i.name} added to {self.name}'s stash") + def drop_player_item(self, item): + self.item = item + self.player_items.remove(item) + print(f"{item.name} removed from your stash") + self.current_room.room_items.append(item) + print(f"{item.name} left in {self.current_room}") + def player_inventory(self): if (len(self.player_items) >= 1): print(f"\n>> Here is what you have on your person:") diff --git a/src/room.py b/src/room.py index 7747f38019..2a6a2753e1 100644 --- a/src/room.py +++ b/src/room.py @@ -21,6 +21,7 @@ def add_room_item(self, item): self.room_items.append(item) for i in self.room_items: print(f"{i.name} added to {self.name}") + def room_inventory(self): if (len(self.room_items) == 0): From f655a8a96129efcb48a1ebb2df4a91aed814e7e2 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Fri, 10 Apr 2020 16:52:22 +0100 Subject: [PATCH 13/19] completed grab and drop functionality for game --- src/adv.py | 66 ++++++++++++++++++++++++++++++++++++++++++--------- src/player.py | 12 ++++++++-- src/room.py | 8 ++++--- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/src/adv.py b/src/adv.py index 2275b74f30..268e804889 100644 --- a/src/adv.py +++ b/src/adv.py @@ -53,11 +53,10 @@ # ADD ITEMS TO ROOMS -axe = Item("AXE", "by jove, it is sharp") -compass = Item("Compass", "weathered, but still works") +axe = Item("Axe", "by jove, it is sharp") outside.stealthy_add(axe) -outside.stealthy_add(compass) +compass = Item("Compass", "weathered, but still works") foyer.stealthy_add(compass) binoculars = Item("Binoculars", "handy for spying") @@ -66,11 +65,11 @@ torch = Item("Torch", "batteries running low") narrow.stealthy_add(torch) -gold = Item("Gold coins", "they are worth a fortune!") +gold = Item("Gold", "a small canvas sack filled with gold coins, they are worth a fortune!") treasure.stealthy_add(gold) -knife = Item("Knife", "pocket knife, hidden in your socks") -new_player.add_player_item(knife) +knife = Item("Knife", "pocket knife, could be hidden in your socks") +new_player.stealthy_add(knife) print("\n------- WELCOME TO JAYNE'S GAME ---------\n") @@ -90,8 +89,10 @@ for element in word_list: print(" > " + element) + # USER PROMPT + # * Waits for user input and decides what to do - user_prompt = (input("\n---- WHAT NOW ? ---- \n[n], [s], [e] or [w] to move\n[look] to search rooms\n[inv] to see your stash\n[q] to quit: ")) + user_prompt = (input("\n---- WHAT NOW ? ---- \n[n], [s], [e] or [w] to move\n[look] to search room\n[inv] to see your stash\n[grab] [item] to grab\n[drop] [item] to drop\n[q] to quit: ")) # If the user enters a cardinal direction, attempt to move to the room there. @@ -237,15 +238,58 @@ elif user_prompt.lower() == 'inv': new_player.player_inventory() # VERB NOUN + + # GRAB elif user_prompt.lower()[:4] == 'grab': - print("Grab!") # GRAB - - # IF PROMPT IS EQUAL TO NAME OF ITEM IN ROOM INVENTORY, DROP FROM ROOM INVENTORY AND ADD TO PLAYERS STASH + grab_separate_words = user_prompt.split(' ') + command = grab_separate_words[0] + item_to_grab = grab_separate_words[1].lower() + + current_room_items = [f"{data.name.lower()}" for data in new_player.current_room.room_items] + + if item_to_grab in current_room_items: + print(f"\n\t>> YOU GRAB: {item_to_grab}") + if item_to_grab == 'axe': + new_player.add_player_item(axe) + elif item_to_grab == 'compass': + new_player.add_player_item(compass) + elif item_to_grab == 'binoculars': + new_player.add_player_item(binoculars) + elif item_to_grab == 'torch': + new_player.add_player_item(torch) + elif item_to_grab == 'gold': + new_player.add_player_item(gold) + elif item_to_grab == 'knife': + new_player.add_player_item(knife) + else: + print("\nThat item is not found here!!\nSearch for it elsewhere\n") # DROP elif user_prompt.lower()[:4] == 'drop': print("Drop!") - new_player.drop_player_item(knife) + # new_player.drop_player_item(knife) + grab_separate_words = user_prompt.split(' ') + command = grab_separate_words[0] + item_to_grab = grab_separate_words[1].lower() + + current_room_items = [f"{data.name.lower()}" for data in new_player.player_items] + + if item_to_grab in current_room_items: + print(f"\t>> YOU DROP: {item_to_grab}") + if item_to_grab == 'axe': + new_player.drop_player_item(axe) + elif item_to_grab == 'compass': + new_player.drop_player_item(compass) + elif item_to_grab == 'binoculars': + new_player.drop_player_item(binoculars) + elif item_to_grab == 'torch': + new_player.drop_player_item(torch) + elif item_to_grab == 'gold': + new_player.drop_player_item(gold) + elif item_to_grab == 'knife': + new_player.drop_player_item(knife) + else: + print("\nThat item is not found here!!\nSearch for it elsewhere\n") # If the user enters "q", quit the game elif user_prompt.lower() == 'q': diff --git a/src/player.py b/src/player.py index 369a0d1f84..3bc3979344 100644 --- a/src/player.py +++ b/src/player.py @@ -13,18 +13,25 @@ def __init__(self, name, room): def __str__(self): return f"{self.name} is currently located: {self.current_room.name}" + def stealthy_add(self, item): + self.item = item + self.player_items.append(item) + def add_player_item(self, item): self.item = item self.player_items.append(item) for i in self.player_items: - print(f"{i.name} added to {self.name}'s stash") + print(f"\t>> {i.name} is in {self.name}'s stash") + print("\n") + self.current_room.room_items.remove(item) def drop_player_item(self, item): self.item = item self.player_items.remove(item) print(f"{item.name} removed from your stash") self.current_room.room_items.append(item) - print(f"{item.name} left in {self.current_room}") + print(f"{item.name} left in {self.current_room.name}") + print("\n") def player_inventory(self): if (len(self.player_items) >= 1): @@ -33,6 +40,7 @@ def player_inventory(self): print(f"\t{i}") else: print(f"\n>> You dont have anything on your person.\nLook in rooms!\n") + print("\n") pass diff --git a/src/room.py b/src/room.py index 2a6a2753e1..7dc1421880 100644 --- a/src/room.py +++ b/src/room.py @@ -20,17 +20,19 @@ def add_room_item(self, item): self.item = item self.room_items.append(item) for i in self.room_items: - print(f"{i.name} added to {self.name}") - + print(f"{i.name} added to {self.name}") def room_inventory(self): if (len(self.room_items) == 0): - return f"There's nothing in this room. That sucks. Search other rooms!" + print(f"\n\t>> There's nothing in this room. That sucks. Search other rooms!\n") elif (len(self.room_items) > 0): print(f"\n>> Look what you found at {self.name}:") for i in self.room_items: print(f"\t{i}") print(f"\n") + else: + print(f"\n\t>> There's nothing in this room. That sucks. Search other rooms!\n") + From 1deccf902c54dd21836e6887301cc733001c1741 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 3 Jun 2020 14:48:23 +0100 Subject: [PATCH 14/19] improvements in GRAB and DROP --- src/adv.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/adv.py b/src/adv.py index 268e804889..6354cf398e 100644 --- a/src/adv.py +++ b/src/adv.py @@ -92,7 +92,7 @@ # USER PROMPT # * Waits for user input and decides what to do - user_prompt = (input("\n---- WHAT NOW ? ---- \n[n], [s], [e] or [w] to move\n[look] to search room\n[inv] to see your stash\n[grab] [item] to grab\n[drop] [item] to drop\n[q] to quit: ")) + user_prompt = (input("\n---- WHAT NOW ? ---- \n[n], [s], [e] or [w] to move\n\n[look] to search room\n[inv] to see your stash\n[grab] [item] to grab\n[drop] [item] to drop\n[q] to quit: ")) # If the user enters a cardinal direction, attempt to move to the room there. @@ -237,8 +237,13 @@ # INV elif user_prompt.lower() == 'inv': new_player.player_inventory() + # VERB NOUN + # GRAB ONLY + elif user_prompt.lower() == 'grab': + print("\n\tGRAB WHAT..?\nYou need to tell me!!\n") + # GRAB elif user_prompt.lower()[:4] == 'grab': # GRAB @@ -264,9 +269,14 @@ new_player.add_player_item(knife) else: print("\nThat item is not found here!!\nSearch for it elsewhere\n") + + # DROP ONLY + elif user_prompt.lower() == 'drop': + print("\n\tDROP WHAT..?\nYou need to specify - I'm not psychic!\n") + # DROP elif user_prompt.lower()[:4] == 'drop': - print("Drop!") + print("\nDrop!") # new_player.drop_player_item(knife) grab_separate_words = user_prompt.split(' ') command = grab_separate_words[0] From fa65cf46a20681b025a01a7997c08acdfa6b72e3 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 3 Jun 2020 15:38:36 +0100 Subject: [PATCH 15/19] added option for prompts when user types item without action prompt. Checks if item is in the players items they have picked up --- src/adv.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/src/adv.py b/src/adv.py index 6354cf398e..3bbe73cc69 100644 --- a/src/adv.py +++ b/src/adv.py @@ -237,11 +237,74 @@ # INV elif user_prompt.lower() == 'inv': new_player.player_inventory() + + # ITEM ONLY + # AXE + elif user_prompt.lower() == 'axe': + typed_item = user_prompt.lower() + + player_items = [f"{data.name.lower()}" for data in new_player.player_items] + + if typed_item in player_items: + print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + else: + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + # COMPASS + elif user_prompt.lower() == 'compass': + typed_item = user_prompt.lower() + + player_items = [f"{data.name.lower()}" for data in new_player.player_items] + + if typed_item in player_items: + print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + else: + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + # BINOCULARS + elif user_prompt.lower() == 'binoculars': + typed_item = user_prompt.lower() + + player_items = [f"{data.name.lower()}" for data in new_player.player_items] + + if typed_item in player_items: + print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + else: + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + # TORCH + elif user_prompt.lower() == 'torch': + typed_item = user_prompt.lower() + + player_items = [f"{data.name.lower()}" for data in new_player.player_items] + + if typed_item in player_items: + print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + else: + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + # GOLD + elif user_prompt.lower() == 'gold': + typed_item = user_prompt.lower() + + player_items = [f"{data.name.lower()}" for data in new_player.player_items] + + if typed_item in player_items: + print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + else: + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + # KNIFE + elif user_prompt.lower() == 'knife': + typed_item = user_prompt.lower() + + player_items = [f"{data.name.lower()}" for data in new_player.player_items] + + if typed_item in player_items: + print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> YOU NEED TO TELL ME!!\n") + else: + print(f"\n\t>> If you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + # VERB NOUN # GRAB ONLY - elif user_prompt.lower() == 'grab': + if user_prompt.lower() == 'grab': print("\n\tGRAB WHAT..?\nYou need to tell me!!\n") # GRAB @@ -307,5 +370,5 @@ break # Print an error message if the movement isn't allowed. else: - print("---- INVALID COMMAND ----") - print("PLEASE SELECT FROM: n, s, e, w or q") + print("\n---- INVALID COMMAND ----") + print("PLEASE SELECT FROM: n, s, e, w or q\n") From 466b6f2dd749e6d36c1547ff2964a912d0e3efe4 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Wed, 3 Jun 2020 16:03:17 +0100 Subject: [PATCH 16/19] changing text width --- src/adv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/adv.py b/src/adv.py index 3bbe73cc69..038adcfb7a 100644 --- a/src/adv.py +++ b/src/adv.py @@ -84,10 +84,10 @@ # * Prints the current description (the textwrap module might be useful here). room_description = new_player.current_room.description - wrapper = textwrap.TextWrapper(width=15) + wrapper = textwrap.TextWrapper(width=25) word_list = wrapper.wrap(text=room_description) for element in word_list: - print(" > " + element) + print(" > " + element) # USER PROMPT @@ -304,7 +304,7 @@ # VERB NOUN # GRAB ONLY - if user_prompt.lower() == 'grab': + elif user_prompt.lower() == 'grab': print("\n\tGRAB WHAT..?\nYou need to tell me!!\n") # GRAB @@ -370,5 +370,5 @@ break # Print an error message if the movement isn't allowed. else: - print("\n---- INVALID COMMAND ----") + print("\n---- INVALID COMMAND ----\n") print("PLEASE SELECT FROM: n, s, e, w or q\n") From bc04e1ffb55d8486df76e888601f6e7d0a0d14d9 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Thu, 4 Jun 2020 14:49:47 +0100 Subject: [PATCH 17/19] tidying up the look of the phrases --- src/adv.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/adv.py b/src/adv.py index 038adcfb7a..41c26e8e74 100644 --- a/src/adv.py +++ b/src/adv.py @@ -247,9 +247,9 @@ player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: - print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") else: - print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!\n") # COMPASS elif user_prompt.lower() == 'compass': typed_item = user_prompt.lower() @@ -257,9 +257,9 @@ player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: - print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") else: - print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!\n") # BINOCULARS elif user_prompt.lower() == 'binoculars': typed_item = user_prompt.lower() @@ -267,9 +267,9 @@ player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: - print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") else: - print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!\n") # TORCH elif user_prompt.lower() == 'torch': typed_item = user_prompt.lower() @@ -277,9 +277,9 @@ player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: - print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") else: - print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!\n") # GOLD elif user_prompt.lower() == 'gold': typed_item = user_prompt.lower() @@ -287,9 +287,9 @@ player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: - print(f"\n\tWhat do you want me to do with {typed_item}? \n\tYou need to tell me!!\n") + print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") else: - print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!\n") # KNIFE elif user_prompt.lower() == 'knife': typed_item = user_prompt.lower() @@ -297,9 +297,9 @@ player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: - print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> YOU NEED TO TELL ME!!\n") + print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") else: - print(f"\n\t>> If you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!") + print(f"\n\tIf you want to do something with {typed_item}, YOU NEED TO GO FIND IT FIRST!!!!\n") # VERB NOUN From f8aec0649516372da75ec8a17ee924eae62908a7 Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Thu, 4 Jun 2020 16:12:46 +0100 Subject: [PATCH 18/19] failsafe if someone selects [grab] [item] when they already have it --- src/adv.py | 58 ++++++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/src/adv.py b/src/adv.py index 41c26e8e74..34259e7ead 100644 --- a/src/adv.py +++ b/src/adv.py @@ -94,6 +94,7 @@ # * Waits for user input and decides what to do user_prompt = (input("\n---- WHAT NOW ? ---- \n[n], [s], [e] or [w] to move\n\n[look] to search room\n[inv] to see your stash\n[grab] [item] to grab\n[drop] [item] to drop\n[q] to quit: ")) + nope ="\n---- YOU SHALL NOT PASS ----\n---- CHOOSE ANOTHER DIRECTION ----\n" # If the user enters a cardinal direction, attempt to move to the room there. @@ -111,9 +112,7 @@ print(new_player.current_room) #OVERLOOK elif new_player.current_room == overlook: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = overlook + print(nope) print(new_player.current_room) #NARROW elif new_player.current_room == narrow: @@ -122,17 +121,13 @@ print(new_player.current_room) #TREASURE elif new_player.current_room == treasure: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = treasure + print(nope) print(new_player.current_room) # SOUTH elif user_prompt.lower() == 's': #OUTSIDE if new_player.current_room == outside: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = outside + print(nope) print(new_player.current_room) #FOYER elif new_player.current_room == foyer: @@ -146,9 +141,7 @@ print(new_player.current_room) #NARROW elif new_player.current_room == narrow: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = narrow + print(nope) print(new_player.current_room) #TREASURE elif new_player.current_room == treasure: @@ -159,9 +152,7 @@ elif user_prompt.lower() == 'e': #OUTSIDE if new_player.current_room == outside: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = outside + print(nope) print(new_player.current_room) #FOYER elif new_player.current_room == foyer: @@ -170,41 +161,29 @@ print(new_player.current_room) #OVERLOOK elif new_player.current_room == overlook: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = overlook + print(nope) print(new_player.current_room) #NARROW elif new_player.current_room == narrow: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = narrow + print(nope) print(new_player.current_room) #TREASURE elif new_player.current_room == treasure: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = treasure + print(nope) print(new_player.current_room) # WEST elif user_prompt.lower() == 'w': #OUTSIDE if new_player.current_room == outside: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = outside + print(nope) print(new_player.current_room) #FOYER elif new_player.current_room == foyer: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = foyer + print(nope) print(new_player.current_room) #OVERLOOK elif new_player.current_room == overlook: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = overlook + print(nope) print(new_player.current_room) #NARROW elif new_player.current_room == narrow: @@ -213,10 +192,9 @@ print(new_player.current_room) #TREASURE elif new_player.current_room == treasure: - print("\n---- YOU SHALL NOT PASS ----") - print("---- CHOOSE ANOTHER DIRECTION ----\n") - new_player.current_room = treasure + print(nope) print(new_player.current_room) + # LOOK elif user_prompt.lower() == 'look': #OUTSIDE @@ -316,6 +294,8 @@ current_room_items = [f"{data.name.lower()}" for data in new_player.current_room.room_items] + player_items = [f"{data.name.lower()}" for data in new_player.player_items] + if item_to_grab in current_room_items: print(f"\n\t>> YOU GRAB: {item_to_grab}") if item_to_grab == 'axe': @@ -329,7 +309,11 @@ elif item_to_grab == 'gold': new_player.add_player_item(gold) elif item_to_grab == 'knife': - new_player.add_player_item(knife) + new_player.add_player_item(knife) + + elif item_to_grab in player_items: + print(f"\n>> You already have --{item_to_grab}-- in your stash, ya numpty!!\n\t>> Type [inv] to see whatcha got!\n") + else: print("\nThat item is not found here!!\nSearch for it elsewhere\n") From 6b31103a3431975218ea3e42773e1f4d40923a3f Mon Sep 17 00:00:00 2001 From: Jayne Carmichael Norrie <39460834+jaynecn@users.noreply.github.com> Date: Thu, 4 Jun 2020 21:31:35 +0100 Subject: [PATCH 19/19] added spyglass and note. Use them in combination with READ functionality to read the note. --- src/adv.py | 62 ++++++++++++++++++++++++++++++++++++++++++++------- src/player.py | 1 + src/text.txt | 3 +++ 3 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/text.txt diff --git a/src/adv.py b/src/adv.py index 34259e7ead..97771227e3 100644 --- a/src/adv.py +++ b/src/adv.py @@ -71,6 +71,13 @@ knife = Item("Knife", "pocket knife, could be hidden in your socks") new_player.stealthy_add(knife) +spyglass = Item("Spyglass", "useful for reading") +narrow.stealthy_add(spyglass) + +note = Item("Note", "drops of blood with faint, shaky writing") +foyer.stealthy_add(note) +# MAKE EVERY NEW ITEM NAME ONE WORD!!! + print("\n------- WELCOME TO JAYNE'S GAME ---------\n") # Write a loop that: @@ -96,6 +103,9 @@ nope ="\n---- YOU SHALL NOT PASS ----\n---- CHOOSE ANOTHER DIRECTION ----\n" + player_items = [f"{data.name.lower()}" for data in new_player.player_items] + + # If the user enters a cardinal direction, attempt to move to the room there. # NORTH @@ -215,6 +225,8 @@ # INV elif user_prompt.lower() == 'inv': new_player.player_inventory() + if 'note' and 'spyglass' in player_items: + print(f"\n\t.. [UNLOCKED]\n\tNow you have the spyglass and the note, you can select [READ] to read the note!!") # ITEM ONLY @@ -222,7 +234,7 @@ elif user_prompt.lower() == 'axe': typed_item = user_prompt.lower() - player_items = [f"{data.name.lower()}" for data in new_player.player_items] + # player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") @@ -232,7 +244,7 @@ elif user_prompt.lower() == 'compass': typed_item = user_prompt.lower() - player_items = [f"{data.name.lower()}" for data in new_player.player_items] + # player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") @@ -242,7 +254,7 @@ elif user_prompt.lower() == 'binoculars': typed_item = user_prompt.lower() - player_items = [f"{data.name.lower()}" for data in new_player.player_items] + # player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") @@ -252,7 +264,7 @@ elif user_prompt.lower() == 'torch': typed_item = user_prompt.lower() - player_items = [f"{data.name.lower()}" for data in new_player.player_items] + # player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") @@ -262,7 +274,7 @@ elif user_prompt.lower() == 'gold': typed_item = user_prompt.lower() - player_items = [f"{data.name.lower()}" for data in new_player.player_items] + # player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") @@ -272,7 +284,7 @@ elif user_prompt.lower() == 'knife': typed_item = user_prompt.lower() - player_items = [f"{data.name.lower()}" for data in new_player.player_items] + # player_items = [f"{data.name.lower()}" for data in new_player.player_items] if typed_item in player_items: print(f"\n\t>> What do you want me to do with {typed_item}? \n\t>> You need to tell me!!\n") @@ -294,7 +306,7 @@ current_room_items = [f"{data.name.lower()}" for data in new_player.current_room.room_items] - player_items = [f"{data.name.lower()}" for data in new_player.player_items] + # player_items = [f"{data.name.lower()}" for data in new_player.player_items] if item_to_grab in current_room_items: print(f"\n\t>> YOU GRAB: {item_to_grab}") @@ -310,12 +322,18 @@ new_player.add_player_item(gold) elif item_to_grab == 'knife': new_player.add_player_item(knife) + elif item_to_grab == 'spyglass': + print(f"\nYou have {item_to_grab}, now go find something to read!!\n") + new_player.add_player_item(spyglass) + elif item_to_grab == 'note': + new_player.add_player_item(note) elif item_to_grab in player_items: print(f"\n>> You already have --{item_to_grab}-- in your stash, ya numpty!!\n\t>> Type [inv] to see whatcha got!\n") else: print("\nThat item is not found here!!\nSearch for it elsewhere\n") + # DROP ONLY elif user_prompt.lower() == 'drop': @@ -344,10 +362,38 @@ elif item_to_grab == 'gold': new_player.drop_player_item(gold) elif item_to_grab == 'knife': - new_player.drop_player_item(knife) + new_player.drop_player_item(knife) + elif item_to_grab == 'spyglass': + new_player.drop_player_item(spyglass) + elif item_to_grab == 'note': + new_player.drop_player_item(note) else: print("\nThat item is not found here!!\nSearch for it elsewhere\n") + + # READ + elif user_prompt.lower() == 'read': + # player_items = [f"{data.name.lower()}" for data in new_player.player_items] + + if 'spyglass' in player_items and 'note' in player_items: + print("\nHere is what the note says:\n") + with open('src/text.txt') as text: + text_doc = text.read() + print(text_doc) + print("\n") + text.close() + + elif 'spyglass' in player_items and 'note' not in player_items: + print("\nGo get the note!!\n") + elif 'note' in player_items and 'spyglass' not in player_items: + print(f"\n\t>> The note's too faint.\n\t>> You need something to help you read.\n\t>> Look around!\n") + else: + print(f"\n\t>> You can't use this.\n\t>> You ain't got the gear yet!! Go look!!!\n") + + #UNLOCK + # elif 'spyglass' and 'note' in player_items: + # print(f"\n [UNLOCKED]\nNow you have the spyglass and the note, you can select [READ] to read the note!!") + # If the user enters "q", quit the game elif user_prompt.lower() == 'q': print("Thank you for playing \nGoodbye!") diff --git a/src/player.py b/src/player.py index 3bc3979344..3f2ff99556 100644 --- a/src/player.py +++ b/src/player.py @@ -27,6 +27,7 @@ def add_player_item(self, item): def drop_player_item(self, item): self.item = item + # print(self.item) self.player_items.remove(item) print(f"{item.name} removed from your stash") self.current_room.room_items.append(item) diff --git a/src/text.txt b/src/text.txt new file mode 100644 index 0000000000..60624f7e70 --- /dev/null +++ b/src/text.txt @@ -0,0 +1,3 @@ +WATCH OUT +HOLY CRAP +THERE'S A MONSTER!! \ No newline at end of file