-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.py
66 lines (55 loc) · 1.84 KB
/
messages.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
VERBOSE_LEVEL = 2
INDENT = " " * 2
class IO:
turn = 0
hp = 0
target_name = ""
conditions = []
total_damage = {}
log = ""
def reset():
IO.log = ""
IO.total_damage = {}
IO.hp = 0
IO.target_name = ""
IO.conditions = []
def printlog():
d = " + ".join(["%i %s" % (v, k) for k, v in IO.total_damage.items()])
damages = [i for i in IO.total_damage.values()]
total = sum(damages)
if d:
if len(damages) == 1:
total = ""
else:
total = " (total %i) " % total
taken = " %s%s damage dealt, %i HP remaining on target." % (d, total, IO.hp)
else:
taken = ""
if IO.log:
IO.printmsg(IO.log + taken, 2, True, True)
for condition in IO.conditions:
IO.printmsg("-> " + condition, 2, True, False)
#if IO.hp <= 0 and IO.target_name:
# death = "-> %s is dead!" % IO.target_name
# IO.printmsg(death, 2, True, False)
@staticmethod
def center_and_pad(string, padding=":"):
times = int( (72 - len(string) + 2) / 2 )
return "{padding} {string} {padding}".format(padding=padding*times,
string=string)
@staticmethod
def printmsg(message, level, indent=False, print_turn=False):
if indent:
tab = INDENT
else:
tab = ""
""" Set if turn number is shown in action log """
if print_turn:
turn = "Turn %s: " % IO.turn
else:
if indent:
turn = " "*len("Turn %s: " % IO.turn)
else:
turn = ""
if VERBOSE_LEVEL >= level:
print(tab + turn + message)