battleman.py: Refactored combatant printing code, and made it more consistent.
This commit is contained in:
parent
2bd533b27d
commit
9d367b69b6
22
battleman.py
22
battleman.py
|
@ -131,6 +131,7 @@ class Combatant():
|
||||||
|
|
||||||
self.hp -= amount
|
self.hp -= amount
|
||||||
|
|
||||||
|
# fixme - should we change this output?
|
||||||
if self.is_down():
|
if self.is_down():
|
||||||
print('{} ({}) is down!'.format(self.name, self.index))
|
print('{} ({}) is down!'.format(self.name, self.index))
|
||||||
elif self.is_bloodied() and not was_bloodied:
|
elif self.is_bloodied() and not was_bloodied:
|
||||||
|
@ -146,6 +147,7 @@ class Combatant():
|
||||||
|
|
||||||
self.hp = min(self.hp + amount, self.max_hp + self.temp_hp)
|
self.hp = min(self.hp + amount, self.max_hp + self.temp_hp)
|
||||||
|
|
||||||
|
# fixme - should we change this output?
|
||||||
if was_down:
|
if was_down:
|
||||||
print('{} ({}) is conscious.'.format(self.name, self.index))
|
print('{} ({}) is conscious.'.format(self.name, self.index))
|
||||||
if was_bloodied and not self.is_bloodied():
|
if was_bloodied and not self.is_bloodied():
|
||||||
|
@ -162,18 +164,22 @@ class Combatant():
|
||||||
return self.hp <= 0
|
return self.hp <= 0
|
||||||
|
|
||||||
|
|
||||||
def get_health_summary(self):
|
def format_health_summary(self):
|
||||||
bloodied = ''
|
bloodied = ''
|
||||||
|
temp_info = ''
|
||||||
if self.is_bloodied():
|
if self.is_bloodied():
|
||||||
bloodied = ', bloodied'
|
bloodied = ', bloodied'
|
||||||
if len(self.conditions):
|
if len(self.conditions):
|
||||||
bloodied = bloodied + ', '
|
bloodied = bloodied + ', '
|
||||||
|
|
||||||
return '{} hp{}{}'.format(self.hp, bloodied, ', '.join([x.name for x in self.conditions]))
|
if self.temp_hp > 0:
|
||||||
|
temp_info = ', {} temp hp'.format(self.temp_hp)
|
||||||
|
|
||||||
|
return '{} hp{}{}{}'.format(self.hp, temp_info, bloodied, ', '.join([x.name for x in self.conditions]))
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} ({hp} hp)".format(self.name, hp=self.hp)
|
return "{}: {} ({})".format(self.index, self.name, self.format_health_summary())
|
||||||
|
|
||||||
|
|
||||||
def input_str(prompt, default=None, show_default=False, prompt_str=':'):
|
def input_str(prompt, default=None, show_default=False, prompt_str=':'):
|
||||||
|
@ -251,7 +257,7 @@ class Battle():
|
||||||
|
|
||||||
print '\nInitiative Roster:\n'
|
print '\nInitiative Roster:\n'
|
||||||
for g in self.groups:
|
for g in self.groups:
|
||||||
print '{} ({})'.format(g.name, g.init)
|
print '{} ({})'.format(g.name, g.init) # fixme - should we change this output?
|
||||||
print ''
|
print ''
|
||||||
|
|
||||||
self.next_round()
|
self.next_round()
|
||||||
|
@ -264,11 +270,11 @@ class Battle():
|
||||||
|
|
||||||
for g in self.groups:
|
for g in self.groups:
|
||||||
if g.is_solo_group():
|
if g.is_solo_group():
|
||||||
ret = ret + '{}: {}\n'.format(g.members[0].index, g.name)
|
ret = ret + '{}\n'.format(g.members[0])
|
||||||
else:
|
else:
|
||||||
ret = ret + '{}:\n'.format(g.name)
|
ret = ret + '{}:\n'.format(g.name)
|
||||||
for c in g.members:
|
for c in g.members:
|
||||||
ret = ret + '\t{}: {} ({})\n'.format(c.index, c.name, c.get_health_summary())
|
ret = ret + '\t{}\n'.format(c)
|
||||||
|
|
||||||
return ret.rstrip()
|
return ret.rstrip()
|
||||||
|
|
||||||
|
@ -279,11 +285,11 @@ class Battle():
|
||||||
|
|
||||||
g = self.groups[current]
|
g = self.groups[current]
|
||||||
if g.is_solo_group():
|
if g.is_solo_group():
|
||||||
ret = ret + '{}: {}\n'.format(g.members[0].index, g.name)
|
ret = ret + '{}\n'.format(g.members[0])
|
||||||
else:
|
else:
|
||||||
ret = ret + '{}:\n'.format(g.name)
|
ret = ret + '{}:\n'.format(g.name)
|
||||||
for c in g.members:
|
for c in g.members:
|
||||||
ret = ret + '\t{}: {} ({})\n'.format(c.index, c.name, c.get_health_summary())
|
ret = ret + '\t{}\n'.format(c)
|
||||||
|
|
||||||
return ret.rstrip()
|
return ret.rstrip()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user