From 9c60ed4d9c6aee0e3bee6778535ae41b74c59ad7 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Wed, 21 Mar 2012 18:00:57 -0400 Subject: [PATCH] battleman.py: Fixed a very silly error with command parsing, and factored out some ugly input handling code to a lib function --- battleman.py | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/battleman.py b/battleman.py index a8f2a56..907f15e 100755 --- a/battleman.py +++ b/battleman.py @@ -17,20 +17,10 @@ class CombatGroup(): @classmethod def from_input(cls): name = raw_input("Name: ") - hp = int(raw_input("hp: ")) - init_mod = int(raw_input("init mod: ")) - - ap = raw_input("action points [0] ") - if ap: - ap = int(ap) - else: - ap = 0 - - surges = raw_input("surges [0]: ") - if surges: - surges = int(surges) - else: - surges = 0 + hp = input_int('hp') + init_mod = input_int('init mod') + ap = input_int('action points', 0) + surges = input_int('healing surges', 0) recharges = [] recharge = '-1' @@ -41,11 +31,7 @@ class CombatGroup(): else: recharges.append(recharge) - count = raw_input("count [1]: ") - if count: - count = int(count) - else: - count = 0 + count = input_int('count', 1) # Now make the combatants... members = [] @@ -150,30 +136,27 @@ def main(): def do_prompt(): comm = raw_input('> ') - # debug - print ('|' + comm + '|') - - if 'comm' == '?': + if comm == '?': do_help() - elif 'comm' == 'a': + elif comm == 'a': print('Sorry, this is still a stub function.') - elif 'comm' == 'l': + elif comm == 'l': do_list_combatants() - elif 'comm' == 'b': + elif comm == 'b': do_begin_battle() - elif 'comm' == 'd': + elif comm == 'd': print('Sorry, this is still a stub function.') - elif 'comm' == 'h': + elif comm == 'h': print('Sorry, this is still a stub function.') - elif 'comm' == 's': + elif comm == 's': print('Sorry, this is still a stub function.') - elif 'comm' == 'c': + elif comm == 'c': print('Sorry, this is still a stub function.') - elif 'comm' == 'r': + elif comm == 'r': print('Sorry, this is still a stub function.') - elif 'comm' == 'n': + elif comm == 'n': print('Sorry, this is still a stub function.') - elif 'comm' == 'w': + elif comm == 'w': print('Sorry, this is still a stub function.')