From e6e22d775ca1fbd54ae94c12d8b0dbf42ec7bfc5 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Thu, 22 Mar 2012 18:07:25 -0400 Subject: [PATCH] battleman.py: Implemented iterating over initiative order, tracking rounds, etc --- battleman.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/battleman.py b/battleman.py index 8612c83..a94416d 100755 --- a/battleman.py +++ b/battleman.py @@ -178,7 +178,7 @@ class Battle(): self.combatant_hash = {} self.groups = [] self.current = None - self.round = -1 + self.round = None def __str__(self): @@ -264,8 +264,21 @@ class Battle(): def next_combatant(self): - print('Sorry, this is still a stub function.') + if not self.validate_started(): + return + 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): @@ -273,6 +286,13 @@ class Battle(): 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() def main(): @@ -331,12 +351,8 @@ def do_prompt(): 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() - index = input_int('choose combatant', battle.get_current_group().members[0].index) + index = input_int('choose combatant') amount = input_int('damage') battle.deal_damage(index, amount)