comparison gamelib/tests/repl_game.py @ 80:a40a76012bd7

Refactor message handling so we can deal with in the gui
author Neil Muller <drnlmuller@gmail.com>
date Wed, 09 May 2012 12:08:44 +0200
parents 52913ba12988
children e4f9513c9dd0
comparison
equal deleted inserted replaced
79:8d1cf0cbe5e1 80:a40a76012bd7
1 from gamelib.gamestate import Game 1 from gamelib.gamestate import Game
2 from gamelib.constants import SUCCESS, FAILURE, NEW_SCIENCE, NEW_SCHEMATIC
2 3
3 4
4 class ReplGame(object): 5 class ReplGame(object):
5 def __init__(self, init_data=None): 6 def __init__(self, init_data=None):
6 self.game = Game(init_data=init_data) 7 self.game = Game(init_data=init_data)
60 for i in missions] 61 for i in missions]
61 research_list = [self.science[i - 1] for i in research_list] 62 research_list = [self.science[i - 1] for i in research_list]
62 self.game.cur_allocation.extend(research_list) 63 self.game.cur_allocation.extend(research_list)
63 self.game.cur_missions.extend(missions) 64 self.game.cur_missions.extend(missions)
64 print "-" * 10, "RESULTS", "-" * 31 65 print "-" * 10, "RESULTS", "-" * 31
65 self.game.end_turn() 66 messages = self.game.end_turn()
67 for msg_type, msg in messages:
68 if msg_type == NEW_SCIENCE or msg_type == NEW_SCHEMATIC:
69 print msg
70 elif msg_type == FAILURE:
71 print 'Mission failure: %s' % msg
72 elif msg_type == SUCCESS:
73 print 'Success: %s' % msg
74 else:
75 print 'Unhandled result %d: %s' % (msg_type, msg)
66 self._begin_turn() 76 self._begin_turn()