Guest User

Game

a guest
Apr 1st, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.14 KB | None | 0 0
  1. import random
  2. from .Magic import Spell
  3.  
  4.  
  5. class Bcolor:
  6.     HEADER = '\033[95m'
  7.     OKBLUE = '\033[94m'
  8.     OKGREEN = '\033[92m'
  9.     WARNING = '\033[93m'
  10.     FAIL = '\033[91m'
  11.     ENDC = '\033[0m'
  12.     BOLD = '\033[1m'
  13.     UNDERLINE = '\033[4m'
  14.  
  15.  
  16. class Person:
  17.     def __init__(self, name, hp, mp, at, df, magic, items):
  18.         self.name = name
  19.         self.maxhp = hp
  20.         self.hp = hp     # HP of the player changes throughout the battle
  21.         self.maxmp = mp
  22.         self.mp = mp
  23.         self.al = at-10
  24.         self.ah = at+10
  25.         self.df = df
  26.         self.magic = magic
  27.         self.items = items
  28.         self.actions = ["Attack", "Magic", "Items"]
  29.  
  30.     def gen_dm(self):
  31.        return random.randrange(self.al, self.ah)
  32.  
  33.     def take_dm(self, dm):
  34.         self.hp -= dm
  35.         if self.hp < 0:
  36.             self.hp = 0
  37.             return self.hp
  38.  
  39.     def heal(self, dm):
  40.         self.hp += dm
  41.         if self.hp > self.maxhp:
  42.             self.hp = self.maxhp
  43.  
  44.     def get_hp(self):
  45.         return self.hp
  46.  
  47.     def get_maxhp(self):
  48.         return self.maxhp
  49.  
  50.     def get_mp(self):
  51.         return self.mp
  52.  
  53.     def get_maxmp(self):
  54.         return self.maxmp
  55.  
  56.     def reduce_mp(self, cost):
  57.         self.mp -= cost
  58.  
  59.     def choose_actions(self):
  60.         i = 1
  61.         print("     Actions")
  62.         for item in self.actions:
  63.             print("     ", str(i) + ":", item)
  64.             i += 1
  65.  
  66.     def magic_choice(self):
  67.         print("     Magic")
  68.         i = 1
  69.         for spell in self.magic:
  70.             print("     ", str(i) + ":", spell.name, " cost : ", spell.cost)
  71.             i += 1
  72.  
  73.     def item_choice(self):
  74.         print("     Items")
  75.         i = 1
  76.         for item in self.items:
  77.             print("     ", str(i) + ":", item["item"].name, " : ", item["item"].des, "(* " + str(item["quantity"]) + ")")
  78.             i += 1
  79.  
  80.     def choose_target(self, Enemy):
  81.         i = 1
  82.         print(Bcolor.BOLD + Bcolor.FAIL + "     TARGET:" + Bcolor.ENDC)
  83.         for enemy in Enemy:
  84.             if enemy.get_hp() != 0:
  85.                 print("             " + str(i) + " :" + enemy.name)
  86.                 i += 1
  87.         choice = int(input("    Choose Target: ")) - 1
  88.         return choice
  89.  
  90.     def enemy_stat(self):
  91.         hp_bar = ""
  92.         bar_health = (self.hp / self.maxhp) * 100 /2
  93.         while bar_health > 0:
  94.             hp_bar += "█"
  95.             bar_health -= 1
  96.         while len(hp_bar) < 50:
  97.             hp_bar += " "
  98.  
  99.         hp_string = str(self.hp) + "/" + str(self.maxhp)  # maintain the length of the HP/maxHP string to a constant
  100.         current_hp = ""
  101.         if len(hp_string) < 11:
  102.             decrease = 11 - len(hp_string)
  103.             while decrease > 0:
  104.                 current_hp += " "
  105.                 decrease -= 1
  106.             current_hp += hp_string
  107.         else:
  108.             current_hp = hp_string
  109.         print("                                     __________________________________________________")
  110.         print(Bcolor.BOLD + str( self.name) + "  " + current_hp + "                  |" + Bcolor.FAIL + hp_bar + Bcolor.ENDC + "|            " + Bcolor.ENDC)
  111.  
  112.  
  113.     def g_s(self):            # Display the stats of the Player
  114.  
  115.         hp_bar = ""           # Display the remaining HP in green colour
  116.         bar_health = (self.hp / self.maxhp) * 100 / 4
  117.         while bar_health > 0:
  118.             hp_bar += "█"
  119.             bar_health -= 1
  120.         while len(hp_bar) < 25:
  121.             hp_bar += " "
  122.  
  123.         mp_bar = ""           # Display the remaining MP in green colour
  124.         bar_magic = (self.mp / self.maxmp) * 100 / 10
  125.         while bar_magic > 0:
  126.             mp_bar += "█"
  127.             bar_magic -= 1
  128.         while len(mp_bar) < 10:
  129.              mp_bar += " "
  130.  
  131.         hp_string = str(self.hp) + "/" + str(self.maxhp)       # maintain the length of the HP/maxHP string to a constant
  132.         current_hp = ""
  133.         if len(hp_string) < 9:
  134.             decrease = 9 - len(hp_string)
  135.             while decrease > 0:
  136.                 current_hp += " "
  137.                 decrease -= 1
  138.             current_hp += hp_string
  139.         else:
  140.             current_hp = hp_string
  141.  
  142.         mp_string = str(self.mp) + "/" + str(self.maxmp)
  143.         current_mp = ""
  144.         if len(mp_string) < 7:
  145.             dec = 7 - len(mp_string)
  146.             while dec > 0:
  147.                 current_mp += " "
  148.                 dec -= 1
  149.             current_mp += mp_string
  150.         else:
  151.             current_mp = mp_string
  152.  
  153.         print("                                   _________________________                 __________")
  154.         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 + "|")
  155.  
  156.     def enemy_spell(self):
  157.         m_c = random.randrange(0, len(self.magic))
  158.         spell = self.magic[m_c]
  159.         m_d = spell.gen_dm()
  160.  
  161.         pct = self.hp / self.maxhp * 100
  162.  
  163.         if self.mp < spell.cost or spell.type == "w" and pct > 50:
  164.             self.enemy_spell()
  165.         else:
  166.             return spell, m_d
Add Comment
Please, Sign In to add comment