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
5 changes: 5 additions & 0 deletions category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Category:
def __init__(self, name): #product
self.name = name
def __str__(self):
return "No products available in " + self.name
36 changes: 36 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 @@ -36,6 +37,8 @@
#
# Main
#
is_playing = True
player = Player(room['outside'])

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

Expand All @@ -49,3 +52,36 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

while is_playing:
print(f'\n Current location: {player.room.name}')
print(player.room.description, "\n")
direction = input('Which way would you like to go? \n`n` for North, `s` for South, `e` for East, and `w` for West. or `q` to quit \n Enter Selection here: ')

try:
if direction == 'n':
player.room = player.room.n_to
except:
print(wrongWay)

try:
if direction == 'e':
player.room = player.room.e_to
except:
print("Can't go that way!")

try:
if direction == 's':
player.room = player.room.s_to
except:
print("Can't go that way!")

try:
if direction == 'w':
player.room = player.room.w_to
except:
print("Can't go that way!")

if direction == 'q':
print("\n\Game Over!")
is_playing = False
4 changes: 4 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Write a class to hold player information, e.g. what room they are in
# currently.

class Player:
def __init__(self, room):
self.room = room
11 changes: 10 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# 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
# self.n_to = n_to
# self.s_to = s_to
# self.e_to = e_to
# self.w_to = w_to
31 changes: 31 additions & 0 deletions start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from category import Category

class Store:
def __init__(self, name, categories):
self.name = name
self.categories = categories

def __str__(self):
output = f"{self.name}" + "\n"
for i , c in enumerate(self.categories):
output += " " + str(i+1) + ". " + c + "\n"
return output

my_store = Store("Aaron's Store", ["food", "beverage", "clothing"])
print(my_store)

selection = 0
while selection != len(my_store.categories)+1:
selection = input("Select the number of a department")
try:
#move casting to int into the try block
selection = int(selection)
if selection == len(my_store.categories)+1:
print("thanks for shopping.")
elif selection > 0 and selection <= len(my_store.categories):
print(my_store.categories[selection - 1])
else:
print("please select a valid number.")
except ValueError:
print("Please enter your choice as a number.")
# print("The user selected "+ str(selection) )