From f2c9b0abbfbaa904cf8a49d6464e98008a11f211 Mon Sep 17 00:00:00 2001 From: artbrgn <54554129+artbrgn@users.noreply.github.com> Date: Thu, 10 Sep 2020 22:55:06 -0500 Subject: [PATCH 1/4] retry --- src/adv.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/player.py | 11 +++++++++++ src/room.py | 14 +++++++++++++- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..a78002821f 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,5 @@ from room import Room +from player import Players # Declare all the rooms @@ -33,11 +34,16 @@ room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] -# + + + +# # # Main # # Make a new player object that is currently in the 'outside' room. +player = Players(input('Player name:'), room['outside']) +print(f"Hello {player.name}") # Write a loop that: # @@ -49,3 +55,40 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + +# LOOP +# READ +# EVAL +# PRINT + +while True: + print(player.current_room.name) + print() + print(player.current_room.description) + cmd = input("\n~~> ") + if cmd == "q": + print('Goodbye!') + exit(0) + elif cmd == 'n': + if player.current_room.n_to is not None: + player.current_room = player.current_room.n_to + else: + print("you cannot move in that direction") + elif cmd == 's': + if player.current_room.s_to is not None: + player.current_room = player.current_room.s_to + else: + print("you cannot move in that direction") + elif cmd == 'e': + if player.current_room.e_to is not None: + player.current_room = player.current_room.e_to + else: + print("you cannot move in that direction") + elif cmd == 'w': + if player.current_room.w_to is not None: + player.current_room = player.current_room.w_to + else: + print("you cannot move in that direction") + else: + print("I did not understand the command") + diff --git a/src/player.py b/src/player.py index d79a175029..a27fd16418 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,13 @@ # Write a class to hold player information, e.g. what room they are in # currently. + +class Players: + def __init__(self, name, starting_room): + self.name = name + self.current_room = starting_room + + def travel(self, direction): + if player.current_room.n_to is not None: + player.current_room = player.current_room.n_to + else: + print("you cannot move in that direction") diff --git a/src/room.py b/src/room.py index 24c07ad4c8..dcf0e56da8 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,14 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. + +class Room: + def __init__(self, name, description): + self.name = name + self.description = description + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + + def __str__(self): + return f"{self.name}". From 02f0746dd6a3f1e57454f1b65767bfdc4dc974be Mon Sep 17 00:00:00 2001 From: artbrgn <54554129+artbrgn@users.noreply.github.com> Date: Thu, 10 Sep 2020 23:00:12 -0500 Subject: [PATCH 2/4] fixed error statemnt --- src/adv.py | 13 ++++++++----- src/player.py | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/adv.py b/src/adv.py index a78002821f..88a36130f6 100644 --- a/src/adv.py +++ b/src/adv.py @@ -73,22 +73,25 @@ if player.current_room.n_to is not None: player.current_room = player.current_room.n_to else: - print("you cannot move in that direction") + print("----you cannot move in that direction----") + print() elif cmd == 's': if player.current_room.s_to is not None: player.current_room = player.current_room.s_to else: - print("you cannot move in that direction") + print("----you cannot move in that direction----") + print() elif cmd == 'e': if player.current_room.e_to is not None: player.current_room = player.current_room.e_to else: - print("you cannot move in that direction") + print("----you cannot move in that direction----") + print() elif cmd == 'w': if player.current_room.w_to is not None: player.current_room = player.current_room.w_to else: - print("you cannot move in that direction") + print("----you cannot move in that direction----") + print() else: print("I did not understand the command") - diff --git a/src/player.py b/src/player.py index a27fd16418..7c2e508c99 100644 --- a/src/player.py +++ b/src/player.py @@ -10,4 +10,5 @@ def travel(self, direction): if player.current_room.n_to is not None: player.current_room = player.current_room.n_to else: - print("you cannot move in that direction") + print("----you cannot move in that direction----") + print() From 4e0541d7589a1942954f0f97bea8991a23d46a54 Mon Sep 17 00:00:00 2001 From: artbrgn <54554129+artbrgn@users.noreply.github.com> Date: Thu, 10 Sep 2020 23:01:01 -0500 Subject: [PATCH 3/4] retry --- src/adv.py | 1 + src/player.py | 1 + src/room.py | 1 + 3 files changed, 3 insertions(+) diff --git a/src/adv.py b/src/adv.py index 88a36130f6..22fd0bd88b 100644 --- a/src/adv.py +++ b/src/adv.py @@ -25,6 +25,7 @@ # Link rooms together + room['outside'].n_to = room['foyer'] room['foyer'].s_to = room['outside'] room['foyer'].n_to = room['overlook'] diff --git a/src/player.py b/src/player.py index 7c2e508c99..2df46f6aed 100644 --- a/src/player.py +++ b/src/player.py @@ -1,6 +1,7 @@ # Write a class to hold player information, e.g. what room they are in # currently. + class Players: def __init__(self, name, starting_room): self.name = name diff --git a/src/room.py b/src/room.py index dcf0e56da8..047581d90e 100644 --- a/src/room.py +++ b/src/room.py @@ -1,6 +1,7 @@ # Implement a class to hold room information. This should have name and # description attributes. + class Room: def __init__(self, name, description): self.name = name From 9628ba3cfef2aa541ad442a9908d5dce9b8880db Mon Sep 17 00:00:00 2001 From: artbrgn <54554129+artbrgn@users.noreply.github.com> Date: Thu, 10 Sep 2020 23:04:11 -0500 Subject: [PATCH 4/4] fixed error in room file --- src/room.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/room.py b/src/room.py index 047581d90e..0123f075ab 100644 --- a/src/room.py +++ b/src/room.py @@ -12,4 +12,4 @@ def __init__(self, name, description): self.w_to = None def __str__(self): - return f"{self.name}". + return f"{self.name}"