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
48 changes: 45 additions & 3 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from room import Room

from player import Player
from item import Item
# Declare all the rooms

room = {
Expand Down Expand Up @@ -35,12 +36,53 @@

#
# Main
#

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

#room holding item
r = Item('A Rock')
room['outside'].items.append(r)
p = Player(room['outside'])
print(f'{p.cur_r}\n{p.cur_r.desc}\n{r.name}')
# Write a loop that:
#
while True:
move = input('Your move: ')
if move == 'e':
if p.cur_r.e_to is None:
print('nope')
else:
p.cur_r = p.cur_r.e_to
print(p.cur_r)
elif move == 'w':
if p.cur_r.w_to is None:
print('nope')
else:
p.cur_r = p.cur_r.w_to
print(p.cur_r)
elif move == 's':
if p.cur_r.s_to is None:
print('nope')
else:
p.cur_r = p.cur_r.s_to
print(p.cur_r)
elif move == 'n':
if p.cur_r.n_to is None:
print('nope')
else:
p.cur_r = p.cur_r.n_to
print(p.cur_r)
elif move == 'q':
break
elif move == 'i':
p.inv()
elif move == 'l':
p.look()
else:
print('enter your move in this format: e,w,n,s,q')



# * 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.
Expand Down
6 changes: 6 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Item():
def __init__(self, name):
self.name = name

def __str__(self):
print(self.name)
20 changes: 20 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player():
def __init__(self, sta_r):
self.cur_r = sta_r
self.bag = []

def inv(self):
if len(self.bag)>0:
for item in self.bag:
if item is None:
pass
else:
print(item)
else:
print('nothing in your bag')

def look(self):
if len(self.cur_r.items)>0:
for item in self.cur_r.items:
print(item)

20 changes: 19 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
class Room():
def __init__(self, name, desc, n_to=None, s_to=None, w_to=None, e_to=None):
self.name = name
self.desc = desc
self.n_to = n_to
self.s_to = s_to
self.e_to = e_to
self.w_to = w_to
self.items = []

def __str__(self):
des = f'{self.name}, {self.desc}'
return des