-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
117 lines (97 loc) · 2.87 KB
/
model.py
File metadata and controls
117 lines (97 loc) · 2.87 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import numpy as np
class Character:
def __init__(
self,
name: str,
hit_points: int,
armor: int,
weapon1: "Weapon",
weapon2: "Weapon",
desc: str,
) -> None:
self.name = name
self.hit_points = hit_points
self.armor = armor
self.weapon1 = weapon1
self.weapon2 = weapon2
self.desc = desc
self.is_alive = True
def __str__(self) -> str:
return (
f"\n{self.name}:\n"
f"{self.desc}\n\n"
f"\t- Armor Class (AC): {self.armor}\n"
f"\t- Hit Points (HP): {self.hit_points}\n"
f"\t- weapon 1: {self.weapon1.name}\n"
f"\t- weapon 2: {self.weapon2.name}\n"
)
def __repr__(self) -> str:
return f"<Character: {self.name}>"
def attack(self, other: "Character", weapon: "Weapon") -> int:
"""Rolls the damage dice and aplly them to the target
Args:
other (Character): The targeted object
weapon (Weapon): The weapon object used to attack
Returns:
int: Rolled damages
"""
damage_dice = weapon.damage
damages = self.roll_damage(damage_dice)
other.damage(damages)
return damages
def roll_damage(self, damage_dice: str) -> int:
"""Rolls damage dice
Args:
damage_dice (str): Description of the dice (ie: 1d4, 2d10 etc...)
Returns:
int: Damages
"""
number_of_dice, value_of_dice = damage_dice.split("d")
rolls = np.random.randint(
1,
int(value_of_dice) + 1,
int(number_of_dice),
)
total_damage = np.sum(rolls)
return total_damage
def damage(self, damages: int) -> None:
"""Apply damages to the object
Args:
damages (int): value of the damages
"""
if self.hit_points > damages:
self.hit_points -= damages
return None
self.hit_points = 0
self.is_alive = False
class Weapon:
def __init__(
self,
name: str,
damage: str,
category: str,
desc: str,
) -> None:
self.name = name
self.damage = damage
self.category = category
self.desc = desc
def __str__(self) -> str:
return f"{self.name}: {self.damage} damage.\n{self.desc}\n"
def __repr__(self) -> str:
return f"<weapon: {self.name}>"
class Monster(Character):
def __init__(
self,
name: str,
hit_points: int,
armor: int,
weapon1: Weapon,
weapon2: Weapon,
difficulty: int,
desc: str,
) -> None:
super().__init__(name, hit_points, armor, weapon1, weapon2, desc)
self.difficulty = difficulty
def __repr__(self) -> str:
return f"<Monster: {self.name}>"