From 9f77f3143abb37649d73859726e31e333b9fe1b9 Mon Sep 17 00:00:00 2001 From: Daniel Gipson Date: Thu, 10 Sep 2020 15:47:49 -0400 Subject: [PATCH 1/2] completed mvp --- src/adv.py | 27 +++++++++++++++++++++++++++ src/player.py | 4 ++++ src/room.py | 14 +++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..b2c1fb347e 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 @@ -38,6 +39,7 @@ # # Make a new player object that is currently in the 'outside' room. +player1 = Player(room['outside']) # Write a loop that: # @@ -49,3 +51,28 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + +playing = None +menu = input(f'Welcome to Darkest Dungeons! To play press p to quit press q\n') +if menu == 'q': + print('Thanks For Playing!') + playing = False +elif menu == 'p': + print('\nPress n, s, e, w to go in any of the cardinal directions available in each room!') + playing = True +while playing: + direction = input(f'\n{player1.currentRoom}choose a direction!\n') + + if direction == 'n' and player1.currentRoom.n_to != None: + player1.currentRoom = player1.currentRoom.n_to + elif direction == 's' and player1.currentRoom.s_to != None: + player1.currentRoom = player1.currentRoom.s_to + elif direction == 'e' and player1.currentRoom.e_to != None: + player1.currentRoom = player1.currentRoom.e_to + elif direction == 'w' and player1.currentRoom.w_to != None: + player1.currentRoom = player1.currentRoom.w_to + elif direction == 'q': + print('\nThanks For Playing') + playing = False + else: + print('\nPlease choose a valid direction!') \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..1b0ed17e2f 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,6 @@ # Write a class to hold player information, e.g. what room they are in # currently. +class Player: + def __init__(self, currentRoom): + self.currentRoom = currentRoom + self.inventory = [] \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..884a388b32 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,14 @@ # 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 + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + + def __str__(self): + return f'Location: {self.name} \n{self.description}\n' From 0c1bc6345c2ca0ecb2a213344e1a8823c435821e Mon Sep 17 00:00:00 2001 From: Daniel Gipson Date: Thu, 10 Sep 2020 23:37:31 -0400 Subject: [PATCH 2/2] completed mvp --- src/adv.py | 61 ++++++++++++++++++++++++++++++++++++++++++++------ src/item.py | 11 +++++++++ src/player.py | 25 ++++++++++++++++++++- src/room.py | 3 +++ src/secret.py | 8 +++++++ src/writing.py | 10 +++++++++ 6 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 src/item.py create mode 100644 src/secret.py create mode 100644 src/writing.py diff --git a/src/adv.py b/src/adv.py index b2c1fb347e..96838e43be 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,5 +1,8 @@ from room import Room from player import Player +from item import Item +from secret import Secret +from writing import Writing # Declare all the rooms @@ -20,6 +23,10 @@ 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by earlier adventurers. The only exit is to the south."""), + + 'hollow': Room("Secret Hollow", """A few dozen feet down the cliff you come upon + a hollow space in the face of the cliff. As the wind howls you see sitting on + an ancient altar is a solid gold monkey idol with diamond eyes""") } @@ -30,9 +37,30 @@ room['foyer'].n_to = room['overlook'] room['foyer'].e_to = room['narrow'] room['overlook'].s_to = room['foyer'] +room['overlook'].c_to = room['hollow'] room['narrow'].w_to = room['foyer'] room['narrow'].n_to = room['treasure'] room['treasure'].s_to = room['narrow'] +room['hollow'].c_to = room['overlook'] + +# Create items +sword = Secret('Sword', 3, 12) +diamond = Item('Diamond', 30) +wand = Secret('Wand', 30, 45) +shield = Item('Shield', 4) +note = Writing('Note', 0, '"Check out the Cliff to \ndiscover a secret treasure"') +idol = Item('Solid gold idol', 500) + + +# Add items to rooms +room['foyer'].secrets.append(sword) +room['narrow'].secrets.append(wand) +room['narrow'].items.append(shield) +room['overlook'].items.append(diamond) +room['treasure'].items.append(note) + +# Add secrets to rooms + # # Main @@ -58,21 +86,40 @@ print('Thanks For Playing!') playing = False elif menu == 'p': - print('\nPress n, s, e, w to go in any of the cardinal directions available in each room!') + print('\nEnter n, s, e, w to go in any of the cardinal directions available in each room!\nTo investigate a room enter i') playing = True while playing: - direction = input(f'\n{player1.currentRoom}choose a direction!\n') + action = input(f'\n{player1.currentRoom}choose a direction or investigate!\n') - if direction == 'n' and player1.currentRoom.n_to != None: + if action == 'n' and player1.currentRoom.n_to != None: player1.currentRoom = player1.currentRoom.n_to - elif direction == 's' and player1.currentRoom.s_to != None: + + elif action == 's' and player1.currentRoom.s_to != None: player1.currentRoom = player1.currentRoom.s_to - elif direction == 'e' and player1.currentRoom.e_to != None: + + elif action == 'e' and player1.currentRoom.e_to != None: player1.currentRoom = player1.currentRoom.e_to - elif direction == 'w' and player1.currentRoom.w_to != None: + + elif action == 'w' and player1.currentRoom.w_to != None: player1.currentRoom = player1.currentRoom.w_to - elif direction == 'q': + + elif action == 'c' and player1.currentRoom.c_to != None: + player1.currentRoom = player1.currentRoom.c_to + + elif action == 'i': + player1.investigate() + + elif action == 'p': + item = input('Enter item\'s name ') + for thing in player1.currentRoom.items: + if item == thing.name and thing.hidden == False: + player1.get(item) + else: + print(f'There is no {item} to pick up') + + elif action == 'q': print('\nThanks For Playing') playing = False + else: print('\nPlease choose a valid direction!') \ No newline at end of file diff --git a/src/item.py b/src/item.py new file mode 100644 index 0000000000..f00a6ab8d1 --- /dev/null +++ b/src/item.py @@ -0,0 +1,11 @@ +class Item: + def __init__(self, name, value): + self.name = name + self.value = value + self.hidden = False + + def __str__(self): + return f'\nname: {self.name} \nvalue: {self.value}' + + def makeSecret(self): + self.hidden = True \ No newline at end of file diff --git a/src/player.py b/src/player.py index 1b0ed17e2f..4fe1568c0c 100644 --- a/src/player.py +++ b/src/player.py @@ -1,6 +1,29 @@ # Write a class to hold player information, e.g. what room they are in # currently. +import random + class Player: def __init__(self, currentRoom): self.currentRoom = currentRoom - self.inventory = [] \ No newline at end of file + self.inventory = [] + + def get(self, item): + if len(self.inventory) < 4 and item.hidden == False: + self.inventory.append(item) + self.currentRoom.items.remove(item) + print(f'Picked up {item.name}') + elif item.hidden == False: + print(f'There is no {item}') + elif self.inventory >= 4: + print(f'Can\'t pick up {item.name}, inventory full') + + def drop(self, item): + self.inventory.remove(item) + + def investigate(self): + search = random.randint(0, 100) + + for secret in self.currentRoom.secrets: + if secret.difficulty <= search: + secret.hidden = False + print(f'Found: \n{secret} \nTo pick up enter "{secret.name}"') \ No newline at end of file diff --git a/src/room.py b/src/room.py index 884a388b32..17a37f7c60 100644 --- a/src/room.py +++ b/src/room.py @@ -5,10 +5,13 @@ class Room: def __init__(self, name, description): self.name = name self.description = description + self.items = [] + self.secrets = [] self.n_to = None self.s_to = None self.e_to = None self.w_to = None + self.c_to = None def __str__(self): return f'Location: {self.name} \n{self.description}\n' diff --git a/src/secret.py b/src/secret.py new file mode 100644 index 0000000000..692a9c2878 --- /dev/null +++ b/src/secret.py @@ -0,0 +1,8 @@ +from item import Item + +class Secret(Item): + def __init__(self, name, value, difficulty): + self.name = name + self.value = value + self.hidden = True + self.difficulty = difficulty \ No newline at end of file diff --git a/src/writing.py b/src/writing.py new file mode 100644 index 0000000000..b0bff230d5 --- /dev/null +++ b/src/writing.py @@ -0,0 +1,10 @@ +from item import Item + +class Writing(Item): + def __init__(self, name, value, text): + super().__init__(name, value) + self.text = text + self.hidden = False + + def read(self): + print(self.text) \ No newline at end of file