Code

Code

Maxim
  1. import os
  2. import random
  3.  
  4. char_race = None
  5. char_role = None
  6. char_name = None
  7.  
  8. # Perks
  9. regeneration = False
  10. berserk = False
  11.  
  12.  
  13. def clear():
  14.    return os.system('cls' if os.name == 'nt' else 'clear')
  15.  
  16.  
  17. def name_input():
  18.    global char_name
  19.   char_name = input('Enter your character name.\n')
  20.   clear()
  21.  
  22.  
  23. def race_select():
  24.    print('Choose character race')
  25.    print('(H)uman, (O)rc, (E)lf')
  26.   need_selection = True
  27.    global char_race
  28.    while need_selection:
  29.     race = input()
  30.      if race.lower() == 'h':
  31.       char_race = 'Human'
  32.       player.max_hp = 45
  33.       player.dexterity = 10
  34.       player.strength = 10
  35.       player.intelligence = 10
  36.       need_selection = False
  37.      elif race.lower() == 'o':
  38.       char_race = 'Orc'
  39.       player.max_hp = 65
  40.       player.dexterity = 5
  41.       player.strength = 20
  42.       player.intelligence = 5
  43.       need_selection = False
  44.        global regeneration
  45.       regeneration = True
  46.      elif race.lower() == 'e':
  47.       char_race = 'Elf'
  48.       player.max_hp = 30
  49.       player.dexterity = 20
  50.       player.strength = 5
  51.       player.intelligence = 5
  52.       need_selection = False
  53.      else:
  54.        print('Wrong race')
  55.   clear()
  56.  
  57.  
  58. def role_select():
  59.    print('Choose character role')
  60.    print('(P)aladin, (B)erserk, (M)age')
  61.   need_selection = True
  62.    global char_role
  63.    while need_selection:
  64.     role = input()
  65.      if role.lower() == 'p':
  66.       char_role = 'Paladin'
  67.       player.hp = player.hp + 10
  68.       player.mana = player.intelligence * 1.5
  69.       need_selection = False
  70.      elif role.lower() == 'b':
  71.       char_role = 'Berserk'
  72.       player.hp = player.hp + 25
  73.       player.mana = player.intelligence * 0.5
  74.       need_selection = False
  75.        global berserk
  76.       berserk = True
  77.      elif role.lower() == 'm':
  78.       char_role = 'Mage'
  79.       player.hp = player.hp + 5
  80.       player.mana = player.intelligence * 2.5
  81.       need_selection = False
  82.      else:
  83.        print('Wrong role')
  84.   clear()
  85.  
  86.  
  87. def action():
  88.   player.mana = player.intelligence * 0.3
  89.    if regeneration:
  90.     player.hp = player.hp + player.max_hp / 100 * 1
  91.  
  92.  
  93. def gameplay():
  94.   player.hp = player.max_hp
  95.    while player.hp > 0:
  96.     clear()
  97.      print('You are', char_name + ', ', char_race, char_role + '.')
  98.      print('Your current stats are:', player.strength, 'STR,', player.dexterity, 'DEX, ', player.intelligence,
  99.         'INT.')
  100.      print('You have', str(player.hp) + '/' + str(player.max_hp), 'HP and', player.mana, 'MP.')
  101.      if regeneration:
  102.        print('You health slowly regenerate.')
  103.      print('You see a rat. it have', str(rat.hp) + '/' + str(rat.max_hp), 'HP.')
  104.     action_check = input('(A)ttack, (D)efend, (M)agic \n')
  105.      if action_check.lower() == 'a':
  106.       rat.hp = rat.hp - player.atk
  107.       player.hp = player.hp - rat.atk
  108.       action()
  109.      elif action_check.lower() == 'd':
  110.        if berserk:
  111.         clear()
  112.          print('You are unable to defend since you are berserk')
  113.          input()
  114.        else:
  115.         player.hp = player.hp - rat.atk / 2
  116.  
  117.  
  118. class LivingCreature:
  119.    def __init__(self, name, description, hp, max_hp, atk):
  120.      self.name = name
  121.      self.description = description
  122.      self.hp = hp
  123.      self.max_hp = max_hp
  124.      self.atk = atk
  125.  
  126.  
  127. class Enemy(LivingCreature):
  128.   hostile = True
  129.  
  130.  
  131. rat = Enemy(name='Rat', description='Just a rat.', hp=15, max_hp=15, atk=random.randint(3, 6))
  132. goblin = Enemy(name='Goblin', description='Just a goblin', hp=25, max_hp=25, atk=random.randint(5, 8))
  133.  
  134.  
  135. class Player(LivingCreature):
  136.   exp = 0
  137.   dexterity = 0
  138.   intelligence = 0
  139.   strength = 0
  140.   mana = 0
  141.  
  142.  
  143. player = Player(name='', description='This is you', hp=50, max_hp=50, atk=5)
  144.  
  145. name_input()
  146. race_select()
  147. role_select()
  148. gameplay()
  149. clear()
  150. print('You are dead. Please come again!')


Report Page