def welcome_msg(hero): ''' A msg to welcome to user to the game and displaying the game info :return: none ''' spooky_castle = RPGInfo("The Spooky Castle") spooky_castle.char = hero spooky_castle.welcome() RPGInfo.info()
from room import Room from character import Friend, Enemy from rpginfo import RPGInfo from item import Item from time import sleep from os import system RPGInfo.welcome() RPGInfo.info() sleep(2) bakpack = ['silver', 'cheese'] # add kitchen object in the game kitchen = Room('Kitchen') kitchen.description = 'The place that people cook food' # add ballroom object in the game ballroom = Room('Ball Room') ballroom.description = 'The place that people go to dance' # add dining hall object in the game dining_hall = Room('Dining Hall') dining_hall.description = 'The place that people eat them food' # link the kitchen to the ballrom and dining hall kitchen.link_room(ballroom, 'southwest') kitchen.link_room(dining_hall, 'south') # link the dining to the ballrom and kitchen dining_hall.link_room(kitchen, 'north')
from room import Room from character import Enemy, Friend from rpginfo import RPGInfo from item import Item spooky_castle = RPGInfo("The Spooky Castle") spooky_castle.welcome() RPGInfo.info() RPGInfo.author = "Raspberry Pi Foundation" kitchen = Room("Kitchen") 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 golden decorations on each wall.") ballroom = Room("Ballroom") ballroom.set_description( "A vast room with a shiny wooden floor. Huge candlesticks guard the entrance." ) bedroom = Room("Bedroom") bedroom.set_description( "A cozy but spooky place to rest with skeletons on the bed") 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")
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
from room import Room from item import Item from character import Enemy from character import Friend from rpginfo import RPGInfo #*Game name spooky_castle = RPGInfo("Spooky Castle") spooky_castle.welcome() RPGInfo.info() RPGInfo.author = "Suguru" RPGInfo.show_author() kitchen = Room("kitchen") #*Somehow the properties aren't working but I guess that is ok kitchen.set_description("A place where you cook.") #*Note that since the attributes are public, I can change them without using a method ''' kitchen.description = "Changed" print(kitchen.description) ''' ballroom = Room("ballroom") ballroom.set_description("A place where you dance.") dining_hall = Room("dining hall") dining_hall.set_description("A place where you eat.") kitchen.link_room(dining_hall, "south")
def win_check(): if not bed_room.character: print("Congratulation you win") RPGInfo.credits() quit()
def game_over(character): if character.health <= 0: print("You died\nGame OVer.") RPGInfo.credits() exit(0)
print("\n") for element in backpack.inventory: if element.name == fight_with: weapon = element current_room.character.fight(fight_with) break if weapon == None: print("You don't have this weapon...") continue if fight_with == current_room.character.weakness: backpack.use_item(weapon) if current_room.character.status == "Dead": current_room.set_character(None) else: print("Game Over...") RPGInfo.credits() sys.exit() elif command == "hug": if current_room.character is None: print("There is no one here...") if current_room.character.forf == "Enemy": print("You shouldn't hug enemies...\n\nGame Over.") RPGInfo.credits() sys.exit() elif current_room.character.forf == "Friend": current_room.character.hug() elif command == "bribe": bargain = None if current_room.character is None:
cheese.size = 2 garlic = Item("garlic") garlic.description = "A plait of fat garlic bulbs" garlic.size = 3 dining_hall.set_character(dave) ballroom.set_character(brad) kitchen.set_character(mildred) conservatory.set_character(frank) dining_hall.set_item(key) kitchen.set_item(garlic) conservatory.set_item(cheese) mystery_manor = RPGInfo("The Mystery Manor") mystery_manor.welcome() current_room = kitchen backpack = [] backpack_capacity = 10 backpack_contents = 0 enemies_defeated = 0 dead = False #main game loop while dead == False: #print("\n") current_room.get_details() inhabitant = current_room.get_character() roomitem = current_room.get_item()