battleman.py: Implemented iterating over initiative order, tracking rounds, etc

This commit is contained in:
Anna Rose 2012-03-22 18:07:25 -04:00
parent 36502d63f8
commit e6e22d775c

View File

@ -178,7 +178,7 @@ class Battle():
self.combatant_hash = {} self.combatant_hash = {}
self.groups = [] self.groups = []
self.current = None self.current = None
self.round = -1 self.round = None
def __str__(self): def __str__(self):
@ -264,8 +264,21 @@ class Battle():
def next_combatant(self): def next_combatant(self):
print('Sorry, this is still a stub function.') if not self.validate_started():
return
g = self.get_current_group() g = self.get_current_group()
g.end_turn()
self.current += 1
if self.current >= len(self.groups):
self.current = 0
self.round += 1
print('Beginning round {}'.format(self.round))
g = self.get_current_group()
g.begin_turn()
def deal_damage(self, index, amount): def deal_damage(self, index, amount):
@ -273,6 +286,13 @@ class Battle():
c.damage(amount) c.damage(amount)
def validate_started(self):
if not self.is_started():
print('Error: you can only run this command after starting the battle')
return False
return True
battle = Battle() battle = Battle()
def main(): def main():
@ -331,12 +351,8 @@ def do_prompt():
def do_damage(): def do_damage():
if not battle.is_started():
print('Error: you can only run this command after starting the battle')
return
print battle.list_combatants() print battle.list_combatants()
index = input_int('choose combatant', battle.get_current_group().members[0].index) index = input_int('choose combatant')
amount = input_int('damage') amount = input_int('damage')
battle.deal_damage(index, amount) battle.deal_damage(index, amount)