Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from room import Room
from player import Player

# Declare all the rooms

Expand Down Expand Up @@ -39,6 +40,8 @@

# Make a new player object that is currently in the 'outside' room.

newPlayer = Player('Louis', room['outside'])

# Write a loop that:
#
# * Prints the current room name
Expand All @@ -49,3 +52,20 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
playerInput = ''
while str(playerInput) != 'q':
print(newPlayer.__str__())
playerInput = input(
"Where do you want to move next? Enter 'n, e, s, w' to move, or enter 'q' to quit. ")
try:
if str(playerInput) == 'n':
newPlayer.room = newPlayer.room .n_to
elif str(playerInput) == 'e':
newPlayer.room = newPlayer.room .e_to
elif str(playerInput) == 's':
newPlayer.room = newPlayer.room .s_to
elif str(playerInput) == 'w':
newPlayer.room = newPlayer.room .w_to
except:
print("You cannot go this way!")
print("You have exited the game")
10 changes: 10 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@

# Write a class to hold player information, e.g. what room they are in
# currently.


class Player:
def __init__(self, name, room):
self.name = name
self.room = room

def __str__(self):
return f"{self.name}, you are at {self.room.name} now. \n{self.room.description}"
9 changes: 8 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
class Room:
def __init__ (self, name, description):
self.name = name
self.description = description

def __str__(self):
return f"This is {self.name}, and {self.description}"