Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def showInstructions():
- # comment
- print("RPG Game")
- print("========")
- print("Commands:")
- print("'go [direction]'")
- print("'get [item]'")
- print("'drop [item]'")
- print("'fight'")
- 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 "foe" in rooms[currentRoom]:
- print("You see a " + rooms[currentRoom]["foe"], "in the room")
- 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 = {
- 1 : { "name" : "Hall" ,
- "east" : 2,
- "south" : 3,
- "item" : "Vase",
- "foe" : "enemy" } ,
- 2 : { "name" : "Master Bedroom" ,
- "west" : 1,
- "south" : 4,
- "east" : 5,
- "item" : "Sword",
- "foe" : "enemy" } ,
- 3 : { "name" : "Kitchen" ,
- "north" : 1,
- "south" : 6,
- "west" : 7,
- "item" : "Machete",
- "foe" : "enemy" } ,
- 4 : { "name" : "Master Bathroom" ,
- "north" : 2,
- "item" : "Plunger",
- "foe" : "enemy" } ,
- 5 : { "name" : "Office Room" ,
- "west" : 2,
- "item" : "Staple Gun",
- "foe" : "enemy" } ,
- 6 : { "name" : "Garage" ,
- "north" : 3,
- "item" : "Pistol",
- "foe" : "enemy" } ,
- 7 : { "name" : "Dining Room" ,
- "south" : 8,
- "east" : 3,
- "item" : "Candle Stick",
- "foe" : "enemy" } ,
- 8 : { "name" : "Living Room" ,
- "east" : 9,
- "south" : 10,
- "north" : 7,
- "item" : "Shield",
- "foe" : "enemy" } ,
- 9 : { "name" : "Guest Bedroom" ,
- "west" : 8,
- "south" : 11,
- "item" : "Soap",
- "foe" : "enemy" } ,
- 10 : { "name" : "Storage Room" ,
- "north" : 8,
- "item" : "Baseball Bat",
- "foe" : "enemy" } ,
- 11 : { "name" : "Guest Bathroom" ,
- "north" : 9,
- "item" : "Shampoo",
- "foe" : "enemy" } ,
- }
- damagePoints = {"Soap": 2, "Shampoo": 3, "Candle stick": 10, "Plunger": 4, "Vase": 5,
- "Shield": 15, "Baseball bat": 30, "Pistol": 90, "Staple gun": 20,
- "Machete": 80, "Sword": 70}
- enemyDamage = { 1 : 10,
- 2 : 40,
- 3 : 20,
- 4 : 25,
- 5 : 33,
- 6 : 40,
- 7 : 50,
- 8 : 65,
- 9 : 28,
- 10 : 60,
- 11 : 72 }
- enemyHealth = { 1 : 20,
- 2 : 30,
- 3 : 40,
- 4 : 50,
- 5 : 60,
- 6 : 70,
- 7 : 84,
- 8 : 90,
- 9 : 78,
- 10 : 25,
- 11 : 48,}
- #start the player in room 1
- currentRoom = 1
- haveFoughtEnemy = True
- moveToRoom = False
- user_health = 100
- number_of_enemies = len(rooms)
- showInstructions()
- originalLocation = dict()
- first_move = True
- #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 len(move) > 1 or (move and move[0] == 'fight'):
- if move[0] == "go":
- # allow user to move at the beginning of the game without fighting the Hall's enemy
- if first_move is True:
- first_move = False
- else:
- # check if user has fought the current room's enemy before moving on
- if haveFoughtEnemy is False and currentRoom in enemyHealth:
- print(f"Must Fight Enemy In This Room Before Moving To Another Room")
- continue
- #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
- # reset haveFoughtEnemy back to False
- haveFoughtEnemy = False
- else:
- print("You can't go that way!")
- #if they type 'get' first
- elif move[0] == "get" :
- print(move[1])
- #if the room contains an item, and the item is the one they want to get
- if "item" in rooms[currentRoom] and move[1] == rooms[currentRoom]["item"].lower():
- #add the item to their inventory
- inventory += [move[1]]
- #display a helpful message
- print(move[1] + " got!")
- originalLocation[move[1]] = currentRoom
- #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] + "!")
- elif move[0] == "drop" :
- if move[1] in inventory:
- inventory.remove(move[1])
- print(move[1] + " dropped!")
- rooms[originalLocation[move[1]]]["item"] = move[1].capitalize()
- else:
- print("{} not in inventory".format(move[1]))
- elif move[0] == "fight":
- print("is fighting")
- # check if current room's enemy still has health
- if currentRoom in enemyHealth:
- user_health -= enemyDamage[currentRoom]
- print("You sustained damage of {}. health remaing {}".format(
- enemyDamage[currentRoom], user_health))
- if len(inventory) > 0:
- enemyHealth[currentRoom] -= damagePoints[inventory[0].capitalize()]
- print("you've dealt {} damage points to enemy in room {}".format(
- damagePoints[inventory[0].capitalize()],
- currentRoom
- ))
- if enemyHealth[currentRoom] <= 0:
- del enemyHealth[currentRoom]
- if not enemyHealth:
- print("You have killed all enemies!")
- break
- elif user_health <= 0:
- print("You're dead!")
- break
- else:
- print("You have defeated this room's enemy")
- haveFoughtEnemy = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement