Moortiii

Python - Dungeon Game Combat

Apr 10th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 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.  
  13.     def pAttack(self, monster):
  14.         sleep()
  15.         diceRoll = random.randint(1,6)
  16.         if(diceRoll > 3):
  17.             isAttacking = True
  18.             monster.hitpoints -= self.attack
  19.             print("You manage to hit the monster!")
  20.             print("You deal {} damage. The monster now has {} hitpoints left".format(self.attack, monster.hitpoints))
  21.         else:
  22.             isAttacking = False
  23.             print("You miss your swing at the monster.")
  24.             print("The monster still has {} hitpoints left.".format(monster.hitpoints))
  25.        
  26.        
  27. class Monster():
  28.     def __init__(self, color, hitpoints, attack):
  29.         self.color = color
  30.         self.hitpoints = hitpoints
  31.         self.attack = attack
  32.  
  33.     def mAttack(self, player):
  34.         sleep()
  35.         diceRoll = random.randint(1,6)
  36.         if(diceRoll > 4):
  37.             isAttacking = True
  38.             player.hitpoints -= self.attack
  39.             print("The monster hits its attack!")
  40.             print("It deals {} damage. You now have {} hitpoints left.".format(self.attack, player.hitpoints))
  41.         else:
  42.             isAttacking = False
  43.             print("The monster misses its attack!")
  44.  
  45.     def mBlock(self):
  46.         sleep()
  47.         diceRoll = random.randint(1,6)
  48.         if(diceRoll > 5):
  49.             isBlocking = True
  50.             print("The monster is blocking.")
  51.         else:
  52.             isBlocking = False
  53.             print("The monster was unable to block your hit.")
  54.  
  55. def fightMonster(player, monster):
  56.     print("You see something lurking in the shadows..")
  57.     print("Suddenly a monster jumps out at you, you have no choice but to fight!")
  58.     while(True):
  59.         if(player.hitpoints > 0):
  60.             player.pAttack(monster)
  61.         else:
  62.             print("You have no hitpoints left. The monster has defeated you!")
  63.             break
  64.         if(monster.hitpoints > 0):
  65.             monster.mAttack(player)
  66.         else:
  67.             print("The monster is out of hitpoints. You win!")
  68.             break  
  69.  
  70. def playGame():
  71.     myMonster = Monster("red", 5, 1)
  72.     myPlayer = Player(10, 2)
  73.     fightMonster(myPlayer, myMonster)
  74.  
  75. playGame()
Advertisement
Add Comment
Please, Sign In to add comment