Using Python3
Adventure_Scaffold/simulation.py
from room import Room from item import Item from adventurer import Adventurer from quest import Quest import sys def read_paths(source): """Returns a list of lists according to the specifications in a config file, (source). source contains path specifications of the form: origin > direction > destination. read_paths() interprets each line as a list with three elements, containing exactly those attributes. Each list is then added to a larger list, `paths`, which is returned.""" # TODO return None def create_rooms(paths): """Receives a list of paths and returns a list of rooms based on those paths. Each room will be generated in the order that they are found.""" # make variables which temporarily store name of room # and also stores the direction of next room and # the name of the next room name_of_room_list = [] direction_list = [] destination_list = [] name_of_room = "" direction = "" destination = "" pathfile = open(paths ,"r") # if len(pathfile)==0: # print("No rooms exist! Exiting program...") while True: temp = pathfile.readline() if temp == "": break result = [x.strip() for x in temp.split('>')] name_of_room = result[0] direction = result[1] destination = result[2] direction_list.append(direction) destination_list.append(destination) if (len(name_of_room_list) == 0): name_of_room = Room(name_of_room) name_of_room.set_path(direction,destination) name_of_room_list.append(name_of_room) count = 0 for i in range(len(name_of_room_list)): if name_of_room_list[i] != name_of_room: count +=1 if count == len(name_of_room_list): name_of_room = Room(name_of_room) name_of_room.set_path(direction,destination) name_of_room_list.append(name_of_room) return name_of_room_list return None def generate_items(source): """Returns a list of items according to the specifications in a config file, (source). source contains item specifications of the form: item name | shortname | skill bonus | will bonus """ # TODO return None def generate_quests(source, items, rooms): """Returns a list of quests according to the specifications in a config file, (source). source contains quest specifications of the form: reward | action | quest description | before_text | after_text | quest requirements | failure message | success message | quest location """ # TODO return None if len(sys.argv) < 4: print("Usage: python3 simulation.py <paths> <items> <quests>") sys.exit() try: file_path = sys.argv[1] file_item = open(sys.argv[2],"r") file_quest = open(sys.argv[3],"r") create_rooms(file_path) ## code here # file_path.flush() # file_path.close() file_item.flush() file_item.close() file_quest.flush() file_quest.close() except FileNotFoundError: print("Please specify a valid configuration file.") sys.exit() adv = Adventurer() room = create_rooms(file_path)[0] room.draw() print("") while True : commands = input(">>> ").upper() if commands == "QUIT": print("Bye!") sys.exit(0) elif commands == "HELP" : print("HELP - Shows some available commands.") print("LOOK or L - Lets you see the map/room again.") print("QUESTS - Lists all your active and completed quests.") print("INV - Lists all the items in your inventory.") print("CHECK - Lets you see an item (or yourself) in more detail.") print("NORTH or N - Moves you to the north.") print("SOUTH or S - Moves you to the south.") print("EAST or E - Moves you to the east.") print("WEST or W - Moves you to the west.") print("QUIT - Ends the adventure.") print("") elif commands == "LOOK" or commands == "L": print("") elif commands == "QUESTS": print("") elif commands == "INV": print("You are carrying:") adv.check_self() elif commands == "CHECK": item_string = input("Check what?") elif commands == "NORTH" or commands == "N": room = room.move(commands) elif commands == "SOUTH" or commands == "S": room = room.move(commands) elif commands == "EAST" or commands == "E": room = room.move(commands) elif commands == "WEST" or commands == "W": room = room.move(commands) else: print("You can't do that.") print("") # TODO: Retrieve info from CONFIG files. Use this information to make Adventurer, Item, Quest, and Room objects. # TODO: Receive commands from standard input and act appropriately.
__MACOSX/Adventure_Scaffold/._simulation.py
Adventure_Scaffold/adventurer.py
class Adventurer: def __init__(self): # initialize the inventory as an empty list self.inventory = [] def get_inv(self): return self.inventory def get_skill(self): """TODO: Returns the adventurer's skill level. Whether this value is generated before or after item bonuses are applied is your decision to make.""" ... def get_will(self): """TODO: Returns the adventurer's will power. Whether this value is generated before or after item bonuses are applied is your decision to make.""" ... def take(self, item): self.get_inv().append(item) def check_self(self): """TODO: Shows adventurer stats and all item stats.""" # print("You are an adventurer, with a SKILL of 5 and a WILL of 5") if len(self.inventory) == 0: print("Nothing.") print("") ...
__MACOSX/Adventure_Scaffold/._adventurer.py
Adventure_Scaffold/.DS_Store
__MACOSX/Adventure_Scaffold/._.DS_Store
Adventure_Scaffold/items.txt
Singing Sword | SWORD | 10 | 0 Shimmering Shield | SHIELD | 5 | 2 Trembling Tome | TOME | 3 | 12 Glistening Goblet | GOBLET | 2 | 5
__MACOSX/Adventure_Scaffold/._items.txt
Adventure_Scaffold/paths.txt
Entrance > NORTH > Foyer Foyer > NORTH > Courtyard Foyer > EAST > Parlour Foyer > SOUTH > Entrance Foyer > WEST > Workshop Courtyard > SOUTH > Foyer Parlour > WEST > Foyer Workshop > EAST > Foyer
__MACOSX/Adventure_Scaffold/._paths.txt
Adventure_Scaffold/tests/00_item.txt
__MACOSX/Adventure_Scaffold/tests/._00_item.txt
Adventure_Scaffold/tests/00_quest.txt
__MACOSX/Adventure_Scaffold/tests/._00_quest.txt
Adventure_Scaffold/tests/00_input.txt
LOOK CRY N S QUESTS
__MACOSX/Adventure_Scaffold/tests/._00_input.txt
Adventure_Scaffold/tests/00_expected.txt
+---------NN---------+ | | | | | | | | | | | | | | | | | | +--------------------+ You are standing at the Garden. There is nothing in this room. >>> +---------NN---------+ | | | | | | | | | | | | | | | | | | +--------------------+ You are standing at the Garden. There is nothing in this room. >>> You can't do that. >>> You move to the north, arriving at the Plaza. +--------------------+ | | | | | | | | | | | | | | | | | | +--------------------+ You are standing at the Plaza. There is nothing in this room. >>> You can't go that way. >>> === All quests complete! Congratulations! ===
__MACOSX/Adventure_Scaffold/tests/._00_expected.txt
Adventure_Scaffold/tests/README.txt
00 - No quests, room with no exits.
__MACOSX/Adventure_Scaffold/tests/._README.txt
Adventure_Scaffold/tests/00_path.txt
Garden > NORTH > Plaza
__MACOSX/Adventure_Scaffold/tests/._00_path.txt
__MACOSX/Adventure_Scaffold/._tests
Adventure_Scaffold/quests.txt
Singing Sword | PULL SWORD | PULL the sword from the stone. | A beautiful silver sword has been wedged deep into a stone pedestal here. | A stone pedestal lies in the centre of the room, devoid of swords. | SKILL 10 | You struggle to pull the sword from the stone, but despite your best efforts, it doesn't budge. | You heave against the stone and pull the sword free from its grasp. You hear the sharp hum of the blade as it moves through the air - a job well-accomplished. | Courtyard Shimmering Shield | SHINE SHIELD | SHINE an old shield until it shimmers. | An old, battered shield rests against the wall here. | There is nothing of note here. | SKILL 3 | You shine and buff the shield as much as you can, but you cannot seem to return it to its former glory. | The shield shines and shimmers like a mirror made of steel. You decide to take it with you. | Foyer Trembling Tome | CALM TOME | CALM a trembling tome in the workshop. | A voluminous tome trembles violently in its bookshelf, threatening to bring the whole thing down on itself. | All is calm in this room. A battered, but well-stocked bookshelf keeps things together along the western wall. | WILL 5 | You reach forth to try calming the book, but the bookshelf just trembles harder! Did that book just snap at you with... teeth? | You reach out and stroke along the spine of the Trembling Tome. You hear the sound of ruffling pages, and the shuddering stops, allowing you to check out the book with no problems. | Workshop Glistening Goblet | STEAL GOBLET | STEAL a glistening goblet from a distracted denizen. | A couple of fat cats are here, playing cards. They stop from time to time to drink from the glistening, ruby-encrusted goblets beside them, to varying degrees of success. | A couple of fat cats are here, engrossed in a game of cards. | SKILL 12 | You reach for the goblet, but one of the cats notices you and swats your hand away, hissing. | You distract one of the cats for a good while, just petting it. The fur is really soft, and they purr receptively to your touch - which is just as well, because that gives you the time to steal a Glistening Goblet from right under their noses. | Parlour
__MACOSX/Adventure_Scaffold/._quests.txt
Adventure_Scaffold/quest.py
class Quest: def __init__(self, reward, action, desc, before, after, req, fail_msg, pass_msg, room): """TODO: Initialises a quest.""" ... def get_info(self): """TODO: Returns the quest's description.""" ... def is_complete(self): """TODO: Returns whether or not the quest is complete.""" def get_action(self): """TODO: Returns a command that the user can input to attempt the quest.""" ... def get_room_desc(self): """TODO: Returns a description for the room that the quest is currently in. Note that this is different depending on whether or not the quest has been completed.""" ... def attempt(self, player): """TODO: Allows the player to attempt this quest. Check the cumulative skill or will power of the player and all their items. If this value is larger than the required skill or will threshold for this quest's completion, they succeed and are rewarded with an item (the room's description will also change because of this). Otherwise, nothing happens.""" ...
__MACOSX/Adventure_Scaffold/._quest.py
Adventure_Scaffold/item.py
class Item: def __init__(self, name, short, skill_bonus, will_bonus): """TODO: Initialises an item.""" ... def get_name(self): """TODO: Returns an item's name.""" ... def get_short(self): """TODO: Returns an item's short name.""" ... def get_info(self): """TODO: Prints information about the item.""" ... def get_skill(self): """TODO: Returns the item's skill bonus.""" ... def get_will(self): """TODO: Returns the item's will bonus.""" ...
__MACOSX/Adventure_Scaffold/._item.py
Adventure_Scaffold/room.py
class Room: def __init__(self, name): self.name = name self.North = False self.n_room = "" self.South = False self.s_room = "" self.East = False self.e_room = "" self.West = False self.w_room = "" def get_name(self): return def get_short_desc(self): file_quest = open('quest.txt','r') read_quest = [file_quest.readline().strip("|")] if read_quest == "": return "There is nothing in this room." else: return read_quest[1] def get_quest_action(self): """TODO: If a quest can be completed in this room, returns a command that the user can input to attempt the quest.""" def set_quest(self, q): """TODO: Sets a new quest for this room.""" def get_quest(self): """TODO: Returns a Quest object that can be completed in this room.""" def set_path(self, dir, dest): """TODO: Creates an path leading from this room to another.""" if dir == "NORTH": self.North = True self.n_room = dest return self.North and self.n_room elif dir == "SOUTH": self.South = True self.s_room = dest return self.South and self.s_room elif dir == "EAST": self.East = True self.e_room = dest return self.East and self.e_room elif dir == "WEST": self.West = True self.w_room = dest return self.West and self.w_room def draw(self): if self.North == True: print("") print("+---------NN---------+") print("| |") print("| |") print("| |") print("| |") else: print("") print("+--------------------+") print("| |") print("| |") print("| |") print("| |") if self.East == True and self.West == True: print("W E") elif self.East == True and self.West == False: print("| E") elif self.West == True and self.East == False: print("W |") else: print("| |") if self.South == True: print("| |") print("| |") print("| |") print("| |") print("+---------SS---------+") else: print("| |") print("| |") print("| |") print("| |") print("+--------------------+") get_name = "You are standing at the {}.".format(self.name) print(get_name) self.get_name() print("There is nothing in this room.") def move(self, dir): """TODO: Returns an adjoining Room object based on a direction given. (i.e. if dir == "NORTH", returns a Room object in the north).""" if dir == "N": dir == "NORTH" elif dir == "S": dir == "SOUTH" elif dir == "E": dir == "EAST" elif dir == "W": dir == "WEST" if dir == "NORTH": if self.North == True: dest = self.n_room else: print("You can\'t go that way") return self if dir == "SOUTH": if self.South == True: dest = self.s_room else: print("You can\'t go that way") return self if dir == "EAST": if self.East == True: dest = self.e_room else: print("You can\'t go that way") return self if dir == "WEST": if self.West == True: dest = self.w_room else: print("You can\'t go that way") return self print("You move to the {}, arriving at the {}.".format(dir.lower(),dest.name)) dest.name() return dest ...