def __init__(self, playerlist): self.playerlist = playerlist self.registry = GameRegistry() self.assets = ListOfAssets.genListOfAssets(self.registry) self.phase = WaitingPhase(self) self.turns = {}
class GameContext: def __init__(self, playerlist): self.playerlist = playerlist self.registry = GameRegistry() self.assets = ListOfAssets.genListOfAssets(self.registry) self.phase = WaitingPhase(self) self.turns = {} def getAssetSet(self): return self.assets def getRegistry(self): return self.registry def getCurrentPhase(self): return GamePhase(self) def getAllDTOShips(self, my_playernum): return [x.to_dto() for x in self.registry.getAllByType(Unit)] def _register_turn(self, turn_number, turn): self.turns[turn_number] = turn def getTurnAttackResults(self, number): return self.turns[number].attack.getResults() def getTurnMoveResults(self, number): return self.turns[number].move.getResults() # Passthrough to phase def addPlayerMove(self, action_order, calling_player): x = self.phase.addPlayerMove(action_order, calling_player) self.phase = self.phase.getNextPhase() return x def getPlayerMoveList(self, calling_player): x = self.phase.getPlayerMoveList(calling_player) self.phase = self.phase.getNextPhase() return x def getPlayerMove(self, move_id, calling_player): x = self.phase.getPlayerMove(move_id, calling_player) self.phase = self.phase.getNextPhase() return x def deletePlayerMove(self, move_id, calling_player): x = self.phase.deletePlayerMove(move_id, calling_player) self.phase = self.phase.getNextPhase() return x def setShipPlacement(self, ship_place_list, calling_player): x = self.phase.setShipPlacement(ship_place_list, calling_player) self.phase = self.phase.getNextPhase() return x def getGameProgress(self, calling_player): x = self.phase.getGameProgress(calling_player) self.phase = self.phase.getNextPhase() return x def setReady(self, player_num, val): x = self.phase.setReady(player_num, val) self.phase = self.phase.getNextPhase() return x
__all__ = ["uno", "oldmaid", "registry"] from registry import GameRegistry from uno import UnoGameLogic from oldmaid import OldMaidGameLogic GameRegistry.register_game(UnoGameLogic) GameRegistry.register_game(OldMaidGameLogic)