Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from room import Room
- from item import Item
- from rpginfo import RPGInfo
- from character import Character, Enemy, Animal
- # game settings
- game_name = "Adventure around the house"
- RPGInfo.author = "Raspberry Pi Foundation and Me"
- # setup rooms
- kitchen = Room("kitchen")
- kitchen.description= "a dank and dirty room buzzing with flies"
- ballroom = Room("ballroom")
- ballroom.description = "a large clean room with a sparkling floor"
- dining_hall = Room("dining hall")
- dining_hall.description = "a dimly lit room with scraps of food surrounding a table"
- office = Room("office")
- office.description = "a small room with bright LED lighting, looks a nice place to work"
- # setup items
- table = Item("table")
- table.set_description("round and has places for four people")
- table.set_mass("heavy")
- table.set_material("metal")
- sword = Item("sword", "light", "wood")
- sword.set_description("long and pointy with a small handle, it has lots of small holes in it")
- cheese = Item("cheese", "light", "cheese")
- cheese.set_description("Smelly, a little bit gooey")
- metal_key = Item("metal key", "heavy", "iron")
- metal_key.set_description("large rusty old key, seems a little bent")
- plastic_key = Item("flimsy key", "light", "plastic")
- plastic_key.set_description("a 3D printed key, red in colour. You can see the layer lines")
- #setup room maze
- kitchen.link_room(dining_hall, "south")
- ballroom.link_room(dining_hall, "east")
- dining_hall.link_room(kitchen, "north")
- dining_hall.link_room(ballroom, "west")
- dining_hall.link_room(office, "south")
- office.link_room(dining_hall, "north")
- #setup characters
- dave = Enemy("Dave", "A smelly zombie")
- dave.set_conversation("Brrlgrh... rgrhl... brains...")
- dave.set_weakness("sword")
- pam = Enemy("Pam", "A glowing zombie")
- pam.set_conversation("foood....fooood.")
- pam.set_weakness("sword")
- pam.set_item("metal_key")
- fred = Character("Fred", "Busy making computer games")
- fred.set_conversation("Sorry, to busy, send me an email")
- fred.set_item("plastic_key")
- cat = Animal("Cat", "Laid down, half sleeping. Acts like it owns the place")
- cat.set_huggable(True)
- cat.set_food("cheese")
- cat.set_hug_sound("purrrrr")
- #setup character locations
- dining_hall.character = dave
- office.character = fred
- kitchen.character = cat
- ballroom.character = pam
- #set starting room
- current_room = kitchen
- #start game
- alive = True
- the_game = RPGInfo(game_name)
- the_game.welcome()
- RPGInfo.info()
- print(f"There are {str(Room.number_of_rooms)} rooms to explore.")
- while alive:
- current_room.get_details()
- inhabitant = current_room.character
- if inhabitant is not None:
- inhabitant.describe()
- # loop so we don't display room details after every action.
- while True:
- command = input(" What would would you like to do? >")
- # Check whether a direction was typed
- if command in ["north", "south", "east", "west"]:
- in_room = current_room
- current_room = current_room.move(command)
- if current_room == in_room:
- pass
- else:
- break # Moved so we need to start the main loop again
- elif command == "talk":
- if inhabitant is not none:
- inhabitant.talk()
- elif command == "fight":
- if isinstance(inhabitant, Enemy):
- fight_item = input(" What item do you want to use >?")
- if inhabitant.fight(fight_item):
- current_room.character = None
- else:
- print("You died")
- alive = False
- break # You're dead, so no more action, break this while and the the main while using above
- else:
- print("You cannot fight anyone")
- elif command == "info":
- break
- elif command == "feed":
- if isinstance(inhabitant, Animal):
- feed_item = input(" What item do you want to use >?")
- if inhabitant.feed(feed_item):
- current_room.character = None
- print(f"{inhabitant.name} has left the room")
- else:
- print("you cannot feed anyone")
- elif command == "hug":
- if isinstance(inhabitant, Animal):
- inhabitant.hug()
- elif isinstance(inhabitant, Enemy):
- print(f"{inhabitant.name} is an Enemy")
- else:
- print("nothing to hug")
- elif command == "steal":
- if inhabitant is not None:
- steal_item = input(" What item do you want to steal >?")
- if isinstance(inhabitant, Enemy): #and inhabitant.item is not None:
- if inhabitant.steal(steal_item) is False:
- alive = False
- break # You're dead, so no more action, break this while and the the main while using above
- else:
- print("you cannot steal from them")
- else:
- print("that is not a command")
- RPGInfo.credits()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement