Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Adventure Game Code - Main File
- ########## Adventure Game - Training for Jaimie Summers ##########
- from room import Room
- from item import Item
- from food import Food
- from character import Enemy, Character, Friend
- #########Players Back Pack - A list to store items in ###################
- backpack = ["fists"]
- command_list = ["north", "east", "south", "west", "talk", "fight", "hug", "take", "eat"]
- ###### Setting numbers of lives
- lives = 2
- enemies_beaten = 0
- ##Food = None
- ############ Setting up the rooms ##########
- #Main Room
- mainroom = Room ("Intro")
- mainroom.set_description("Welcome to the 'Adventure Game'. In this adventure you must defeat the enemies and save 'Summers Mansion'. You are equipped only with your fists and have 2 lives, what can you do to save the Mansion? \nRead the clues and type commands to play the game. \n Type options to find out what choices you have \nTo start the game go south!")
- #Room 1 - The Kitchen
- kitchen = Room("Kitchen")
- kitchen.set_description("""A dank and dirty room buzzing with flies, there is a sink full of washing up, dirty clothes infront of the washing machine and a kitchen table in the centre of the room. The kitchen table has a newspaper, dirty coffee mug and the remains of someones breakfast.""")
- #Room 2 - The Dining Room
- dining_hall = Room("Dining Room")
- dining_hall.set_description("""A large room with ornate golden decorations on each wall. There is a large dining table with 10 chairs, golden cutlery and white plates are set for each dinner guest. There is a painting of a elderly woman on the wall.""")
- #Room 3 - The Ball Room
- ball_room = Room ("Ball Room")
- ball_room.set_description("""A vast room with a huge chandelier. To the south of the room are large doors each decorated with red velvet floor length curtains. There is a grand piano to the east of the room.""")
- #Room 4 - Cupboard 1
- cupboard_kitchen = Room("Kitchen Cupboard")
- cupboard_kitchen.set_description("""A small cupboard full of food, there is a whiff of stale and rotten food""")
- ########### All rooms need to be linked ##########
- #Linking the rooms
- mainroom.link_room(kitchen, "south")
- kitchen.link_room(dining_hall, "south")
- kitchen.link_room(cupboard_kitchen, "east")
- cupboard_kitchen.link_room(kitchen, "west")
- dining_hall.link_room(kitchen, "north")
- dining_hall.link_room(ball_room, "west")
- ball_room.link_room(dining_hall, "east")
- ######### Putting enemy's and characters into the rooms ##########
- #Dave an Enemy in the Dining Room
- dave = Enemy("Dave", "A smelly zombie")
- dave.set_conversation("What's up, dude!")
- dave.set_weakness("cheese")
- dining_hall.set_character(dave)
- #Catrina the friendly skeletan in the Ball Room ##########
- catrina = Friend("Catrina", "A friendly skeleton")
- catrina.set_conversation("Why hello there.")
- ball_room.set_character(catrina)
- ##### Food items in rooms #####
- crisps = Food ("Crisps")
- crisps.set_description("A half eaten bag of crisps, there is enough to gain some energy")
- cupboard_kitchen.set_food(crisps)
- ##### Items in rooms #####
- cheese = Item ("Cheese")
- cheese.set_description ("A large block of smelly cheese")
- ball_room.set_item(cheese)
- sword = Item ("Sword")
- sword.set_description ("A blunt sword!")
- kitchen.set_item(sword)
- ##Current room to start the game##
- current_room = mainroom
- ########## Dead means GAME OVER ##########
- dead = False
- ########### Game loop ##########
- while dead == False:
- print("\n")
- current_room.get_details()
- inhabitant = current_room.get_character()
- if inhabitant is not None:
- inhabitant.describe()
- item = current_room.get_item()
- if item is not None:
- item.describe()
- food = current_room.get_food()
- if food is not None:
- food.describe()
- command = input("Type your command here > ")
- ################################ Call commands
- if command == "options":
- print ("You can type the following options...")
- print (command_list)
- ################################ MOVE
- if command in ["north", "south", "east", "west"]:
- # Move in the given direction
- current_room = current_room.move(command)
- ################################# TALK
- elif command == "talk":
- # Talk to the inhabitant - check whether there is one!
- if inhabitant is not None:
- inhabitant.talk()
- ################################## FIGHT
- elif command == "fight":
- # Check whether an object is an instance of a particular
- if inhabitant == None or isinstance(inhabitant, Friend):
- print("There is no one here to fight with")
- else:
- print("What will you fight with?")
- fight_with = input("Choose your weapon! >")
- print(backpack)
- if fight_with in backpack:
- if inhabitant.fight(fight_with) == True:
- enemies_beaten = enemies_beaten + 1
- print ("You have beeaten " + str(enemies_beaten) + " enemies!")
- print("Hooray, you won the fight!")
- if enemies_beaten == 1:
- print ("You have been successful in saving Summers Mansion!!! Well done!")
- dead = True
- else:
- print ("Continue finding the enemies to save Summers Mansion!")
- dead = False
- current_room.set_character(None)
- else:
- lives = lives - 1
- if lives == 0:
- print("That's the end of the game")
- dead = True
- else:
- print("Oh dear, you lost the fight. You now have " + str(lives))
- else:
- print("Try again! You don't have a " + fight_with)
- #################################### HUG
- elif command == "hug":
- if inhabitant == None:
- print("There is no one here to hug :(")
- else:
- if isinstance(inhabitant, Enemy):
- print("I wouldn't do that if I were you...")
- else:
- inhabitant.hug()
- #################################### TAKE
- elif command == "take":
- if item == None:
- print ("There is nothing to collect here")
- else:
- print ("You have collected an item")
- backpack.append(item.get_name().lower())
- current_room.set_item(None)
- print (backpack)
- #################################### EAT
- elif command == "eat":
- if food == None:
- print ("There is nothing to eat here!")
- else:
- print ("You have eaten...and now have")
- lives = lives + 1
- current_room.set_food(None)
- Food = None
- print ("You now have " + str(lives) + " lives")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement