From 294c2e9222347e1211cde8995306b68cc84213de Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 13:14:44 -0600 Subject: [PATCH 01/20] init commit --- examples/guessing_game.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/guessing_game.py b/examples/guessing_game.py index 5c27a5443f..526f846ad3 100644 --- a/examples/guessing_game.py +++ b/examples/guessing_game.py @@ -25,4 +25,6 @@ def guessing_game(): print("Too big!") if __name__ == '__main__': - guessing_game() \ No newline at end of file + guessing_game() + +# init \ No newline at end of file From f24f254ac7dd7c5233499645c81a94300d750abb Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 14:07:29 -0600 Subject: [PATCH 02/20] init Player and Room classes --- src/item.py | 4 ++++ src/player.py | 4 ++++ src/room.py | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/item.py diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..5ed21fc1dd --- /dev/null +++ b/src/item.py @@ -0,0 +1,4 @@ +# This will be the base class for specialized item types to be declared later. +# The item should have name and description attributes. +# Hint: the name should be one word for ease in parsing later. + diff --git a/src/player.py b/src/player.py index d79a175029..2028ed6403 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,6 @@ # Write a class to hold player information, e.g. what room they are in # currently. + +class Player: + def __init__(self, currentRoom): + self.currentRoom = currentRoom \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..b172774a9e 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,7 @@ # 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 From df825297dd0fd709931755e6cf72ba4f77b51a8a Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 14:16:22 -0600 Subject: [PATCH 03/20] add test for room class --- src/adv.py | 3 +++ src/player.py | 5 +++-- src/room.py | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..f4ba1049e9 100644 --- a/src/adv.py +++ b/src/adv.py @@ -21,6 +21,9 @@ earlier adventurers. The only exit is to the south."""), } +# Check Room class is being called correctly +# for x, i in room.items(): +# print(x, i) # Link rooms together diff --git a/src/player.py b/src/player.py index 2028ed6403..7ac462ea97 100644 --- a/src/player.py +++ b/src/player.py @@ -2,5 +2,6 @@ # currently. class Player: - def __init__(self, currentRoom): - self.currentRoom = currentRoom \ No newline at end of file + def __init__(self, currentRoom, playerItem): + self.currentRoom = currentRoom + self.playerItem = playerItem \ No newline at end of file diff --git a/src/room.py b/src/room.py index b172774a9e..4f37698dc1 100644 --- a/src/room.py +++ b/src/room.py @@ -5,3 +5,7 @@ class Room: def __init__(self, name, description): self.name = name self.description = description + + def __str__(self): + return str(self.__dict__) + From 1cdc253bd11313cde406f8b0966f3a217ee722f0 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 14:38:36 -0600 Subject: [PATCH 04/20] make player object, return what room and name in str --- src/adv.py | 4 ++++ src/player.py | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/adv.py b/src/adv.py index f4ba1049e9..7e17c28346 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 @@ -42,6 +43,9 @@ # Make a new player object that is currently in the 'outside' room. +p = Player('outside', 'Conner') +print(p) + # Write a loop that: # # * Prints the current room name diff --git a/src/player.py b/src/player.py index 7ac462ea97..632e109b87 100644 --- a/src/player.py +++ b/src/player.py @@ -2,6 +2,9 @@ # currently. class Player: - def __init__(self, currentRoom, playerItem): + def __init__(self, currentRoom, name): self.currentRoom = currentRoom - self.playerItem = playerItem \ No newline at end of file + self.name = name + + def __str__(self): + return f"{self.name} is currently in room: {self.currentRoom}" \ No newline at end of file From 0c0d261f0798c671b313f6e438fcd50d8afa9109 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 14:44:30 -0600 Subject: [PATCH 05/20] user input parser start --- src/adv.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index 7e17c28346..bcdf2d5683 100644 --- a/src/adv.py +++ b/src/adv.py @@ -44,7 +44,8 @@ # Make a new player object that is currently in the 'outside' room. p = Player('outside', 'Conner') -print(p) +# Checks the player info +# print(p) # Write a loop that: # @@ -56,3 +57,12 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + + +# Parser for user input +while True: + dir = input(">> ") + + if dir == 'q': + print("Good bye!") + exit() From 6678e6838bb0b71e59778a06ca5d665de212b2bb Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 16:39:00 -0600 Subject: [PATCH 06/20] redo of dungeon --- src/adv.py | 25 ++++++++++++++----------- src/room.py | 8 ++++++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/adv.py b/src/adv.py index bcdf2d5683..879fe2efea 100644 --- a/src/adv.py +++ b/src/adv.py @@ -24,7 +24,7 @@ # Check Room class is being called correctly # for x, i in room.items(): -# print(x, i) +# print(x) # Link rooms together @@ -42,10 +42,7 @@ # # Make a new player object that is currently in the 'outside' room. - -p = Player('outside', 'Conner') -# Checks the player info -# print(p) +player = Player(room['outside'], 'Conner') # Write a loop that: # @@ -58,11 +55,17 @@ # # If the user enters "q", quit the game. +player_move = input("[n] North, [e] East, [s] South, [w] West, [q] Quit") + +while player_move != 'q': + + if player_move == 'n' or player_move == 'e' or player_move == 's' or player_move == 'w': -# Parser for user input -while True: - dir = input(">> ") + if player_move == 'n': + player.currentRoom = player.currentRoom.n_to + print(player.currentRoom) + break + if player_move == 'q': + print("Good bye!") + quit() - if dir == 'q': - print("Good bye!") - exit() diff --git a/src/room.py b/src/room.py index 4f37698dc1..ce2d57f8dc 100644 --- a/src/room.py +++ b/src/room.py @@ -2,10 +2,14 @@ # description attributes. class Room: - def __init__(self, name, description): + def __init__(self, name, description, n_to, s_to, e_to, w_to): self.name = name self.description = description + self.n_to = n_to + self.s_to = s_to + self.e_to = e_to + self.w_to = w_to def __str__(self): - return str(self.__dict__) + return f"You are currently in {self.name}.\n {self.description}" From 4970c9a863b037560c85cbc4733c4335e5c7a209 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 16:50:08 -0600 Subject: [PATCH 07/20] update --- src/adv.py | 13 ++++++++----- src/room.py | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/adv.py b/src/adv.py index 879fe2efea..359e9ebcc1 100644 --- a/src/adv.py +++ b/src/adv.py @@ -55,17 +55,20 @@ # # If the user enters "q", quit the game. -player_move = input("[n] North, [e] East, [s] South, [w] West, [q] Quit") +player_move = input("[n] North, [e] East, [s] South, [w] West, [q] Quit >> ") -while player_move != 'q': +game_over = False + +while game_over == False: if player_move == 'n' or player_move == 'e' or player_move == 's' or player_move == 'w': - if player_move == 'n': + if player_move == 'n' and player.currentRoom.n_to != None: player.currentRoom = player.currentRoom.n_to print(player.currentRoom) - break + game_over = False + if player_move == 'q': print("Good bye!") - quit() + game_over = True diff --git a/src/room.py b/src/room.py index ce2d57f8dc..401faad188 100644 --- a/src/room.py +++ b/src/room.py @@ -2,7 +2,7 @@ # description attributes. class Room: - def __init__(self, name, description, n_to, s_to, e_to, w_to): + def __init__(self, name, description, n_to = None, s_to = None, e_to = None, w_to = None): self.name = name self.description = description self.n_to = n_to @@ -11,5 +11,5 @@ def __init__(self, name, description, n_to, s_to, e_to, w_to): self.w_to = w_to def __str__(self): - return f"You are currently in {self.name}.\n {self.description}" + return f"You are currently in {self.name}.\n{self.description}" From cf3e3a820046d5f2322d374f75868a02dd4e4c2c Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 16:58:51 -0600 Subject: [PATCH 08/20] player can move in the dungeon --- src/adv.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/adv.py b/src/adv.py index 359e9ebcc1..2d3cdf2918 100644 --- a/src/adv.py +++ b/src/adv.py @@ -55,20 +55,32 @@ # # If the user enters "q", quit the game. -player_move = input("[n] North, [e] East, [s] South, [w] West, [q] Quit >> ") game_over = False while game_over == False: - if player_move == 'n' or player_move == 'e' or player_move == 's' or player_move == 'w': + player_move = input("[n] North, [e] East, [s] South, [w] West, [q] Quit >> ") + + if player_move == 'n' or player_move == 'e' or player_move == 's' or player_move == 'w' or player_move == 'q': if player_move == 'n' and player.currentRoom.n_to != None: player.currentRoom = player.currentRoom.n_to print(player.currentRoom) - game_over = False - if player_move == 'q': + elif player_move == 'e' and player.currentRoom.e_to != None: + player.currentRoom = player.currentRoom.e_to + print(player.currentRoom) + + elif player_move == 's' and player.currentRoom.s_to != None: + player.currentRoom = player.currentRoom.s_to + print(player.currentRoom) + + elif player_move == 'w' and player.currentRoom.w_to != None: + player.currentRoom = player.currentRoom.w_to + print(player.currentRoom) + + elif player_move == 'q': print("Good bye!") game_over = True From be9865a297f494f513616f18ca235dd326b92dcc Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 17:00:55 -0600 Subject: [PATCH 09/20] can input a users name --- src/adv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index 2d3cdf2918..3ed830b631 100644 --- a/src/adv.py +++ b/src/adv.py @@ -42,7 +42,8 @@ # # Make a new player object that is currently in the 'outside' room. -player = Player(room['outside'], 'Conner') +name = input("What is your adventurer's name? ") +player = Player(room['outside'], name) # Write a loop that: # From 0d25f139136d775b6d1981bf6e925fdaf67604d8 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 17:13:03 -0600 Subject: [PATCH 10/20] handle going to an unavailable room --- src/adv.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/adv.py b/src/adv.py index 3ed830b631..5f05c57ca0 100644 --- a/src/adv.py +++ b/src/adv.py @@ -81,6 +81,18 @@ player.currentRoom = player.currentRoom.w_to print(player.currentRoom) + elif player_move == 'n' and player.currentRoom.n_to == None: + print('This seems to be the wrong way, please choose a different direction') + + elif player_move == 'e' and player.currentRoom.e_to == None: + print('This seems to be the wrong way, please choose a different direction') + + elif player_move == 's' and player.currentRoom.s_to == None: + print('This seems to be the wrong way, please choose a different direction') + + elif player_move == 'w' and player.currentRoom.w_to == None: + print('This seems to be the wrong way, please choose a different direction') + elif player_move == 'q': print("Good bye!") game_over = True From 1ada3699c9080726968bdeb24e377f66636172ca Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 17:15:05 -0600 Subject: [PATCH 11/20] clean up text in terminal --- src/adv.py | 2 +- src/room.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/adv.py b/src/adv.py index 5f05c57ca0..69fc178090 100644 --- a/src/adv.py +++ b/src/adv.py @@ -61,7 +61,7 @@ while game_over == False: - player_move = input("[n] North, [e] East, [s] South, [w] West, [q] Quit >> ") + player_move = input("\n[n] North, [e] East, [s] South, [w] West, [q] Quit >> ") if player_move == 'n' or player_move == 'e' or player_move == 's' or player_move == 'w' or player_move == 'q': diff --git a/src/room.py b/src/room.py index 401faad188..fd0a9d6202 100644 --- a/src/room.py +++ b/src/room.py @@ -11,5 +11,5 @@ def __init__(self, name, description, n_to = None, s_to = None, e_to = None, w_t self.w_to = w_to def __str__(self): - return f"You are currently in {self.name}.\n{self.description}" + return f"\nYou are currently in {self.name}.\n{self.description}" From 427f0e5ac1f9b250d49b7a909f5c44fa34a81719 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 18:00:35 -0600 Subject: [PATCH 12/20] push for review --- src/player.py | 7 ++++--- src/room.py | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/player.py b/src/player.py index 632e109b87..e1e2f8cd99 100644 --- a/src/player.py +++ b/src/player.py @@ -1,10 +1,11 @@ # Write a class to hold player information, e.g. what room they are in # currently. + class Player: - def __init__(self, currentRoom, name): + def __init__(self, currentRoom, playerName): self.currentRoom = currentRoom - self.name = name + self.playerName = playerName def __str__(self): - return f"{self.name} is currently in room: {self.currentRoom}" \ No newline at end of file + return f"{self.playerName} is currently in room: {self.currentRoom}" \ No newline at end of file diff --git a/src/room.py b/src/room.py index fd0a9d6202..4b0e12221d 100644 --- a/src/room.py +++ b/src/room.py @@ -1,8 +1,11 @@ # Implement a class to hold room information. This should have name and # description attributes. -class Room: +from player import Player + +class Room(Player): def __init__(self, name, description, n_to = None, s_to = None, e_to = None, w_to = None): + super().__init__(currentRoom, playerName) self.name = name self.description = description self.n_to = n_to @@ -12,4 +15,5 @@ def __init__(self, name, description, n_to = None, s_to = None, e_to = None, w_t def __str__(self): return f"\nYou are currently in {self.name}.\n{self.description}" + # return f"\n{playerName} are currently in {self.name}.\n{self.description}" From 6bc8bde9b72c9caae9dcb636d8f72c2ad2f817ec Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 19:56:01 -0600 Subject: [PATCH 13/20] add greeting update commands --- src/adv.py | 24 +++++++++++++----------- src/room.py | 5 +---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/adv.py b/src/adv.py index 69fc178090..f59cec5b8e 100644 --- a/src/adv.py +++ b/src/adv.py @@ -56,44 +56,46 @@ # # If the user enters "q", quit the game. +print(f"\nGreetings {player.playerName}, you can control your adventure using the keys: N, E, S, W to move around the dungeon and Q to end your time here") + game_over = False while game_over == False: - player_move = input("\n[n] North, [e] East, [s] South, [w] West, [q] Quit >> ") + player_move = input("\n[N] North, [E] East, [S] South, [W] West, [Q] Quit >> ").upper() - if player_move == 'n' or player_move == 'e' or player_move == 's' or player_move == 'w' or player_move == 'q': + if player_move == 'N' or player_move == 'E' or player_move == 'S' or player_move == 'W' or player_move == 'Q': - if player_move == 'n' and player.currentRoom.n_to != None: + if player_move == 'N' and player.currentRoom.n_to != None: player.currentRoom = player.currentRoom.n_to print(player.currentRoom) - elif player_move == 'e' and player.currentRoom.e_to != None: + elif player_move == 'E' and player.currentRoom.e_to != None: player.currentRoom = player.currentRoom.e_to print(player.currentRoom) - elif player_move == 's' and player.currentRoom.s_to != None: + elif player_move == 'S' and player.currentRoom.s_to != None: player.currentRoom = player.currentRoom.s_to print(player.currentRoom) - elif player_move == 'w' and player.currentRoom.w_to != None: + elif player_move == 'W' and player.currentRoom.w_to != None: player.currentRoom = player.currentRoom.w_to print(player.currentRoom) - elif player_move == 'n' and player.currentRoom.n_to == None: + elif player_move == 'N' and player.currentRoom.n_to == None: print('This seems to be the wrong way, please choose a different direction') - elif player_move == 'e' and player.currentRoom.e_to == None: + elif player_move == 'E' and player.currentRoom.e_to == None: print('This seems to be the wrong way, please choose a different direction') - elif player_move == 's' and player.currentRoom.s_to == None: + elif player_move == 'S' and player.currentRoom.s_to == None: print('This seems to be the wrong way, please choose a different direction') - elif player_move == 'w' and player.currentRoom.w_to == None: + elif player_move == 'W' and player.currentRoom.w_to == None: print('This seems to be the wrong way, please choose a different direction') - elif player_move == 'q': + elif player_move == 'Q': print("Good bye!") game_over = True diff --git a/src/room.py b/src/room.py index 4b0e12221d..4b270113bc 100644 --- a/src/room.py +++ b/src/room.py @@ -1,11 +1,8 @@ # Implement a class to hold room information. This should have name and # description attributes. -from player import Player - -class Room(Player): +class Room: def __init__(self, name, description, n_to = None, s_to = None, e_to = None, w_to = None): - super().__init__(currentRoom, playerName) self.name = name self.description = description self.n_to = n_to From 747fb689482b234df16f2a86a358407731c8ebcc Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 20:09:03 -0600 Subject: [PATCH 14/20] item class --- src/item.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/item.py b/src/item.py index 5ed21fc1dd..9aaeaa1d30 100644 --- a/src/item.py +++ b/src/item.py @@ -2,3 +2,10 @@ # The item should have name and description attributes. # Hint: the name should be one word for ease in parsing later. +class Item: + def __init__(self, item, itemDes): + self.item = item + self.itemDes = itemDes + + def __str__(self): + return f"{self.item}: {self.itemDes}" \ No newline at end of file From 167c806775ea33ec68524a423ec2f3adddae9629 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Wed, 13 Feb 2019 20:11:39 -0600 Subject: [PATCH 15/20] catch an invalid command --- src/adv.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/adv.py b/src/adv.py index f59cec5b8e..181168e347 100644 --- a/src/adv.py +++ b/src/adv.py @@ -99,3 +99,5 @@ print("Good bye!") game_over = True + else: + print('Invalid command, please choose from the given options') From bd80e1d3231d5b9ebaf7ef508eee50391e9b1972 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Thu, 14 Feb 2019 08:29:14 -0600 Subject: [PATCH 16/20] refactor wrong way statement --- src/adv.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/adv.py b/src/adv.py index 181168e347..41eee0584b 100644 --- a/src/adv.py +++ b/src/adv.py @@ -63,7 +63,14 @@ while game_over == False: - player_move = input("\n[N] North, [E] East, [S] South, [W] West, [Q] Quit >> ").upper() + player_move = input("\n[N] North, [E] East, [S] South, [W] West, [Q] Quit, [I] Items >> ").upper() + + if player_move == 'I': + item_input = input("[Drop] or [Take] [Item] >> ").upper() + + if item_input == 'DROP SWORD': + print('Sword has been dropped') + if player_move == 'N' or player_move == 'E' or player_move == 'S' or player_move == 'W' or player_move == 'Q': @@ -83,16 +90,7 @@ player.currentRoom = player.currentRoom.w_to print(player.currentRoom) - elif player_move == 'N' and player.currentRoom.n_to == None: - print('This seems to be the wrong way, please choose a different direction') - - elif player_move == 'E' and player.currentRoom.e_to == None: - print('This seems to be the wrong way, please choose a different direction') - - elif player_move == 'S' and player.currentRoom.s_to == None: - print('This seems to be the wrong way, please choose a different direction') - - elif player_move == 'W' and player.currentRoom.w_to == None: + elif player_move == 'N' and player.currentRoom.n_to == None or player_move == 'E' and player.currentRoom.e_to == None or player_move == 'S' and player.currentRoom.s_to == None or player_move == 'W' and player.currentRoom.w_to == None: print('This seems to be the wrong way, please choose a different direction') elif player_move == 'Q': From 27d3d13c2ce7b1aecc5533422233543bdd71daec Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Thu, 14 Feb 2019 08:35:53 -0600 Subject: [PATCH 17/20] clean up and comment --- src/adv.py | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/adv.py b/src/adv.py index 41eee0584b..74f026c48a 100644 --- a/src/adv.py +++ b/src/adv.py @@ -22,10 +22,6 @@ earlier adventurers. The only exit is to the south."""), } -# Check Room class is being called correctly -# for x, i in room.items(): -# print(x) - # Link rooms together room['outside'].n_to = room['foyer'] @@ -37,28 +33,20 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] -# -# Main -# +# ##################################################################### # +# Main # +# ##################################################################### # -# Make a new player object that is currently in the 'outside' room. +# Name input name = input("What is your adventurer's name? ") -player = Player(room['outside'], name) -# 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. -# -# If the user enters "q", quit the game. +# Player object starts 'outside' +player = Player(room['outside'], name) +# Greeting for when you enter the game print(f"\nGreetings {player.playerName}, you can control your adventure using the keys: N, E, S, W to move around the dungeon and Q to end your time here") - +# game loop game_over = False while game_over == False: From 4762d59c6efc47f0e016151fcad10ebd6cb95402 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Thu, 14 Feb 2019 15:22:50 -0600 Subject: [PATCH 18/20] players can drop and pick up items --- src/adv.py | 47 ++++++++++++++++++++++++++++++++++++++++++++--- src/item.py | 6 +++--- src/player.py | 3 ++- src/room.py | 9 ++++++--- 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/adv.py b/src/adv.py index 74f026c48a..33d05c5cc0 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,11 @@ from room import Room from player import Player +from item import Item + +# Declare items available + +sword = Item('Sword', 'A short and rusty blade, must of been left here ages ago!') +shield = Item('Shield', 'a small wooden shield') # Declare all the rooms @@ -46,6 +52,16 @@ # Greeting for when you enter the game print(f"\nGreetings {player.playerName}, you can control your adventure using the keys: N, E, S, W to move around the dungeon and Q to end your time here") +# Add items to foyer room +def add_items_to_foyer(): + if player.currentRoom.name != room['foyer'].name: + room['foyer'].items.pop() + room['foyer'].items.pop() + if player.currentRoom.name == room['foyer'].name: + room['foyer'].items.append(sword) + room['foyer'].items.append(shield) + + # game loop game_over = False @@ -54,28 +70,51 @@ player_move = input("\n[N] North, [E] East, [S] South, [W] West, [Q] Quit, [I] Items >> ").upper() if player_move == 'I': + if len(player.playerItem) > 0: + print(player.playerItem[0]) + if len(player.playerItem) > 1: + print(player.playerItem[0]) + print(player.playerItem[1]) + item_input = input("[Drop] or [Take] [Item] >> ").upper() if item_input == 'DROP SWORD': - print('Sword has been dropped') + player.playerItem.remove(sword) + print(f'\n{sword.itemName} has been dropped') + + if item_input == 'TAKE SWORD': + player.playerItem.append(sword) + print(f"{sword.itemName} has been picked up") + + if item_input == 'DROP SHIELD': + player.playerItem.remove(shield) + print(f'\n{shield.itemName} has been dropped') + + if item_input == 'TAKE SHIELD': + player.playerItem.append(shield) + print(f"{shield.itemName} has been picked up") if player_move == 'N' or player_move == 'E' or player_move == 'S' or player_move == 'W' or player_move == 'Q': if player_move == 'N' and player.currentRoom.n_to != None: player.currentRoom = player.currentRoom.n_to + add_items_to_foyer() print(player.currentRoom) elif player_move == 'E' and player.currentRoom.e_to != None: player.currentRoom = player.currentRoom.e_to + add_items_to_foyer() print(player.currentRoom) elif player_move == 'S' and player.currentRoom.s_to != None: player.currentRoom = player.currentRoom.s_to + add_items_to_foyer() print(player.currentRoom) elif player_move == 'W' and player.currentRoom.w_to != None: player.currentRoom = player.currentRoom.w_to + add_items_to_foyer() print(player.currentRoom) elif player_move == 'N' and player.currentRoom.n_to == None or player_move == 'E' and player.currentRoom.e_to == None or player_move == 'S' and player.currentRoom.s_to == None or player_move == 'W' and player.currentRoom.w_to == None: @@ -85,5 +124,7 @@ print("Good bye!") game_over = True - else: - print('Invalid command, please choose from the given options') + + + # else: + # print('Invalid command, please choose from the given options') diff --git a/src/item.py b/src/item.py index 9aaeaa1d30..9a0e282590 100644 --- a/src/item.py +++ b/src/item.py @@ -3,9 +3,9 @@ # Hint: the name should be one word for ease in parsing later. class Item: - def __init__(self, item, itemDes): - self.item = item + def __init__(self, itemName, itemDes): + self.itemName = itemName self.itemDes = itemDes def __str__(self): - return f"{self.item}: {self.itemDes}" \ No newline at end of file + return f"{self.itemName}: {self.itemDes}" \ No newline at end of file diff --git a/src/player.py b/src/player.py index e1e2f8cd99..53f12f14ef 100644 --- a/src/player.py +++ b/src/player.py @@ -3,9 +3,10 @@ class Player: - def __init__(self, currentRoom, playerName): + def __init__(self, currentRoom, playerName, playerItem = []): self.currentRoom = currentRoom self.playerName = playerName + self.playerItem = playerItem def __str__(self): return f"{self.playerName} is currently in room: {self.currentRoom}" \ No newline at end of file diff --git a/src/room.py b/src/room.py index 4b270113bc..daf31c70e6 100644 --- a/src/room.py +++ b/src/room.py @@ -2,15 +2,18 @@ # description attributes. class Room: - def __init__(self, name, description, n_to = None, s_to = None, e_to = None, w_to = None): + def __init__(self, name, description, n_to = None, s_to = None, e_to = None, w_to = None, items = []): self.name = name self.description = description self.n_to = n_to self.s_to = s_to self.e_to = e_to self.w_to = w_to + self.items = items def __str__(self): - return f"\nYou are currently in {self.name}.\n{self.description}" - # return f"\n{playerName} are currently in {self.name}.\n{self.description}" + if len(self.items) > 0: + return f"\nYou are currently in {self.name}.\n{self.description}\n\nYou spot some items in the distance\n\n{self.items[0]}\n{self.items[1]}" + else: + return f"\nYou are currently in {self.name}.\n{self.description}" From 943c8f62fbd6b931a035a882868043ee4c81d358 Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Thu, 14 Feb 2019 15:28:17 -0600 Subject: [PATCH 19/20] fix print error when holding multiple items --- src/adv.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/adv.py b/src/adv.py index 33d05c5cc0..eff25f7ae9 100644 --- a/src/adv.py +++ b/src/adv.py @@ -70,11 +70,8 @@ def add_items_to_foyer(): player_move = input("\n[N] North, [E] East, [S] South, [W] West, [Q] Quit, [I] Items >> ").upper() if player_move == 'I': - if len(player.playerItem) > 0: - print(player.playerItem[0]) - if len(player.playerItem) > 1: - print(player.playerItem[0]) - print(player.playerItem[1]) + + print(*player.playerItem, sep = "\n") item_input = input("[Drop] or [Take] [Item] >> ").upper() From c2291fe3ce4c041ffb7d6769293e49ca39b7c45e Mon Sep 17 00:00:00 2001 From: TRIF3X Date: Thu, 14 Feb 2019 15:30:26 -0600 Subject: [PATCH 20/20] update comments --- src/adv.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/adv.py b/src/adv.py index eff25f7ae9..e93c55ecd5 100644 --- a/src/adv.py +++ b/src/adv.py @@ -69,6 +69,8 @@ def add_items_to_foyer(): player_move = input("\n[N] North, [E] East, [S] South, [W] West, [Q] Quit, [I] Items >> ").upper() + # Inventory inputs + if player_move == 'I': print(*player.playerItem, sep = "\n") @@ -92,6 +94,8 @@ def add_items_to_foyer(): print(f"{shield.itemName} has been picked up") + # Player movement + if player_move == 'N' or player_move == 'E' or player_move == 'S' or player_move == 'W' or player_move == 'Q': if player_move == 'N' and player.currentRoom.n_to != None: