Skip to content
Browse files

Changing game master nad player interface to keep track of current phase

  • Loading branch information...
1 parent 3ab8a7a commit ad7ae8913015195e4aa4fb04b97376c1551bf50b @elElmo committed
View
13 risk/ai/bots.py
@@ -10,10 +10,15 @@ def __init__(self, title):
def choose_territories(self, board):
raise NotImplementedError
- def take_turn(self, game_master):
+ def reinforce(self, game_master):
self._deploy_reserves(game_master)
+
+ def attack(self, game_master):
self._attack_all_possible_targets(game_master)
+ def fortify(self, game_master):
+ pass
+
def deploy_reserves(self, game_master):
# evenly distributes
territories = game_master.player_territories(self)
@@ -41,8 +46,6 @@ def move_after_attack(self, game_master, origin_name, target_name):
risk.logger.debug("%s now has: %s armies" %(origin_name, origin_armies))
risk.logger.debug("%s now has: %s armies" %(target_name, destination_armies))
-
-
def _attack_all_possible_targets(self, game_master):
territories = game_master.player_territories(self)
for name, territory in territories.iteritems():
@@ -124,8 +127,10 @@ class IanRiskBot(BasicRiskBot):
def __init__(self, title):
BasicRiskBot.__init__(self, "group bot[%s]" % title)
- def take_turn(self, game_master):
+ def reinforce(self, game_master):
self.deploy_reserves(game_master)
+
+ def attack(self, game_master):
self.attack_others(game_master)
def attack_others(self, game_master):
View
3 risk/errors/game_master.py
@@ -7,7 +7,8 @@ def __init__(self, msg):
class NoSuchPlayerError(GameMasterError):
def __init__(self, attempted_player, number_of_players):
- GameMasterError.__init__("attempted to access player: %s but only have" \
+ GameMasterError.__init__(self,
+ "attempted to access player: %s but only have" \
" %s players" % (attempted_player, number_of_players))
class NotEnoughReserves(GameMasterError):
View
19 risk/game_master.py
@@ -12,6 +12,11 @@
from risk.errors.battle import *
from risk.player import HumonRiskPlayer
+REINFORCE_PHASE = 0
+ATTACK_PHASE = 1
+FORTIFY_PHASE = 2
+UNDEFINED_PHASE = 3
+
class GameMaster(object):
_RISK_RULE_STARTING_RESERVES = 40
_DEPLOYS_PER_TURN = 5
@@ -24,6 +29,7 @@ def __init__(self, board, settings, num_players=5):
num_players)
self.board = board
+ self.phase = UNDEFINED_PHASE
# need to setup with settings later
self.ended = False
self.end_turn_callbacks = []
@@ -197,14 +203,21 @@ def _get_player_with_index(self, index):
###########################################################################
## Player actions
#
- @event_action
+ #@event_action
def player_take_turn(self):
self.call_start_turn_callbacks()
+ self.phase = UNDEFINED_PHASE
player = self._get_player_with_index(self._current_player)
player.reserves += len(self.player_territories(player))
- player.take_turn(self)
+ self.phase = REINFORCE_PHASE
+ player.reinforce(self)
+ self.phase = ATTACK_PHASE
+ player.attack(self)
+ self.phase = FORTIFY_PHASE
+ player.fortify(self)
+ self.phase = UNDEFINED_PHASE
- @event_action
+ #@event_action
def player_territories(self, player):
# O(n) lookup
player_territories = {}
View
10 risk/graphics/graphics.py
@@ -111,7 +111,7 @@ def shutdown(*args):
def add_graphic_hooks(game_master):
game_master.add_start_turn_callback(check_picasso_liveness)
- game_master.add_start_turn_callback(show_human_player)
+ #game_master.add_start_turn_callback(show_human_player)
game_master.add_start_turn_callback(delay)
game_master.add_start_turn_callback(check_gui_quit_event)
game_master.add_end_turn_callback(check_gui_quit_event)
@@ -133,10 +133,10 @@ def initialize_territories(picasso, game_master):
def initialize_other_graphic_assets(picasso, game_master):
datastore = Datastore()
- current_player_asset = assets.text.CurrentPlayerAsset(
- 100, 100, game_master)
- picasso.add_asset('4_current_player', current_player_asset)
- datastore.add_entry('current_player', current_player_asset)
+ #current_player_asset = assets.text.CurrentPlayerAsset(
+ # 100, 100, game_master)
+ #picasso.add_asset('4_current_player', current_player_asset)
+ #datastore.add_entry('current_player', current_player_asset)
feedback_asset = assets.text.TextAsset(100, 650,
'choose territory to attack')
datastore.add_entry('attack_feedback', feedback_asset)
View
6 risk/graphics/input.py
@@ -109,8 +109,8 @@ def reinforce_phase(player, game_master):
# state init vector
datastore = Datastore()
picasso = get_picasso()
- reserve_count_asset = ReserveCountAsset(player)
- picasso.add_asset(LAYER, reserve_count_asset)
+ #reserve_count_asset = ReserveCountAsset(player)
+ #picasso.add_asset(LAYER, reserve_count_asset)
# core state machine
disable_enemy_territories(player)
while player.reserves > 0:
@@ -126,7 +126,7 @@ def reinforce_phase(player, game_master):
reinforce_add_army_fail(player, game_master, territory)
# exit state
enable_all_clickables()
- picasso.remove_asset(LAYER, reserve_count_asset)
+ #picasso.remove_asset(LAYER, reserve_count_asset)
def reinforce_add_army(player, game_master, territory, number_of_armies=1):
game_master.player_add_army(player, territory.name, number_of_armies)
View
2 risk/graphics/picasso.py
@@ -96,7 +96,7 @@ def end(self):
self.ended = True
def get_fps_asset(self):
- asset = TextAsset(1050, 16, "%s FPS" % int(self.clock.get_fps()),
+ asset = TextAsset(1000, 16, "%s FPS" % int(self.clock.get_fps()),
(255, 255, 0), 32)
return asset
View
18 risk/graphics/player.py
@@ -20,21 +20,25 @@ class HumonGuiRiskPlayer(HumonRiskPlayer):
def __init__(self, name):
HumonRiskPlayer.__init__(self, name)
- def take_turn(self, game_master):
+ def reinforce(self, game_master):
#self.reserves = 0
#for territory in game_master.player_territories(self).values():
# territory.armies = 100
- picasso = get_picasso()
- phase_asset = TextAsset(400, 600, 'reinforcing...')
- picasso.add_asset(LAYER, phase_asset)
+ #picasso = get_picasso()
+ #phase_asset = TextAsset(400, 600, 'reinforcing...')
+ #picasso.add_asset(LAYER, phase_asset)
risk.logger.debug("starting reinforcement phase")
risk.graphics.input.handle_user_mouse_input(game_master,
reinforce_phase)
+
+ def attack(self, game_master):
risk.logger.debug("starting attack phase")
- phase_asset.render_text('attacking...')
+ #phase_asset.render_text('attacking...')
risk.graphics.input.handle_user_mouse_input(game_master, attack_phase)
+
+ def fortify(self, game_master):
risk.logger.debug("starting fortify phase")
- phase_asset.render_text('fortifying...')
+ #phase_asset.render_text('fortifying...')
risk.graphics.input.handle_user_mouse_input(game_master, fortify_phase)
risk.logger.debug("GUI player finished turn!")
- picasso.remove_asset(LAYER, phase_asset)
+ #picasso.remove_asset(LAYER, phase_asset)
View
13 risk/player/player.py
@@ -16,7 +16,13 @@ def __init__(self, name):
self.is_bot = False
self.reserves = 0
- def take_turn(self, game_master):
+ def reinforce(self, game_master):
+ raise NotImplementedError
+
+ def attack(self, game_master):
+ raise NotImplementedError
+
+ def fortify(self, game_master):
raise NotImplementedError
def choose_territory(self, available):
@@ -31,7 +37,7 @@ def __init__(self, name):
# Python sucks at this, base refers to base class
AbstractRiskPlayer.__init__(self, name)
- def take_turn(self, game_master):
+ def reinforce(self, game_master):
while self.reserves > 0:
print 'player has armies to deploy'
print "%s's territories: " % self.name
@@ -41,8 +47,11 @@ def take_turn(self, game_master):
game_master.player_territories(self))
commands.prompt_user(self, game_master,
reinforce_commands, HumonRiskPlayer._no_more_reserves)
+ def attack(self, game_master):
print "Attack phase, next to enter fortification phase"
commands.prompt_user(self, game_master, attack_commands)
+
+ def fortify(self, game_master):
print "Fortification phase, next to end turn"
commands.prompt_user(self, game_master, fortify_commands)

0 comments on commit ad7ae89

Please sign in to comment.
Something went wrong with that request. Please try again.