def rumble(self, myitems, inhabitant, name, profile): """ this function deals with the fight sequence of the game """ fightfinished = False while fightfinished == False: print('************* FIGHT - FIGHT - FIGHT ************') print('* YOU\tvs.\t', str.upper(name), 'the', profile) print('************************************************') numlist = list() rk = 1 print('You can use:') usedweapon = [itm[0] for itm in myitems] for usedweapon in myitems: print('\t-', rk, ')\t', usedweapon[0]) numlist.append(str(rk)) rk +=1 print('\tor simply give up the fight (g)!') fightinput = input('> what do you want to use? > ') if fightinput not in numlist: if fightinput != str.lower('g'): print('This is not an option!\n') else: print('Wise choise!\n') break else: myref = int(fightinput) - 1 weapon = myitems[myref] fightresult = inhabitant.fight(weapon, GameInfo.health, GameInfo.lives) GameInfo.health = fightresult[1] if fightresult[0] == True: if inhabitant.get_befriended() == 1: myitems.pop(myref) converted = Friend(inhabitant.name, inhabitant.description, inhabitant.conversation, ("","")) converted.set_given(1) converted.explored = 1 GameInfo.Fr_dict[str(inhabitant.name)] = converted GameInfo.En_dict.pop(inhabitant.name) inhabitant = converted GameInfo.current_room.set_character(inhabitant) print('Well done, you converted', inhabitant.name, 'into a friend\n') else: if inhabitant.get_killed() == 1: GameInfo.En_dict.pop(inhabitant.name) inhabitant = None GameInfo.current_room.set_character(None) if len(GameInfo.En_dict) == 0: GameInfo.completedgame() fightfinished = True else: if fightresult[2] == 0: exit('Thank you for playing') elif fightresult[2]!= GameInfo.lives: print('You cannot fight anymore!') GameInfo.lives = fightresult[2] fightfinished = True return myitems, inhabitant, GameInfo.health, GameInfo.lives
def createCharacters(minE,maxE,minF,maxF): #use random to create 1 to 3 enemies and friends numofEnemies = random.randint(minE, maxE) numofFriends = random.randint(minF, maxF) #create the enemy list enemiesList=[] for i in range(numofEnemies): # create a list with the enemy instances enemiesList.append(Enemy(characternames[i])) # set the descriptions for the enemies tdescription=('a ' + adjectivesBad[i] + " " + type[i]) enemiesList[i].set_description(tdescription) # want list is created in createCharacter.py enemiesList[i].set_wants(wants[i]) #create the friend list friendsList=[] for i in range(numofFriends): #we need to create an index to make sure we do not assin a want that is assigned to an enemy j = i + numofEnemies # create a list with the enemy instances friendsList.append(Friend(characternames[j])) # set the descriptions tdescription=('a '+ adjectivesGood[j] + " " + type[j]) friendsList[i].set_description(tdescription) # want list is created in createCharacter.py friendsList[i].set_wants(wants[j]) #combine the two lists characterList=friendsList+enemiesList return characterList
def charsetting(s_name, c_type, room_asgn, c_cat, c_speech, c_weakness): """ function to create character objects and assign details """ n_stg = s_name unwrap_gift = c_weakness.split('|') if c_type == 'Friend': """ the unwrap_gift will pass a 2 item list to the friend all items follow the same list pattern (see in previous function ==> hidden_item) """ stg = Friend(s_name, c_cat, c_speech, (unwrap_gift[0],unwrap_gift[1])) cls.Fr_dict[str(n_stg)] = stg cls.Ch_dict[str(n_stg)] = stg else: stg = Enemy(s_name, c_cat, c_speech, unwrap_gift) GameInfo.potentialfriends += 1 cls.En_dict[str(n_stg)] = stg cls.Ch_dict[str(n_stg)] = stg for rm, r_obj in cls.House_dict.items(): """ assign character to room """ if room_asgn == rm: r_obj.set_character(stg) r_obj.set_ch_det(cls.Ch_dict) return stg, cls.Fr_dict, cls.En_dict, cls.Ch_dict, cls.House_dict
def createFriends(numofFriends,numofEnemies): friendsList=[] for i in range(numofFriends): #we need to create an index to make sure we do not assin a want that is assigned to an enemy j = i + numofEnemies # create a list with the enemy instances friendsList.append(Friend(characternames(j))) # set the descriptions tdescription=('a '+ adjectivesGood(i) + " " + type(j)) friendsList[i].set_description(tdescription) # want list is created in createCharacter.py friendsList[i].set_wants(wants(j))
kitchen.link_room(cellar, "down") cellar.link_room(wine_cellar, "east") wine_cellar.link_room(cellar, "west") swimming_pool.link_room(ballroom, "east") ballroom.link_room(swimming_pool, "west") gym.link_room(swimming_pool, "up") swimming_pool.link_room(gym, "down") kitchen.link_room(greenhouse, "west") greenhouse.link_room(kitchen, "east") dave = Enemy("Dave", "a smelly, hungry zombie.") dave.set_conversation("Brrlgrh... rgrhl... braaains...") dave.set_weakness("brains") dining_hall.set_character(dave) catrina = Friend("Catrina", "a tall friendly skeleton.") catrina.set_conversation("Why hello there, friend!") ballroom.set_character(catrina) key = Item("key") key.set_description ("a small shiny key") cheese = Item("cheese") cheese.set_description ("a cumbling block of smelly, rotting cheese") broken_glass = Item("broken glass") broken_glass.set_description ("several broken bottles' worth of broken glass") weight = Item("weight") weight.set_description ("a ten pound iron weight")
tennis = Item("tennis") tennis.set_description("A furry greeinsh round thing") dining_hall.set_item(tennis) dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("I eat your brains") dave.set_weakness("cheese") dining_hall.set_character(dave) baxter = Enemy("Baxter", "A rabid wild dog beast") baxter.set_conversation("Woof Woof") baxter.set_weakness("tennis") kitchen.set_character(baxter) claire = Friend("Claire", "A sexy ghost who loves you") claire.set_conversation("Come and give me a great big hug") claire.set_strength("bff") ballroom.set_character(claire) dead = False current_room = kitchen current_item = sword while not dead and Enemy.enemies_defeated <= 1: print("\n") # Print out the room details current_room.get_details() # Print out the item/s in the room current_item.get_details() inhabitant = current_room.get_character()
from room import Room from item import Item from helpMe import HelpMe from character import Enemy from character import Friend myhelp = HelpMe() myhelp.helpMe() dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("I am a a zomilator") dave.set_weakness("cheese") mary = Friend("Mary", "A nice person") mary.set_conversation("I like hugs") #dave.set_weakness("cheese") # create rooms kitchen = Room("Kitchen") kitchen.set_description("A dank and dirty room buzzing with flies.") kitchen.set_character(mary) dining_hall = Room("Dining Hall") dining_hall.set_description( "A large room with ornate golden decorations on each wall.") #put an enemy in the room dining_hall.set_character(dave) ballroom = Room("Ballroom") ballroom.set_description( "A vast room with a shiny wooden floor. Huge candlesticks guard the entrance."
borris.set_weakness("brain") kitchen.set_character(borris) # Add item(s) to room brain = Item("brain") brain.set_description("A wet and wriggling brain. Looks like zombie food.") dining_hall.set_item(brain) quartz = Item("quartz") quartz.set_description("A huge crystal ball! It is full of inclusions and very dazzling.") kitchen.set_item(quartz) # Add a new character catrina = Friend("Catrina", "A happily lost treasure-hunter with a fondness for quartz.") catrina.set_conversation("'Hello, there! I am looking for a large quartz crystal. Have you seen it?'") catrina.set_item_give("quartz") ballroom.set_character(catrina) #puts catrina in the ballroom ##### CURRENT ROOM ##### current_room = parlor backpack = [] #empty, as you find items, they will go in backpack dead = False while dead == False: print("\n") current_room.get_details()
# link the rooms kitchen.link_room(dining_hall, "south") ballroom.link_room(dining_hall, "east") dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "west") # set characters dave = Enemy("Dave", "A smelly zombie!") dave.set_conversation("Ahhh...I will eat you!") dave.set_weakness("cheese") susi = Character("Susi", "A cute little puppy") susi.set_conversation("Wuff, wuff!") ricky = Friend("Ricky", "A lovely penguin") ricky.set_conversation("Hello!") # put characters into rooms dining_hall.set_character(dave) ballroom.set_character(susi) kitchen.set_character(ricky) current_room = kitchen # items cheese = Item("cheese") old_sward = Item("old Sward") shield = Item("Shield") wand = Item("wand") book = Item("Book")
# link rooms kitchen.link_room(dining_hall, "south") dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "west") ballroom.link_room(dining_hall, "east") # set Enemy dave = Enemy("Dave", "A smelly zombie") # initialize enemy dave.describe() dave.set_conversation("Brrlgrh... rgrhl... brains...") # set auto-response dave.set_weakness("cheese") dave.talk() # trigger conversation dining_hall.set_character(dave) # place enemy # set Friend catrina = Friend("Catrina", "A friendly skeleton") # initialize Friend catrina.describe() catrina.set_conversation("Why hello there...") # set auto-response catrina.talk() # trigger conversation ballroom.set_character(catrina) # place friend # player location current_room = kitchen dead = False while dead == False: print("\n") current_room.get_details() inhabitant = current_room.get_character() if inhabitant is not None:
dinning_hall.link_room(ballroom, "west") ballroom.link_room(dinning_hall, "east") # Create characters and assing them to rooms # Chicho chicho = Enemy("Chicho", "Un apestoso zombi") chicho.set_conversation("Eres lo peor que nos ha pasado nunca") chicho.set_weakness("Chocos") dinning_hall.set_character(chicho) chicho.set_items(["lobos", "dragones", "mandriles"]) # Catrina catrina = Friend("Catrina", "Una amistosa esqueleto") catrina.set_conversation("¿Hay alguien ahí?") ballroom.set_character(catrina) # Create items and assign it to rooms # Chocos chocos = Item() chocos.set_name("Chocos") chocos.set_description("Cefalópodos recién pescados") ballroom.set_item(chocos) # Comienza el bucle de la partida current_room = kitchen #mochila = []
kitchen.set_description("A dank and dirty room buzzing with flies.") dining_hall = Room("Dining Hall") dining_hall.set_description("A grand room with a table") ballroom = Room("Ballroom") ballroom.set_description("A large room with room to dance") kitchen.link_room(dining_hall, "south") dining_hall.link_room(kitchen, "north") ballroom.link_room(dining_hall, "east") dining_hall.link_room(ballroom, "west") current_room = kitchen banker = Friend("Banker", "A Friendy Bank Manager - Well this is a fanasty!!!!") banker.set_conversation("Its going to cosh you!!") banker.set_cash(500) kitchen.set_character(banker) dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("Brrlgrh... rgrhl... brains...") dave.set_weakness("cheese") dining_hall.set_character(dave) mark = Enemy("Mark", "A greedy Goblin") mark.set_conversation("Give me all your money") mark.set_weakness("dagger") mark.set_bribe(50) ballroom.set_character(mark)
# Items time_machine = Item("Time Machine") time_machine.set_description( "It's a small metallic intricate cube, with a rotating ball nestled in it." ) time_machine.set_power("teleport") # Items in rooms ballroom.set_item(time_machine) # Characters jeff = Enemy("Jeff", "A bare knock fighter") jeff.set_conversation("I'll blow you down like smoke!") jeff.set_weakness("melon") catrina = Friend("Catrina", "A friendly skeleton") catrina.set_conversation("I'm all bones.") # Characters in rooms dining_hall.set_character(jeff) kitchen.set_character(catrina) # No repetitions new_room = True new_inhabitant = True new_gadget = True # Starting elements current_room = kitchen backpack = [] dead = False
bunker.set_item(nuclearbomb) bunker.link_room(kitchen, "South") kitchen.link_room(bunker, "North") dining_hall = Room("Dining Hall") dining_hall.set_description( "A large room with ornate golden decorations on each wall.") dining_hall.link_room(kitchen, "North") kitchen.link_room(dining_hall, "South") ballroom = Room("Ballroom") ballroom.set_description("A place where people dance at parties") ballroom.link_room(dining_hall, "East") dining_hall.link_room(ballroom, "West") jon = Friend("Jon", "An old pal. ") jon.set_conversation("Sah dude") ##dining_hall.get_details() ##print() ##kitchen.get_details() current_room = kitchen dave = Enemy("Dave", "A smelly zombie.") ##dave.describe() ##dave.talk() dave.set_conversation("bruh bruh bruh bruh bruh") ##dave.talk() ## dave.set_worth(5) dave.set_weakness("cheese") ##print("What will you fight with?")
damage=100) key1 = Item('Key 1', 'The 1st key! now to find the lock...', 'key', room=office) key2 = Item('Key 2', 'The 2nd key! now to find the lock...', 'key', room=vault) key3 = Item('Key 3', 'The 3rd key! now to find the lock...', 'key', room=secret) newton = Friend('Issac Newton', 'The famous guy', 'Whats the value of g on earth?', '9.8', newtonsflaminglasersword) # Now for all the enemies... somerandomguy = Friend( 'Some Random Guy', 'Just someone in your house i guess. At least they are friendly', 'What goes up but never comes down?', 'age', key3) octopus = Enemy('Octopus', 'PUT OCTOPUS DESCRIPTION HERE', 10, 10, health) guard = Enemy('Guard', 'Someone has to look after the office!', 100, 20, sword) guyintheoffice = Enemy('Guy in the Office', 'just someone in the office apparently', 10, 1, key1)
dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "west") ballroom.link_room(dining_hall, "east") dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("What's up, dude! I'm hungry.") dave.set_weakness("cheese") dining_hall.set_character(dave) tabitha = Enemy("Tabitha", "An enormous spider with countless eyes and furry legs.") tabitha.set_conversation("Sssss....I'm so bored...") tabitha.set_weakness("book") ballroom.set_character(tabitha) jane = Friend("Jane", "A pretty girl") jane.set_conversation("Hi there, give us a hug") lobby.set_character(jane) cheese = Item("cheese") cheese.set_description("A large and smelly block of cheese") ballroom.set_item(cheese) book = Item("book") book.set_description("A really good book entitled 'Knitting for dummies'") dining_hall.set_item(book) current_room = deck backpack = [] dead = False
"A large room with ornate golden decorations on each wall") ballroom = Room("Ballroom") ballroom.set_description("A vast room with a shiny floor.") kitchen.link_room(dining_hall, "south") dining_hall.link_room(kitchen, "north") ballroom.link_room(dining_hall, "east") dining_hall.link_room(ballroom, "west") dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("Braiiiinnnnns") dave.set_weakness("cheese") laura = Friend( "Laura", "Laura creates and maintains Raspberry Pi educational resources. Aside from computers, she loves cats, cakes, board games and making jam." ) laura.set_conversation("Sorry, did you somehow put me inside your game?") laura.favorites = [ "computer", "computers", "cats", "cat", "cake", "cakes", "board game", "board games" ] cheese = Item("cheese") cheese.set_description("This is a wedge of cheese.") roland = Enemy("Roland", "An evil cat.") roland.set_weakness("tuna") tuna = Item("tuna")
dining_hall.get_character() cheese = Item("cheese") cheese.set_description("A food that Dave the Zombie hates!") dining_hall.set_item(cheese) akashi = Enemy("Akashi", "The monster") akashi.set_conversation("Yeet") akashi.set_bribe("True") akashi.set_weakness("call mama phone") kitchen.set_character(akashi) call_mama_phone = Item("call mama phone") call_mama_phone.set_description("A phone that calls Akashi's mom.") kitchen.set_item(call_mama_phone) sunny = Friend("Sunny", "A nice friend who likes to dance!") sunny.set_conversation("Do you want to dance?") ballroom.set_character(sunny) #*Start in the kitchen current_room = kitchen defeat_enemy_count = 0 #*Store items in backpack backpack = [] loop = True while loop: print("\n") current_room.get_details() #*Check whether there are characters in the room. inhabitant = current_room.get_character()
# Enemies dave = Enemy('Dave', 'A smelly grumpy zombie') dave.set_conversation('Brrlgrh... rgrhl... brains...') dave.set_weakness('cheese') jack = Enemy('Jack', 'An enormous fierce rat') jack.set_conversation('And a fine day it is') jack.set_weakness('book') jill = Enemy('Jill', 'A nasty troll') jill.set_conversation('How much will you pay me to cross the bridge?') jill.set_weakness('duster') # Friends connie = Friend('Connie', 'A friendly skelton') connie.set_conversation('How are you today?') connie.set_hint('Dave doesn\'t like cheese.') jim = Friend('Jim', 'A friendly gardiner') jim.set_conversation('I hope it doens\'t rain inside again today') jim.set_hint('Jack doesn\'t like books') oscar = Friend('Oscar', 'A friendly little white dog with a very waggy tail') oscar.set_conversation('Where''s my treat human') oscar.set_hint('I''ll guard the treat cupboard for you') # Neutral gaylord = Nuetral('Gaylord', 'A Bored Shop keeper') gaylord.set_conversation('I don\'t have many things to sell, can you bring me some more items for my shop')
"A large room with ornate golden decorations on every wall") ballroom = Room("Ballroom") ballroom.set_description("A vast room with shiny decorations") kitchen.link_room(dining_hall, "south") dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "west") ballroom.link_room(dining_hall, "east") dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("Brrlgrh... rgrhl... brains...") dave.set_weakness("cheese") dining_hall.set_character(dave) catrina = Friend("Catrina", "A friendly skeleton") catrina.set_conversation("Why hello there.") ballroom.set_character(catrina) candle = Item("Candle") candle.set_description("A candle to see your way through dark passages") kitchen.set_item(candle) current_room = kitchen backpack = [] dead = False while dead == False: print("\n")
# introduce a character, Dave in the Dining Hall dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("That'll be your brain that I'm after") dave.set_weakness("elephant") dave.set_awake(True) dining_hall.set_character(dave) # add another enemy, Eben, in the Ballroom eben = Enemy("Eben", "An angry giant with a deep voice") eben.set_conversation("I run a large computer company") eben.set_weakness("artichoke") eben.set_awake(False) ballroom.set_character(eben) # add a friend, kate in the kitchen greta = Friend("Greta", "An environmental warrior") greta.set_conversation("Stop flying, it's madness and terrible") greta.set_awake(False) kitchen.set_character(greta) # distribute items sword = Item("sword", "it's pointy at one end") kitchen.set_item(sword) elephant = Item("elephant", "surprisingly small, grey and with a trunk") dining_hall.set_item(elephant) artichoke = Item("artichoke", "it's green and spikey") ballroom.set_item(artichoke) # main game initialisation
kitchen.set_description("A dank and dirty room buzzing with flies.") dining_hall = Room("Dining Hall") dining_hall.set_description("A large room with ornate decorations.") ballroom = Room("Ballroom") ballroom.set_description("A vast room with a shiny wooden floor.") # Add an enemy and it's weakness to defeat it dave = Enemy("Dave","A bad, very smelly Zombie") dave.set_weakness("cheese") # Add some conversation for Dave when talked to dave.set_conversation("Argh, me eat your brains!") # Add a friend and it's feelings kati = Friend("Kati","A friendly skeleton") kati.set_feelings("I'm very happy today!") # Add some conversation for Kati when talked to kati.set_conversation("Do you need a hug today?") # Add an item cheese = Item("Cheese") cheese.set_description("A large and smelly block of cheese") kitchen.link_room(dining_hall, "south") dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "west") ballroom.link_room(dining_hall, "east") # Add characters to rooms dining_hall.set_character(dave)
def game_start(): fname = "rooms.txt" fh = open(fname) spooky_castle = RPGInfo("The Spooky Castle") spooky_castle.welcome() RPGInfo.info() RPGInfo.author = "Santiago Fernández de la Torre" for line in fh: if line.startswith("Kitchen:"): pieces = line.split(":") kitchen_description = pieces[1].strip() if line.startswith("Ballroom"): pieces = line.split(":") ballroom_description = pieces[1].strip() if line.startswith("Dining Hall"): pieces = line.split(":") dininghall_description = pieces[1].strip() backpack = Inventory() kitchen = Room("Kitchen") kitchen.set_description(kitchen_description) ballroom = Room("Ballroom") ballroom.set_description(ballroom_description) dining_hall = Room("Dining hall") dining_hall.set_description(dininghall_description) #print("There are " + str(Room.number_of_rooms) + " rooms to explore.") kitchen.link_room(dining_hall, "south") dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "east") ballroom.link_room(dining_hall, "west") dave = Enemy("Dave", "A smelly zombie!\n") dave.set_conversation("BrAiNs!\n") dave.set_weakness("cheese") eustace = Enemy("Eustace", "A very angry buttler") eustace.set_conversation("Justicia social!") eustace.set_weakness(None) eustace.set_interest("gold coin") morgan = Friend("Morgan Freeman", "You just met GOD") morgan.set_conversation("Hello, my child.") cheese = Item("cheese") cheese.description = "A piece of moldy cheese" cheese.itype = "Consumable" cheese.quantity = 1 kitchen.set_item(cheese) gold = Item("gold coin") gold.description = "A gold coin from ancient times" gold.itype = "Consumable" gold.quantity = 1 dining_hall.set_item(gold) # sword = Item("sword") # sword.description = "An old rusty sword" # sword.itype="Usable" # sword.quantity = 1 # dining_hall.set_item(sword) key = Item("key") key.description = "A key used to get out of the spooky castle" key.itype = "Usable" key.quantity = 1 key.durability = 1 ballroom.set_item(key) fists = Item("fists") fists.description = "Who needs weapons when you have these cannons?" fists.itype = "Usable" fists.quantity = 999 fists.durability = 999 backpack.set_inventory(fists) kitchen.set_character(morgan) dining_hall.set_character(dave) ballroom.set_character(eustace) current_room = kitchen return current_room, fists, key, kitchen, dining_hall, ballroom, gold, morgan, eustace, dave, backpack, spooky_castle
"A vast room with a shiny wooden floor; huge candlesticks guard the entrance" ) print("There are " + str(Room.number_of_rooms) + " rooms to explore") kitchen.link_room(dining_hall, "south") dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "west") ballroom.link_room(dining_hall, "east") dave = Enemy("Dave", "A smelly zombie!") dave.set_conversation("Brrlgrh... rgrhl... brains...") dave.set_weakness("cheese") dining_hall.set_character(dave) catrina = Friend("Catrina", "A friendly skeleton") catrina.set_conversation("Hello, there!") ballroom.set_character(catrina) cheese = Item("cheese") cheese.set_description("A large and smelly block of cheese") ballroom.set_item(cheese) book = Item("book") book.set_description("A really good book entitled 'Knitting for dummies'") dining_hall.set_item(book) current_room = kitchen backpack = [] dead = False
def __init__(self, config=None): """Create a game world using the supplied configuration details. If no config specified, then use default_config world configuration. The game world has: title, rooms, characters, items, messages, and the success criteria. """ # use default_config is none supplied if config == None: config = default_config # instance variables for a world self.title = config['title'] self.rooms = {} self.items = {} self.characters = {} self.player = None self.messages = config['messages'] self.success = config['success'] # populate the world using the configuration details try: # configure rooms doing = "rooms" # room config has: (name, description, key_item, used_msg)* keyitems = [] # list of key items to config later for conf in config['rooms']: self.rooms[conf[0]] = Room(conf[0], conf[1]) if conf[3] != None: # key items to be set when have items keyitems.append( (conf[0], conf[2], conf[3])) # (room, item, msg) # configure links between rooms doing = "links" # links config has: (room1, direction1, room2, direction2)* for conf in config['links']: self.rooms[conf[0]].link_room(self.rooms[conf[2]], conf[1], conf[3]) # configure items doing = "items" # items config has: (name, description, location) player_items = [] # list of player items to config later for conf in config['items']: self.items[conf[0]] = Item(conf[0], conf[1]) if conf[2] in self.rooms: # place item in room self.rooms[conf[2]].leave(self.items[conf[0]]) else: # item on character to add later player_items.append((conf[0], conf[2])) # now configure key_items in rooms - has (room, item, msg) doing = "key_items" for conf in keyitems: self.rooms[conf[0]].set_key_item(self.items[conf[1]], conf[2]) # configure characters (enemies, friends, player) doing = "enemies" # links config has: (name, description, conversation, location, weakness, defeat_msg)* for conf in config['enemies']: self.characters[conf[0]] = Enemy(conf[0], conf[1]) self.characters[conf[0]].set_conversation(conf[2]) self.characters[conf[0]].move_to(self.rooms[conf[3]]) if conf[4] != None: self.characters[conf[0]].set_weakness( self.items[conf[4]], conf[5]) doing = "friends" # friends config has: (name, description, conversation, location, desire, thank_msg)* for conf in config['friends']: self.characters[conf[0]] = Friend(conf[0], conf[1]) self.characters[conf[0]].set_conversation(conf[2]) self.characters[conf[0]].move_to(self.rooms[conf[3]]) if conf[4] != None: self.characters[conf[0]].set_desires( self.items[conf[4]], conf[5]) doing = "players" # players config has: (name, description, location)* num_players = 0 for conf in config['players']: self.characters[conf[0]] = Player(conf[0], conf[1]) self.characters[conf[0]].move_to(self.rooms[conf[2]]) self.player = self.characters[conf[0]] num_players += 1 if num_players != 1: print("You can only have 1 player character in the game!") # now configure player_items on characters - has (item, character) doing = "player_items" for conf in player_items: self.characters[conf[1]].add(self.items[conf[0]]) except (IndexError, KeyError, ValueError) as msg: print("### Error: Incorrect format or values in " + doing + " config: " + str(conf)) print(str(msg)) raise
dining_hall.set_description( "Dark, cold and full of cobwebs and rat-like sounds") dining_hall.link_room(kitchen, "north") dining_hall.link_room(ballroom, "west") garden.set_description("A tangled semi-jungle of prickly thorns") garden.link_room(kitchen, "east") garden.link_room(ballroom, "south") dave = Enemy("Dave", "a slimy, stinky zombie") dining_hall.set_character(dave) dave.set_conversation("Hey Dude - listen to an old zombie!") dave.set_weakness("cheese") dave.add_name_to_set() duncan = Friend("Duncan", "a shifty-looking elf") duncan.set_conversation("Ugh, can't I have some peace.") garden.set_character(duncan) duncan.will_fight = False duncan.will_hug = False duncan.will_bribe = True duncan.gift = "magnifying glass" duncan.add_name_to_set() aurora = Friend("Aurora", "a powerful, magical fairy") aurora.set_conversation("Sparkly, sparkle.") ballroom.set_character(aurora) aurora.will_fight = True aurora.will_hug = True aurora.will_bribe = False aurora.gift = "sapphire"
ballroom.link_room(dining_hall, 'west') # creating the first enemy and putting him in the dining hall enemy = Enemy('Drake', 'A sweetie zumbie') enemy.conversation = 'braaain, I want braaaain' enemy.weakness = 'cheese' dining_hall.character = enemy # creating the second enemy and putting him in the ballroom enemy_two = Enemy('David', 'A dangerous demon') enemy_two.conversation = 'I want to take your soul' enemy_two.weakness = 'silver' ballroom.character = enemy_two # creating a friendly person and putting in the kitchen friend = Friend('jacob', 'A very friendly guy') friend.conversation = 'I\'m just passing a time here' kitchen.character = friend knife = Item('knife', 'to kill people') kitchen.item = knife current_room = kitchen # creating the walk form starting in the kitchen while True: print('\n') print(f'There are {Room.number_of_rooms} rooms to explorer') if current_room.character is not None: inhabitant = current_room.character if current_room.item is not None: hashere = current_room.item
cheese = Item("cheese") cheese.set_description("A block of yellow mouldy cheese") key = Item("key") key.set_description("Your way to freedom") # Assign items to rooms kitchen.set_item(cheese) dining_room.set_item(gun) # Create characters dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("I am here to eat your brains") dave.set_weakness("cheese") catrina = Friend("Catrina", "A friendly skeleton") catrina.set_conversation("I am here to guide you") # Assign characters to rooms dining_room.set_character(dave) # Function to reassign an item to a room during game def change_item(item): if item == 'gun': current_room.set_item(gun) elif item == 'cheese': current_room.set_item(cheese) elif item == 'dagger': current_room.set_item(dagger) elif item == 'key':
cuisine.set_item(fromage) livre = Item("livre") livre.set_readable_name("un livre") livre.set_description("Un très gros livre intitulé \"Python pour les nuls\".") salon.set_item(livre) # Define the people dave = Enemy("Dave", "Un zombie puant") dave.set_conversation("Arrrgggg... yahhhhh... manger...") dave.set_weakness("fromage") salon.set_character(dave) olga = Friend("Olga", "Un squelette sympa") olga.set_conversation("Salut ! Je suis un tas d'os.") cuisine.set_character(olga) tabatha = Enemy("Tabatha", "Une énorme araignée aux pattes velues.") tabatha.set_conversation("Pfffff.... Je m'ennuie...") tabatha.set_weakness("livre") salle_a_manger.set_character(tabatha) #Start: current_room = cuisine backpack = [] dead = False
) kitchen.link_room(dining_hall, "s") dining_hall.link_room(kitchen, "n") dining_hall.link_room(ballroom, "w") ballroom.link_room(dining_hall, "e") vlad = Enemy("Vlad", "A scary vampire") vlad.set_conversation("I'm always looking for my necks victim!") vlad.set_weakness("stake") dave = Enemy("Dave", "A smelly zombie") dave.set_conversation("Brrlgrh... Rgrhl... Braaaaains!") dave.set_weakness("bat") catrina = Friend("Catrina", "A friendly skeleton") catrina.set_conversation("Konnichiwa!") kitchen.set_character(vlad) dining_hall.set_character(dave) ballroom.set_character(catrina) bat = Item("bat", "A solid looking cricket bat") stake = Item("stake", "A wooden stake, sharpened at one end") ballroom.set_item(bat) dining_hall.set_item(stake) current_room = kitchen inventory = [] game_over = False