Skip to content

Second attempt #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
70 changes: 60 additions & 10 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 All @@ -24,7 +25,7 @@

# Link rooms together

room['outside'].n_to = room['foyer']
room['foyer'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
Expand All @@ -37,15 +38,64 @@
# Main
#

print('\n\n======================================================')
print(' Welcome to Adventure Game:')
print('======================================================\n')

# Make a new player object that is currently in the 'outside' room.
player = Player(input('Enter a name: '), room['foyer'])
player.current_room = player.current_room.s_to
print('Your are in the ', player.current_room.name)
print('Description: ', player.current_room.description)

def wichWay():
global direction
print('------------------------------------------')
direction = input('Choose a compass direction: \n N = North, S = South, E = East, or W = West \n')
wichWay()

# Write a loop that:
#
# * 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.
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

while True:
if direction == 'n':
if player.current_room.n_to is not None:
player.current_room = player.current_room.n_to
print('Description: ', player.current_room.description)
wichWay()
else:
print('Can not go North from here')
wichWay()

if direction == 's':
if player.current_room.s_to is not None:
player.current_room = player.current_room.s_to
print('Your are in the ', player.current_room.name)
print('Description: ', player.current_room.description)
wichWay()
else:
print('Can not go to South from here')
wichWay()
if direction == 'e':
if player.current_room.e_to is not None:
player.current_room = player.current_room.e_to
print('You are in the ', player.current_room.name)
print('Description: ', player.current_room.description)
wichWay()
else:
print('Can not go Easth from here')
wichWay()
if player.current_room.w_to is not None:
player.current_room = player.current_room.w_to
print('You are in the ', player.current_room.name)
print('Description: ', player.current_room.description)
wichWay()
else:
print('Can not go West frm here')
wichWay()
if direction == 'q':
print('Good bye')
break

else:
print('Wrong Entry')
wichWay()
15 changes: 15 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Item:
def __init__(self, name, description):
self.name = name
self.description = description

def __str__(self):
return f'{self.name} {self.description}'

def on_take(self, item):
print(f"You have picked up {item}.")

def on_drop(self, item):
print(f"You have dropped {item}.")

print(Item('Gu', '2amo').on_drop('Gun'))
15 changes: 15 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player:
def __init__(self, name, current_room):
self.name = name
self.current_room = current_room
self.list = []

def __str__(self):
return f'{self.name} {self.current_room} {self.list}'

def addItem(self, item):
self.list.append(item)

def removeItem(self, item):
self.list.remove(item)

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


def addItem(self, item):
return self.list.append(item)

def removeItem(self, item):
print(f'Items in: ' ,{self.list})
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
l = ['Hamid', 'Amin', 'Elham']

for e in l:
print('Your Name is: ',e)