Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.01 KB | None | 0 0
  1. def showInstructions():
  2.     # comment
  3.     print("RPG Game")
  4.     print("========")
  5.     print("Commands:")
  6.     print("'go [direction]'")
  7.     print("'get [item]'")
  8.     print("'drop [item]'")
  9.     print("'fight'")
  10.  
  11. def showStatus():
  12.     #print the player's current status
  13.     print("---------------------------")
  14.     print("You are in the " + rooms[currentRoom]["name"])
  15.     #print the current inventory
  16.     print("Inventory : " + str(inventory))
  17.     #print an item if there is one
  18.     if "foe" in rooms[currentRoom]:
  19.         print("You see a " + rooms[currentRoom]["foe"], "in the room")
  20.     if "item" in rooms[currentRoom]:
  21.         print("You see a " + rooms[currentRoom]["item"])
  22.     print("---------------------------")
  23.  
  24. #an inventory, which is initially empty
  25. inventory = []
  26.  
  27. #a dictionary linking a room to other room positions
  28. rooms = {
  29.  
  30.     1 : {  "name"  : "Hall" ,
  31.            "east"  : 2,
  32.            "south" : 3,
  33.            "item"  : "Vase",
  34.            "foe" : "enemy" }  ,
  35.  
  36.     2 : {  "name"  : "Master Bedroom" ,
  37.            "west"  : 1,
  38.            "south" : 4,
  39.            "east"  : 5,
  40.            "item"  : "Sword",
  41.            "foe"   : "enemy" }  ,
  42.  
  43.     3 : {  "name"  : "Kitchen" ,
  44.            "north" : 1,
  45.            "south" : 6,
  46.            "west"  : 7,
  47.            "item"  : "Machete",
  48.            "foe"   : "enemy" }  ,
  49.  
  50.     4 : {  "name"  : "Master Bathroom" ,
  51.            "north" : 2,
  52.            "item"  : "Plunger",
  53.            "foe"   : "enemy" }  ,
  54.  
  55.     5 : {  "name"  : "Office Room" ,
  56.            "west"  : 2,
  57.            "item"  : "Staple Gun",
  58.            "foe"   : "enemy" }  ,
  59.  
  60.     6 : {  "name"  : "Garage" ,
  61.            "north" : 3,
  62.            "item"  : "Pistol",
  63.            "foe"   : "enemy" }  ,
  64.  
  65.     7 : {  "name"  : "Dining Room" ,
  66.            "south" : 8,
  67.            "east"  : 3,
  68.            "item"  : "Candle Stick",
  69.            "foe"   : "enemy" }  ,
  70.  
  71.     8 : {  "name"  : "Living Room" ,
  72.            "east"  : 9,
  73.            "south" : 10,
  74.            "north" : 7,
  75.            "item"  : "Shield",
  76.            "foe"   : "enemy" }  ,
  77.  
  78.     9 : {  "name"  : "Guest Bedroom" ,
  79.            "west"  : 8,
  80.            "south" : 11,
  81.            "item"  : "Soap",
  82.            "foe"   : "enemy" }  ,
  83.  
  84.     10 : { "name"  : "Storage Room" ,
  85.            "north" : 8,
  86.            "item"  : "Baseball Bat",
  87.            "foe"   : "enemy" }  ,
  88.  
  89.     11 : { "name"  : "Guest Bathroom" ,
  90.            "north" : 9,
  91.            "item"  : "Shampoo",
  92.            "foe"   : "enemy" }  ,
  93.  
  94.  
  95. }
  96.  
  97.  
  98. damagePoints = {"Soap": 2, "Shampoo": 3, "Candle stick": 10, "Plunger": 4, "Vase": 5,
  99.                 "Shield": 15, "Baseball bat": 30, "Pistol": 90, "Staple gun": 20,
  100.                 "Machete": 80, "Sword": 70}
  101.  
  102. enemyDamage = { 1 : 10,
  103.                 2 : 40,
  104.                 3 : 20,
  105.                 4 : 25,
  106.                 5 : 33,
  107.                 6 : 40,
  108.                 7 : 50,
  109.                 8 : 65,
  110.                 9 : 28,
  111.                 10 : 60,
  112.                 11 : 72 }
  113.  
  114. enemyHealth = { 1 : 20,
  115.                 2 : 30,
  116.                 3 : 40,
  117.                 4 : 50,
  118.                 5 : 60,
  119.                 6 : 70,
  120.                 7 : 84,
  121.                 8 : 90,
  122.                 9 : 78,
  123.                 10 : 25,
  124.                 11 : 48,}
  125.  
  126.  
  127.  
  128.  
  129. #start the player in room 1
  130. currentRoom = 1
  131. haveFoughtEnemy = True
  132. moveToRoom = False
  133. user_health = 100
  134. number_of_enemies = len(rooms)
  135.  
  136. showInstructions()
  137. originalLocation = dict()
  138. first_move = True
  139.  
  140. #loop infinitely
  141. while True:
  142.  
  143.     showStatus()
  144.  
  145.     #get the player's next 'move'
  146.     #.split() breaks it up into an list array
  147.     #eg typing 'go east' would give the list:
  148.     #['go','east']
  149.     move = input(">").lower().split()
  150.  
  151.     #if they type 'go' first
  152.     if len(move) > 1 or (move and move[0] == 'fight'):
  153.         if move[0] == "go":
  154.  
  155.             # allow user to move at the beginning of the game without fighting the Hall's enemy
  156.             if first_move is True:
  157.                 first_move = False
  158.             else:
  159.                 # check if user has fought the current room's enemy before moving on
  160.                 if haveFoughtEnemy is False and currentRoom in enemyHealth:
  161.                     print(f"Must Fight Enemy In This Room Before Moving To Another Room")
  162.                     continue
  163.             #check that they are allowed wherever they want to go
  164.             if move[1] in rooms[currentRoom]:
  165.                 #set the current room to the new room
  166.                 currentRoom = rooms[currentRoom][move[1]]
  167.                 #there is no door (link) to the new room
  168.  
  169.                 # reset haveFoughtEnemy back to False
  170.                 haveFoughtEnemy = False
  171.             else:
  172.                 print("You can't go that way!")
  173.  
  174.         #if they type 'get' first
  175.         elif move[0] == "get" :
  176.             print(move[1])
  177.             #if the room contains an item, and the item is the one they want to get
  178.             if "item" in rooms[currentRoom] and move[1] == rooms[currentRoom]["item"].lower():
  179.                 #add the item to their inventory
  180.                 inventory += [move[1]]
  181.                 #display a helpful message
  182.                 print(move[1] + " got!")
  183.  
  184.                 originalLocation[move[1]] = currentRoom
  185.                 #delete the item from the room
  186.                 del rooms[currentRoom]["item"]
  187.             #otherwise, if the item isn't there to get
  188.             else:
  189.                 #tell them they can't get it
  190.                 print("Can't get " + move[1] + "!")
  191.  
  192.         elif move[0] == "drop" :
  193.             if move[1] in inventory:
  194.                 inventory.remove(move[1])
  195.                 print(move[1] + " dropped!")
  196.                 rooms[originalLocation[move[1]]]["item"] = move[1].capitalize()
  197.             else:
  198.                 print("{} not in inventory".format(move[1]))
  199.  
  200.         elif move[0] == "fight":
  201.             print("is fighting")
  202.             # check if current room's enemy still has health
  203.             if currentRoom in enemyHealth:
  204.                 user_health -= enemyDamage[currentRoom]
  205.                 print("You sustained damage of {}. health remaing {}".format(
  206.                     enemyDamage[currentRoom], user_health))
  207.                 if len(inventory) > 0:
  208.                     enemyHealth[currentRoom] -= damagePoints[inventory[0].capitalize()]
  209.  
  210.                     print("you've dealt {} damage points to enemy in room {}".format(
  211.                         damagePoints[inventory[0].capitalize()],
  212.                         currentRoom
  213.                     ))
  214.  
  215.                     if enemyHealth[currentRoom] <= 0:
  216.                         del enemyHealth[currentRoom]
  217.                         if not enemyHealth:
  218.                             print("You have killed all enemies!")
  219.                             break
  220.                         elif user_health <= 0:
  221.                             print("You're dead!")
  222.                             break
  223.             else:
  224.                 print("You have defeated this room's enemy")
  225.             haveFoughtEnemy = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement