Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- def showInstructions():
- #print a main menu and the commands
- print('''
- Survival horror
- ===============
- Commands:
- go [direction]
- get [item]
- You have only 2 minutes to escape!!
- ''')
- def GameOver():
- print('Time is out! GAME OVER!!!!!!!!!')
- def showStatus():
- #print the player's current status
- print("---------------------------")
- print("You are in the " + rooms[currentRoom]["name"])
- #print the current inventory
- print("Inventory : " + str(inventory))
- #print an item if there is one
- if "item" in rooms[currentRoom]:
- print("You see a " + rooms[currentRoom]["item"])
- print("---------------------------")
- #an inventory, which is initially empty
- inventory = []
- #a dictionary linking a room to other room positions
- rooms = {
- 'room_1':{
- "name" : "hallWay",
- "west" : "room_2",
- "east" : "room_4",
- "item" : "documents",
- },
- 'room_2':{
- "name" : "terfd",
- "north" : "room_3",
- "east" : "room_6",
- "south": "room_1",
- "item" : "phone",
- },
- 'room_3':{
- "name" : "homeTheater",
- "south" : "room_2",
- "item" : "monster",
- },
- 'room_4':{
- "name" : "kitchen",
- "east" : "room_5",
- "item" : "gun",
- },
- 'room_5':{
- "name" : "toilet",
- "south" : "room_4",
- "item" : "monster",
- },
- 'room_6':{
- "name" : "bedRoom",
- "west": "room_7",
- "south" : "room_2",
- },
- 'room_7':{
- "name": "closet",
- "south": "room_6",
- "north" : "exit",
- "item": "key",
- },
- 'exit':{
- "name": "exit",
- "item": "exit",
- },
- }
- #start the player in room 1
- currentRoom = 'room_1'
- showInstructions()
- t = threading.Timer(120, GameOver)
- t.start()
- #loop infinitely
- while True:
- showStatus()
- #get the player's next 'move'
- #.split() breaks it up into an list array
- #eg typing 'go east' would give the list:
- #['go','east']
- move = input(">").lower().split()
- #if they type 'go' first
- if move[0] == "go":
- #check that they are allowed wherever they want to go
- if move[1] in rooms[currentRoom]:
- #set the current room to the new room
- currentRoom = rooms[currentRoom][move[1]]
- #there is no door (link) to the new room
- else:
- print("You can't go that way!")
- #if they type 'get' first
- if move[0] == "get" :
- #if the room contains an item, and the item is the one they want to get
- if "item" in rooms[currentRoom] and move[1] in rooms[currentRoom]["item"]:
- #add the item to their inventory
- inventory += [move[1]]
- #display a helpful message
- print(move[1] + " got!")
- #delete the item from the room
- del rooms[currentRoom]["item"]
- #otherwise, if the item isn't there to get
- else:
- #tell them they can't get it
- print("Can't get " + move[1] + "!")
- if "item" in rooms[currentRoom] and "monster" in rooms[currentRoom]["item"]:
- print("A monster has got you... GAME OVER!")
- print("Press any key to quit")
- input()
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement