Moortiii

Fighting monsters

Apr 17th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.01 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4. def sleep():
  5.     time.sleep(1)
  6.     print("")
  7.    
  8. class Player():
  9.     def __init__(self, hitpoints, attack):
  10.         self.hitpoints = hitpoints
  11.         self.attack = attack
  12.         self.backpack = {"bandages": 5, "hatchet": 1, "rocks": 3}
  13.  
  14.     def pAttack(self, monster):
  15.         sleep()
  16.         diceRoll = random.randint(1,6)
  17.         if(diceRoll >= 5):
  18.             criticalHit = (self.attack * 2) - 1
  19.             monster.hitpoints -= criticalHit
  20.             print("You critically hit the {}!".format(monster.name))
  21.             print("You deal {} damage. The {} now has {} hitpoints left".format(criticalHit, monster.name, monster.hitpoints))
  22.         else:
  23.             monster.hitpoints -= self.attack
  24.             print("You manage to hit the {}!".format(monster.name))
  25.             print("You deal {} damage. The {} now has {} hitpoints left".format(self.attack, monster.name, monster.hitpoints))
  26.  
  27.     def pBlock(self, monster):
  28.         sleep()
  29.         print("You manage to block the {}'s hit!".format(monster.name))
  30.         print("You still have {} hitpoints left".format(self.hitpoints))
  31.  
  32.     def pMisses(self, monster):
  33.         sleep()
  34.         print("You miss your swing at the {}!".format(monster.name))
  35.         print("The {} still has {} hitpoints left.".format(monster.name, monster.hitpoints))
  36.  
  37.     def viewInventory(self):
  38.         print("Backpack: {}".format(self.backpack))
  39.  
  40.     def useItem(self):
  41.         itemToUse = input("Type 'B' to use a bandage and heal up: ").upper()
  42.         if(itemToUse == "B"):
  43.             if(self.backpack["bandages"] > 0):
  44.                 self.hitpoints += 5
  45.                 self.backpack["bandages"] -= 1
  46.                 print("You have {} bandages left".format(self.backpack["bandages"]))
  47.             else:
  48.                 print("You are out of bandages!")
  49. class Monster():
  50.     def __init__(self, color, hitpoints, attack):
  51.         self.color = color
  52.         self.hitpoints = hitpoints
  53.         self.attack = attack
  54.         self.name = "fabledong"
  55.    
  56.     def mAttack(self, player):
  57.         sleep()
  58.         player.hitpoints -= self.attack
  59.         print("The {} hits its attack!".format(self.name))
  60.         print("It deals {} damage. You now have {} hitpoints left.".format(self.attack, player.hitpoints))
  61.  
  62.     def mMisses(self, player):
  63.         sleep()
  64.         print("The {} misses its attack!".format(self.name))
  65.         print("You still have {} hitpoints left".format(player.hitpoints))
  66.        
  67.     def mBlock(self):
  68.         sleep()
  69.         print("The {} is able to block your attack!".format(self.name))
  70.         print("The {} still has {} hitpoints left".format(self.name, self.hitpoints))
  71.  
  72. class Dragon():
  73.     def __init__(self, hitpoints, attack):
  74.         self.hitpoints = hitpoints
  75.         self.attack = attack
  76.         self.spells = ["fireball", "iceblast", "earthquake"]
  77.         self.name = "dragon"
  78.  
  79.     def mAttack(self, player):
  80.         spellChoice = random.choice(self.spells)
  81.         spellDamage = 0
  82.         if(spellChoice == "fireball"):
  83.             spellDamage = 3
  84.         elif(spellChoice == "iceblast"):
  85.             spellDamage = 5
  86.         elif(spellChoice == "earthquake"):
  87.             spellDamage = 8
  88.         player.hitpoints -= spellDamage
  89.         sleep()
  90.         print("The {} uses {}!".format(self.name, spellChoice))
  91.         sleep()
  92.         print("It deals {} damage to you. You have {} hitpoints left!".format(spellDamage, player.hitpoints))
  93.  
  94.     def mMisses(self, player):
  95.         sleep()
  96.         print("The {} misses its attack!".format(self.name))
  97.         print("You still have {} hitpoints left".format(player.hitpoints))
  98.        
  99.     def mBlock(self):
  100.         sleep()
  101.         print("The {} is able to block your attack!".format(self.name))
  102.         print("The {} still has {} hitpoints left".format(self.name, self.hitpoints))
  103.        
  104.  
  105. def fightMonster(player, monster):
  106.     print("The {} has {} attack and {} hitpoints.".format(monster.name, monster.attack, monster.hitpoints))
  107.     print("You have {} attack and {} hitpoints.".format(player.attack, player.hitpoints))
  108.     while(True):
  109.         mIsStunned = False
  110.         if(player.hitpoints > 0):
  111.             wantsToAttack = input("Do you want to attack, block or use an item? 'A' / 'B' / 'I'\n\n").upper()
  112.             if(wantsToAttack == "A"):
  113.                 pDiceRoll = random.randint(1,6)
  114.                 if(pDiceRoll > 3):
  115.                     player.pAttack(monster)
  116.                 else:
  117.                     player.pMisses(monster)
  118.             elif(wantsToAttack == "I"):
  119.                 player.viewInventory()
  120.                 player.useItem()
  121.             else:
  122.                 pDiceRoll = random.randint(1,6)
  123.                 if(pDiceRoll > 3):
  124.                     player.pBlock(monster)
  125.                     print("You stun the {}, it's a guaranteed hit!".format(monster.name))
  126.                     mIsStunned = True
  127.                     player.pAttack(monster)
  128.                 else:
  129.                     monster.mAttack(player)
  130.             if(monster.hitpoints <= 0):
  131.                 print("The {} is all out of hitpoints! You win the battle!".format(monster.name))
  132.                 break
  133.             else:
  134.                 if(mIsStunned):
  135.                     sleep()
  136.                     print("The {} is stunned and unable to attack".format(monster.name))
  137.                 else:
  138.                     if(player.hitpoints > 0):
  139.                         print("The {} tries to attack you.".format(monster.name))
  140.                         mDiceRoll = random.randint(1,6)
  141.                         if(mDiceRoll > 3):
  142.                             monster.mAttack(player)
  143.                         else:
  144.                             monster.mMisses(player)
  145.         else:
  146.             print("You are out of hitpoints! You lose the battle!")
  147.             break
  148.     sleep()
  149.  
  150. def playGame():
  151.     myMonster = Monster("red", 15, 2)
  152.     myDragon = Dragon(20, 5)
  153.     myPlayer = Player(20, 4)
  154.     fightMonster(myPlayer, myMonster)
  155.     fightMonster(myPlayer, myDragon)
  156.  
  157. playGame()
Advertisement
Add Comment
Please, Sign In to add comment