diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..48b8ab902b 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,4 +1,7 @@ from room import Room +from player import Player +import time + # Declare all the rooms @@ -49,3 +52,42 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. +directions={ + 'w': 'north', + 's': 'south', + 'a': 'west', + 'd': 'east' +} + + +def start_game(): + name=input('Enter your name here: ') + player_1=Player(name,room['outside']) + print(f''' + Welcome to Treasure Hunting,{name}! + Press w,s,d,a,q to go north,south,east,west or to q to quit''') + time.sleep(1) + while True: + cmd=input(f''' + You\'re in {player_1.location.name}. + {player_1.location.description}\n ''') + if cmd in directions: + if (player_1.location.n_to==None and cmd=='w' or + player_1.location.s_to==None and cmd=='s' or + player_1.location.w_to==None and cmd=='a' or + player_1.location.e_to==None and cmd=='d'): + print (f'Sorry! You can\'t go {directions[cmd]} from here') + time.sleep(1) + continue + else: + player_1.change_location(cmd) + continue + elif cmd == 'q': + print('Thank you for playing. Goodbye!!') + quit() + else: + print('Please enter a valid direction') + continue + +start_game() + diff --git a/src/player.py b/src/player.py index d79a175029..16895cb8ab 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,30 @@ # Write a class to hold player information, e.g. what room they are in # currently. + + + +class Player: + def __init__(self,name,location): + self.name=name + self.location=location + def change_location(self,direction): + if direction =='w': + self.location=self.location.n_to + elif direction=='s': + self.location=self.location.s_to + elif direction=='a': + self.location=self.location.w_to + elif direction =='d': + self.location=self.location.e_to + + # location=['outside','foyer','narrow'] + # for place in location: + # if self.location == place: + # if self.location=='outside': + # print('Outside yall') + # elif self.location=='foyer': + # self.location='overlook' + # elif self.location=='narrow': + # self.location='treasure' + # else: + # pass \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..e479e9eb41 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,19 @@ # 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,n_to=None,s_to=None,w_to=None,e_to=None,direction=None): + 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 + self.direction=direction + + + + + + + +