-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.py
79 lines (65 loc) · 1.98 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
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
"""Character classes for easy character creation."""
import random
from adventurelib import Item
class Character(Item):
"""A generic character class that can speak, die, and more."""
def __init__(
self,
name: str,
description: str,
speech: list = None,
def_name: str = None,
gender: str = None,
health: int = 10,
):
"""Construct a Character object."""
if speech is None:
speech = []
super().__init__(name.title())
self.name = name.title()
self.def_name = def_name.lower() if def_name else f"the {self.name.lower()}"
self.gender = gender
self.description = description
self.health = health
self.speech = speech
self.subject_pronoun = "they"
self.object_pronoun = "it"
def talk(self):
if self.speech:
return random.choice(self.speech)
def die(self, msg: str = "{} died."):
print(msg.format(self.def_name))
def check_dead(self, msg: str = None):
if self.health <= 0:
self.die(msg) if msg else self.die()
return True
class MaleCharacter(Character):
"""A male character."""
def __init__(
self,
name: str,
description: str,
speech: list = None,
def_name: str = None,
health: int = 100,
):
if speech is None:
speech = []
super().__init__(name, def_name, description, speech, "m", health)
self.subject_pronoun = "he"
self.object_pronoun = "him"
class FemaleCharacter(Character):
"""A female character."""
def __init__(
self,
name: str,
description: str,
speech: list = None,
def_name: str = None,
health: int = 100,
):
if speech is None:
speech = []
super().__init__(name, def_name, description, speech, "f", health)
self.subject_pronoun = "she"
self.object_pronoun = "her"