From f20022fb50324bc9387cf5443bf594c50727c480 Mon Sep 17 00:00:00 2001 From: Andrew S Lowe Date: Thu, 7 May 2020 12:36:43 -0400 Subject: [PATCH] finished first half of adv game --- 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..e8c76a0d8a 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") + \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..bf35041cce 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") \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..c9930c8d62 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}" \ No newline at end of file