import random import time def sleep(): time.sleep(1) print("") class Player(): def __init__(self, hitpoints, attack): self.hitpoints = hitpoints self.attack = attack def pAttack(self, monster): sleep() diceRoll = random.randint(1,6) if(diceRoll > 3): isAttacking = True monster.hitpoints -= self.attack print("You manage to hit the monster!") print("You deal {} damage. The monster now has {} hitpoints left".format(self.attack, monster.hitpoints)) else: isAttacking = False print("You miss your swing at the monster.") print("The monster still has {} hitpoints left.".format(monster.hitpoints)) class Monster(): def __init__(self, color, hitpoints, attack): self.color = color self.hitpoints = hitpoints self.attack = attack def mAttack(self, player): sleep() diceRoll = random.randint(1,6) if(diceRoll > 4): isAttacking = True player.hitpoints -= self.attack print("The monster hits its attack!") print("It deals {} damage. You now have {} hitpoints left.".format(self.attack, player.hitpoints)) else: isAttacking = False print("The monster misses its attack!") def mBlock(self): sleep() diceRoll = random.randint(1,6) if(diceRoll > 5): isBlocking = True print("The monster is blocking.") else: isBlocking = False print("The monster was unable to block your hit.") def fightMonster(player, monster): print("You see something lurking in the shadows..") print("Suddenly a monster jumps out at you, you have no choice but to fight!") while(True): if(player.hitpoints > 0): player.pAttack(monster) else: print("You have no hitpoints left. The monster has defeated you!") break if(monster.hitpoints > 0): monster.mAttack(player) else: print("The monster is out of hitpoints. You win!") break def playGame(): myMonster = Monster("red", 5, 1) myPlayer = Player(10, 2) fightMonster(myPlayer, myMonster) playGame()