Code
Maxim
- import os
- import random
-
- char_race = None
- char_role = None
- char_name = None
-
- # Perks
- regeneration = False
- berserk = False
-
-
- def clear():
- return os.system('cls' if os.name == 'nt' else 'clear')
-
-
- def name_input():
- global char_name
- char_name = input('Enter your character name.\n')
- clear()
-
-
- def race_select():
- print('Choose character race')
- print('(H)uman, (O)rc, (E)lf')
- need_selection = True
- global char_race
- while need_selection:
- race = input()
- if race.lower() == 'h':
- char_race = 'Human'
- player.max_hp = 45
- player.dexterity = 10
- player.strength = 10
- player.intelligence = 10
- need_selection = False
- elif race.lower() == 'o':
- char_race = 'Orc'
- player.max_hp = 65
- player.dexterity = 5
- player.strength = 20
- player.intelligence = 5
- need_selection = False
- global regeneration
- regeneration = True
- elif race.lower() == 'e':
- char_race = 'Elf'
- player.max_hp = 30
- player.dexterity = 20
- player.strength = 5
- player.intelligence = 5
- need_selection = False
- else:
- print('Wrong race')
- clear()
-
-
- def role_select():
- print('Choose character role')
- print('(P)aladin, (B)erserk, (M)age')
- need_selection = True
- global char_role
- while need_selection:
- role = input()
- if role.lower() == 'p':
- char_role = 'Paladin'
- player.hp = player.hp + 10
- player.mana = player.intelligence * 1.5
- need_selection = False
- elif role.lower() == 'b':
- char_role = 'Berserk'
- player.hp = player.hp + 25
- player.mana = player.intelligence * 0.5
- need_selection = False
- global berserk
- berserk = True
- elif role.lower() == 'm':
- char_role = 'Mage'
- player.hp = player.hp + 5
- player.mana = player.intelligence * 2.5
- need_selection = False
- else:
- print('Wrong role')
- clear()
-
-
- def action():
- player.mana = player.intelligence * 0.3
- if regeneration:
- player.hp = player.hp + player.max_hp / 100 * 1
-
-
- def gameplay():
- player.hp = player.max_hp
- while player.hp > 0:
- clear()
- print('You are', char_name + ', ', char_race, char_role + '.')
- print('Your current stats are:', player.strength, 'STR,', player.dexterity, 'DEX, ', player.intelligence,
- 'INT.')
- print('You have', str(player.hp) + '/' + str(player.max_hp), 'HP and', player.mana, 'MP.')
- if regeneration:
- print('You health slowly regenerate.')
- print('You see a rat. it have', str(rat.hp) + '/' + str(rat.max_hp), 'HP.')
- action_check = input('(A)ttack, (D)efend, (M)agic \n')
- if action_check.lower() == 'a':
- rat.hp = rat.hp - player.atk
- player.hp = player.hp - rat.atk
- action()
- elif action_check.lower() == 'd':
- if berserk:
- clear()
- print('You are unable to defend since you are berserk')
- input()
- else:
- player.hp = player.hp - rat.atk / 2
-
-
- class LivingCreature:
- def __init__(self, name, description, hp, max_hp, atk):
- self.name = name
- self.description = description
- self.hp = hp
- self.max_hp = max_hp
- self.atk = atk
-
-
- class Enemy(LivingCreature):
- hostile = True
-
-
- rat = Enemy(name='Rat', description='Just a rat.', hp=15, max_hp=15, atk=random.randint(3, 6))
- goblin = Enemy(name='Goblin', description='Just a goblin', hp=25, max_hp=25, atk=random.randint(5, 8))
-
-
- class Player(LivingCreature):
- exp = 0
- dexterity = 0
- intelligence = 0
- strength = 0
- mana = 0
-
-
- player = Player(name='', description='This is you', hp=50, max_hp=50, atk=5)
-
- name_input()
- race_select()
- role_select()
- gameplay()
- clear()
- print('You are dead. Please come again!')