Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from .Magic import Spell
- class Bcolor:
- HEADER = '\033[95m'
- OKBLUE = '\033[94m'
- OKGREEN = '\033[92m'
- WARNING = '\033[93m'
- FAIL = '\033[91m'
- ENDC = '\033[0m'
- BOLD = '\033[1m'
- UNDERLINE = '\033[4m'
- class Person:
- def __init__(self, name, hp, mp, at, df, magic, items):
- self.name = name
- self.maxhp = hp
- self.hp = hp # HP of the player changes throughout the battle
- self.maxmp = mp
- self.mp = mp
- self.al = at-10
- self.ah = at+10
- self.df = df
- self.magic = magic
- self.items = items
- self.actions = ["Attack", "Magic", "Items"]
- def gen_dm(self):
- return random.randrange(self.al, self.ah)
- def take_dm(self, dm):
- self.hp -= dm
- if self.hp < 0:
- self.hp = 0
- return self.hp
- def heal(self, dm):
- self.hp += dm
- if self.hp > self.maxhp:
- self.hp = self.maxhp
- def get_hp(self):
- return self.hp
- def get_maxhp(self):
- return self.maxhp
- def get_mp(self):
- return self.mp
- def get_maxmp(self):
- return self.maxmp
- def reduce_mp(self, cost):
- self.mp -= cost
- def choose_actions(self):
- i = 1
- print(" Actions")
- for item in self.actions:
- print(" ", str(i) + ":", item)
- i += 1
- def magic_choice(self):
- print(" Magic")
- i = 1
- for spell in self.magic:
- print(" ", str(i) + ":", spell.name, " cost : ", spell.cost)
- i += 1
- def item_choice(self):
- print(" Items")
- i = 1
- for item in self.items:
- print(" ", str(i) + ":", item["item"].name, " : ", item["item"].des, "(* " + str(item["quantity"]) + ")")
- i += 1
- def choose_target(self, Enemy):
- i = 1
- print(Bcolor.BOLD + Bcolor.FAIL + " TARGET:" + Bcolor.ENDC)
- for enemy in Enemy:
- if enemy.get_hp() != 0:
- print(" " + str(i) + " :" + enemy.name)
- i += 1
- choice = int(input(" Choose Target: ")) - 1
- return choice
- def enemy_stat(self):
- hp_bar = ""
- bar_health = (self.hp / self.maxhp) * 100 /2
- while bar_health > 0:
- hp_bar += "█"
- bar_health -= 1
- while len(hp_bar) < 50:
- hp_bar += " "
- hp_string = str(self.hp) + "/" + str(self.maxhp) # maintain the length of the HP/maxHP string to a constant
- current_hp = ""
- if len(hp_string) < 11:
- decrease = 11 - len(hp_string)
- while decrease > 0:
- current_hp += " "
- decrease -= 1
- current_hp += hp_string
- else:
- current_hp = hp_string
- print(" __________________________________________________")
- print(Bcolor.BOLD + str( self.name) + " " + current_hp + " |" + Bcolor.FAIL + hp_bar + Bcolor.ENDC + "| " + Bcolor.ENDC)
- def g_s(self): # Display the stats of the Player
- hp_bar = "" # Display the remaining HP in green colour
- bar_health = (self.hp / self.maxhp) * 100 / 4
- while bar_health > 0:
- hp_bar += "█"
- bar_health -= 1
- while len(hp_bar) < 25:
- hp_bar += " "
- mp_bar = "" # Display the remaining MP in green colour
- bar_magic = (self.mp / self.maxmp) * 100 / 10
- while bar_magic > 0:
- mp_bar += "█"
- bar_magic -= 1
- while len(mp_bar) < 10:
- mp_bar += " "
- hp_string = str(self.hp) + "/" + str(self.maxhp) # maintain the length of the HP/maxHP string to a constant
- current_hp = ""
- if len(hp_string) < 9:
- decrease = 9 - len(hp_string)
- while decrease > 0:
- current_hp += " "
- decrease -= 1
- current_hp += hp_string
- else:
- current_hp = hp_string
- mp_string = str(self.mp) + "/" + str(self.maxmp)
- current_mp = ""
- if len(mp_string) < 7:
- dec = 7 - len(mp_string)
- while dec > 0:
- current_mp += " "
- dec -= 1
- current_mp += mp_string
- else:
- current_mp = mp_string
- print(" _________________________ __________")
- print(Bcolor.BOLD + str(self.name) + " " + current_hp +" |" + Bcolor.OKGREEN + hp_bar + Bcolor.ENDC + "| " + Bcolor.ENDC + Bcolor.BOLD + current_mp + " |" + Bcolor.OKBLUE + mp_bar + Bcolor.ENDC + "|")
- def enemy_spell(self):
- m_c = random.randrange(0, len(self.magic))
- spell = self.magic[m_c]
- m_d = spell.gen_dm()
- pct = self.hp / self.maxhp * 100
- if self.mp < spell.cost or spell.type == "w" and pct > 50:
- self.enemy_spell()
- else:
- return spell, m_d
Add Comment
Please, Sign In to add comment