From da55d2a599e710cc8528f5ac242b43eacafe8a73 Mon Sep 17 00:00:00 2001 From: Khoa Tran Date: Mon, 6 Jul 2020 10:29:22 -0500 Subject: [PATCH 1/2] finish basic functionality, will work on cleaning up the code and refactor --- src/adv.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/player.py | 8 ++++++++ src/room.py | 9 ++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..1c0096d8ac 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 @@ -49,3 +50,55 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + + + + + + 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 quit respectively') + while True: + cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description} ') + if cmd == 'w': + player_1.location=room['outside'].n_to + while True: + cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description} ') + if cmd == 'w': + player_1.location=room['foyer'].n_to + while True: + cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description}') + if cmd == 's': + player_1.location=room['overlook'].s_to + break + elif cmd == 'q': + quit() + elif cmd == 's': + player_1.location=room['foyer'].s_to + break + elif cmd == 'd': + player_1.location=room['foyer'].e_to + while True: + cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description}') + if cmd == 'a': + player_1.location=room['narrow'].w_to + break + elif cmd == 'w': + player_1.location=room['narrow'].n_to + while True: + cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description} ') + if cmd == 's': + player_1.location=room['treasure'].s_to + break + elif cmd == 'q': + quit() + elif cmd == 'q': + quit() + elif cmd == 'q': + quit() + elif cmd == 'q': + break + +start_game() + diff --git a/src/player.py b/src/player.py index d79a175029..45bea9b524 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,10 @@ # 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 + + + + \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..80a13023a0 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,9 @@ # 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): + self.name=name + self.description=description + + + From 97569a6dcf4ab8e8d7aac11dd5ea109dc49c43fe Mon Sep 17 00:00:00 2001 From: Khoa Tran Date: Mon, 13 Jul 2020 12:47:25 -0500 Subject: [PATCH 2/2] finish day1 MVP --- src/adv.py | 75 ++++++++++++++++++++++----------------------------- src/player.py | 28 ++++++++++++++++--- src/room.py | 12 ++++++++- 3 files changed, 67 insertions(+), 48 deletions(-) diff --git a/src/adv.py b/src/adv.py index 1c0096d8ac..48b8ab902b 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,7 @@ from room import Room from player import Player +import time + # Declare all the rooms @@ -50,55 +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(): +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 quit respectively') + 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} ') - if cmd == 'w': - player_1.location=room['outside'].n_to - while True: - cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description} ') - if cmd == 'w': - player_1.location=room['foyer'].n_to - while True: - cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description}') - if cmd == 's': - player_1.location=room['overlook'].s_to - break - elif cmd == 'q': - quit() - elif cmd == 's': - player_1.location=room['foyer'].s_to - break - elif cmd == 'd': - player_1.location=room['foyer'].e_to - while True: - cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description}') - if cmd == 'a': - player_1.location=room['narrow'].w_to - break - elif cmd == 'w': - player_1.location=room['narrow'].n_to - while True: - cmd=input(f'You\'re in {player_1.location.name}.{player_1.location.description} ') - if cmd == 's': - player_1.location=room['treasure'].s_to - break - elif cmd == 'q': - quit() - elif cmd == 'q': - quit() - elif cmd == 'q': - quit() + 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': - break + 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 45bea9b524..16895cb8ab 100644 --- a/src/player.py +++ b/src/player.py @@ -1,10 +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 - - - - \ No newline at end of file + 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 80a13023a0..e479e9eb41 100644 --- a/src/room.py +++ b/src/room.py @@ -1,9 +1,19 @@ # Implement a class to hold room information. This should have name and # description attributes. class Room: - def __init__(self,name,description): + 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 + + + + +