import random
import time
def sleep():
time.sleep(1)
print("")
class Player():
def __init__(self, hitpoints, attack):
self.hitpoints = hitpoints
self.attack = attack
self.backpack = {"bandages": 5, "hatchet": 1, "rocks": 3}
def pAttack(self, monster):
sleep()
diceRoll = random.randint(1,6)
if(diceRoll >= 5):
criticalHit = (self.attack * 2) - 1
monster.hitpoints -= criticalHit
print("You critically hit the {}!".format(monster.name))
print("You deal {} damage. The {} now has {} hitpoints left".format(criticalHit, monster.name, monster.hitpoints))
else:
monster.hitpoints -= self.attack
print("You manage to hit the {}!".format(monster.name))
print("You deal {} damage. The {} now has {} hitpoints left".format(self.attack, monster.name, monster.hitpoints))
def pBlock(self, monster):
sleep()
print("You manage to block the {}'s hit!".format(monster.name))
print("You still have {} hitpoints left".format(self.hitpoints))
def pMisses(self, monster):
sleep()
print("You miss your swing at the {}!".format(monster.name))
print("The {} still has {} hitpoints left.".format(monster.name, monster.hitpoints))
def viewInventory(self):
print("Backpack: {}".format(self.backpack))
def useItem(self):
itemToUse = input("Type 'B' to use a bandage and heal up: ").upper()
if(itemToUse == "B"):
if(self.backpack["bandages"] > 0):
self.hitpoints += 5
self.backpack["bandages"] -= 1
print("You have {} bandages left".format(self.backpack["bandages"]))
else:
print("You are out of bandages!")
class Monster():
def __init__(self, color, hitpoints, attack):
self.color = color
self.hitpoints = hitpoints
self.attack = attack
self.name = "fabledong"
def mAttack(self, player):
sleep()
player.hitpoints -= self.attack
print("The {} hits its attack!".format(self.name))
print("It deals {} damage. You now have {} hitpoints left.".format(self.attack, player.hitpoints))
def mMisses(self, player):
sleep()
print("The {} misses its attack!".format(self.name))
print("You still have {} hitpoints left".format(player.hitpoints))
def mBlock(self):
sleep()
print("The {} is able to block your attack!".format(self.name))
print("The {} still has {} hitpoints left".format(self.name, self.hitpoints))
class Dragon():
def __init__(self, hitpoints, attack):
self.hitpoints = hitpoints
self.attack = attack
self.spells = ["fireball", "iceblast", "earthquake"]
self.name = "dragon"
def mAttack(self, player):
spellChoice = random.choice(self.spells)
spellDamage = 0
if(spellChoice == "fireball"):
spellDamage = 3
elif(spellChoice == "iceblast"):
spellDamage = 5
elif(spellChoice == "earthquake"):
spellDamage = 8
player.hitpoints -= spellDamage
sleep()
print("The {} uses {}!".format(self.name, spellChoice))
sleep()
print("It deals {} damage to you. You have {} hitpoints left!".format(spellDamage, player.hitpoints))
def mMisses(self, player):
sleep()
print("The {} misses its attack!".format(self.name))
print("You still have {} hitpoints left".format(player.hitpoints))
def mBlock(self):
sleep()
print("The {} is able to block your attack!".format(self.name))
print("The {} still has {} hitpoints left".format(self.name, self.hitpoints))
def fightMonster(player, monster):
print("The {} has {} attack and {} hitpoints.".format(monster.name, monster.attack, monster.hitpoints))
print("You have {} attack and {} hitpoints.".format(player.attack, player.hitpoints))
while(True):
mIsStunned = False
if(player.hitpoints > 0):
wantsToAttack = input("Do you want to attack, block or use an item? 'A' / 'B' / 'I'\n\n").upper()
if(wantsToAttack == "A"):
pDiceRoll = random.randint(1,6)
if(pDiceRoll > 3):
player.pAttack(monster)
else:
player.pMisses(monster)
elif(wantsToAttack == "I"):
player.viewInventory()
player.useItem()
else:
pDiceRoll = random.randint(1,6)
if(pDiceRoll > 3):
player.pBlock(monster)
print("You stun the {}, it's a guaranteed hit!".format(monster.name))
mIsStunned = True
player.pAttack(monster)
else:
monster.mAttack(player)
if(monster.hitpoints <= 0):
print("The {} is all out of hitpoints! You win the battle!".format(monster.name))
break
else:
if(mIsStunned):
sleep()
print("The {} is stunned and unable to attack".format(monster.name))
else:
if(player.hitpoints > 0):
print("The {} tries to attack you.".format(monster.name))
mDiceRoll = random.randint(1,6)
if(mDiceRoll > 3):
monster.mAttack(player)
else:
monster.mMisses(player)
else:
print("You are out of hitpoints! You lose the battle!")
break
sleep()
def playGame():
myMonster = Monster("red", 15, 2)
myDragon = Dragon(20, 5)
myPlayer = Player(20, 4)
fightMonster(myPlayer, myMonster)
fightMonster(myPlayer, myDragon)
playGame()
Comments