diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..b21942e5b7 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,5 @@ from room import Room +from player import Player # Declare all the rooms @@ -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'] @@ -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() \ No newline at end of file diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..13fe1770ec --- /dev/null +++ b/src/item.py @@ -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')) \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..cf09406c1d 100644 --- a/src/player.py +++ b/src/player.py @@ -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) + diff --git a/src/room.py b/src/room.py index 24c07ad4c8..fd3b4989df 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,18 @@ # 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, 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}) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000000..22419fb0f6 --- /dev/null +++ b/test.py @@ -0,0 +1,4 @@ +l = ['Hamid', 'Amin', 'Elham'] + +for e in l: + print('Your Name is: ',e) \ No newline at end of file