import random
odds = 0
progression = 0
crystal_hi = False
check = False
check1 = False
check2 = False
check3 = False
burn = False
class Character:
global burn, odds
def __init__(self):
self.name = ""
self.health = 1
self.health_max = 1
self.burn = False
def do_damage(self, enemy):
global burn, odds
odds = random.randint(1,25)
if odds == 25:
if self.name == "goblin" or self.name == "skeleton" or self.name == "vampire" or self.name == "living crystal" or self.name == "dragon":
print (f"The {self.name} performed a critical hit!!")
else:
print (f"{self.name} performed a critical hit!!")
damage = max((random.randint(self.attack // 2, self.attack)) - random.randint(enemy.defense // 2, enemy.defense), 0)
if damage == 0:
damage = 2
else:
damage *= 2
if self.name == ("dragon"):
enemy.burn = True
print(f"The dragon's fire breath sets {enemy.name} on fire!")
else:
damage = max((random.randint(self.attack // 2, self.attack)) - random.randint(enemy.defense // 2, enemy.defense), 0)
if enemy.burn == True:
odds = random.randint(1,4)
if odds == 4:
print(f"{self.name} stops burning")
enemy.burn = False
else:
print(f"{self.name} takes extra burn damage")
damage += random.randint((enemy.health // 25),(enemy.health // 10))
enemy.health -= damage
if damage == 0:
if self.name == "goblin" or self.name == "skeleton" or self.name == "vampire" or self.name == "living crystal" or self.name == "dragon":
print(f"The {enemy.name} evades {self.name}'s attack.")
else:
print(f"{self.name} evades the {enemy.name}'s attack.")
else:
if self.name == "goblin" or self.name == "skeleton" or self.name == "vampire" or self.name == "living crystal" or self.name == "dragon":
print(f"The {self.name} does {damage} DAMAGE to {enemy.name}!")
else:
print(f"{self.name} does {damage} DAMAGE to the {enemy.name}!")
return enemy.health <= 0
class Enemy(Character):
global odds, progression
def __init__(self, player):
if progression <= 5:
Character.__init__(self)
self.name = 'goblin'
self.health = random.randint(3, 5)
self.defense = 1
self.attack = 2
elif progression >= 6 and progression <= 10:
odds = random.randint(1,25)
if odds > 20:
Character.__init__(self)
self.name = 'skeleton'
self.health = random.randint(5, 10)
self.defense = 2
self.attack = 4
else:
Character.__init__(self)
self.name = 'goblin'
self.health = random.randint(3, 5)
self.defense = 1
self.attack = 2
elif progression >= 11 and progression < 10000:
odds = random.randint(1,25)
if odds > 20:
Character.__init__(self)
self.name = 'vampire'
self.health = random.randint(10, 25)
self.defense = 4
self.attack = 8
else:
Character.__init__(self)
self.name = 'skeleton'
self.health = random.randint(5, 10)
self.defense = 2
self.attack = 4
else:
odds = random.randint(1,50)
if odds >= 41:
Character.__init__(self)
self.name = 'dragon'
self.health = random.randint(75, 100)
self.defense = 8
self.attack = 15
else:
Character.__init__(self)
self.name = 'living crystal'
self.health = random.randint(25, 50)
self.defense = 5
self.attack = 10
class Player(Character):
global progression, crystal_hi
def __init__(self):
Character.__init__(self)
self.enemy = None
self.state = 'normal'
self.health = 10
self.health_max = 10
self.attack = 3
self.defense = 1
def crystal(self):
global crystal_hi, progression
if crystal_hi == True:
progression -= 10000
crystal_hi = False
else:
if progression >= 26:
progression += 10000
crystal_hi = True
else:
print(f"{p.name} doesn't understand the suggestion.")
def quit(self):
print(f"{self.name} can't find the way back home, and dies of starvation.\nR.I.P.")
self.health = 0
def help(self): print(list(Commands.keys()))
def status(self): print(f"{self.name}'s health: {self.health}/{self.health_max}")
def tired(self):
print(f"{self.name} feels tired.")
self.health = max(1, self.health - 1)
def rest(self):
if self.state != 'normal':
print(f"{self.name} can't rest now!")
self.enemy_attacks()
else:
print(f"{self.name} rests.")
odds = random.randint(1,7)
if odds == 7:
self.enemy = Enemy(self)
print(f"{self.name} is rudely awakened by a {self.enemy.name}!")
self.state = 'fight'
self.enemy_attacks()
else:
if self.health < self.health_max:
if self.health >= ((self.health_max)-(self.health // 3)):
self.health = self.health_max
print(f"{self.name} has full health")
else:
self.health += random.randint((self.health // 7), (self.health // 3))
else:
print(f"{self.name} slept too much.")
self.health = self.health - 1
def explore(self):
if progression <= 10:
if self.state != 'normal':
print(f"{self.name} is too busy right now!")
self.enemy_attacks()
else:
odds = random.randint (1,3)
if odds == 1:
print(f"{self.name} explores a twisty passage.")
elif odds == 2:
print(f"{self.name} finds some remains.")
else:
print(f"{self.name} glides their hand across the wall as they walk.")
if random.randint(0, 1):
self.enemy = Enemy(self)
print(f"{self.name} encounters {self.enemy.name}!")
self.state = 'fight'
else:
if random.randint(0, 1):
self.tired()
elif progression >= 11 and progression <= 10000:
if self.state != 'normal':
print(f"{self.name} is too busy right now!")
self.enemy_attacks()
else:
odds = random.randint(1,3)
if odds == 1:
print(f"{self.name} explores deeper passages.")
elif odds == 2:
print(f"{self.name} finds some items.")
else:
print(f"{self.name} notices strange markings on the walls.")
if random.randint(0, 1):
self.enemy = Enemy(self)
print(f"{self.name} encounters {self.enemy.name}!")
self.state = 'fight'
elif random.randint(0, 1):
self.tired()
else:
if self.state != 'normal':
print(f"{self.name} is too busy right now!")
self.enemy_attacks()
else:
odds = random.randint (1,3)
if odds == 1:
print(f"{self.name} stares in awe at the crystals.")
elif odds == 2:
print(f"{self.name} finds some rare resources.")
else:
print(f"{self.name} almost gets lost in the caverns.")
if random.randint(0, 1):
self.enemy = Enemy(self)
print(f"{self.name} encounters {self.enemy.name}!")
self.state = 'fight'
else:
if random.randint(0, 5) == 5:
self.tired()
def flee(self):
if self.state != 'fight':
print(f"{self.name} runs in circles for a while.")
self.tired()
else:
if random.randint(1, self.health + 5) > random.randint(1, self.enemy.health):
print(f"{self.name} flees from the {self.enemy.name}.")
self.enemy = None
self.state = 'normal'
else:
print(f"{self.name} couldn't escape from the {self.enemy.name}!")
self.enemy_attacks()
def attack(self):
global progression
if self.state != 'fight':
print(f"{self.name} swats the air, without notable results.")
self.tired()
else:
if self.do_damage(self.enemy):
print(f"{self.name} kills the {self.enemy.name}!")
self.enemy = None
self.state = 'normal'
if random.randint(0, 15) < 10:
if self.health > 100:
print(f"{self.name}'s muscles can't grow any bigger.")
else:
odds = random.randint (1,3)
self.health += odds
self.health_max += odds
progression += odds
print(f"{self.name} feels stronger!")
else: self.enemy_attacks()
def enemy_attacks(self):
if self.enemy.do_damage(self):
print(f"{self.name} was slaughtered by the {self.enemy.name}!!!\nR.I.P.")
Commands = {
'quit': Player.quit,
'help': Player.help,
'status': Player.status,
'rest': Player.rest,
'explore': Player.explore,
'flee': Player.flee,
'attack': Player.attack,
'crystal': Player.crystal
}
def game():
global odds, progression, crystal_hi, check, check1, check2, check3, burn
p = Player()
p.name = input("What is your character's name? ")
while p.name == "goblin" or p.name == "skeleton" or p.name == "vampire" or p.name == "living crystal" or p.name == "dragon":
print("You can't be the name of an enemy. Choose a different name.")
p.name = input("What is your character's name? ")
print("(type help to get a list of actions)\n")
print(f"{p.name} enters a dark cave, searching for adventure.")
while p.health > 0:
if check == False and progression >= 6:
print(f"{p.name} senses a change in the caverns.")
check = True
if check1 == False and progression >= 11 and progression <= 25:
print(f"{p.name} feels uneasy as they start to encounter stronger monsters.")
check1 = True
if check2 == False and progression >= 26:
print(f"{p.name} discovers an opening, crystals poking out of the wall.")
print(f"{p.name} notices strong enemies through the tunnel.")
print("(Type crystal when you think you're ready)")
check2 = True
if check3 == False and progression >= 10000:
print("Type crystal to leave (You can use it to go to and back at any time.")
check3 = True
line = input("> ")
args = line.split()
if len(args) > 0:
commandFound = False
for c in list(Commands.keys()):
if args[0] == c[:len(args[0])]:
Commands[c](p)
commandFound = True
break
if not commandFound:
print(f"{p.name} doesn't understand the suggestion.")
game()