-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.py
45 lines (37 loc) · 1.14 KB
/
character.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import random
from combat import Combat
class Character(Combat, object):
attack_limit = 10 # this overrides the attack inheritance and lets the character roll between 1 and 10, giving more opportunities for a "hit" (a number above 4).
experience = 0
base_hit_points = 10
def attack(self):
roll = random.randint(1, self.attack_limit)
if self.weapon == 'sword':
roll += 1
elif self.weapon == 'axe':
roll += 2
return roll > 4
def get_weapon(self):
weapon_choice = input("Weapon ([S]word, [A]xe, [B]ow: ").lower()
if weapon_choice in 'sab':
if weapon_choice == 's':
return 'sword'
elif weapon_choice == 'a':
return 'axe'
else:
return 'bow'
else:
return self.get_weapon()
def __init__(self, **kwargs):
self.name = input("Name: ")
self.weapon = self.get_weapon()
self.hit_points = self.base_hit_points
for key, value in kwargs.items():
setattr(self, key, value)
def __str__(self):
return '{}, HP: {}, XP: {}'.format(self.name, self.hit_points, self.experience)
def rest(self):
if self.hit_points < self.base_hit_points:
self.hit_points += 1
def leveled_up(self):
return self.experience >= 5