import random class Dado(random.Random): FIRST_FACE = 1 LAST_FACE = 6 def __init__(self,seed=None): random.Random.__init__(self,seed) self.__ultimo_lancio = self.lancio() def lancio(self): return self.randint(self.FIRST_FACE,self.LAST_FACE) def getUltimoLancio(self): return self.__ultimo_lancio def __str__(self): return "[" + self.__ultimo_lancio.__str__() + "]" ################# LAST EDITED ON 3 dec 2007 - BEGIN class PlayGameHandler: """ Manage games and player. Singleton pattern, allows only one instance. """ __currentGame = None @staticmethod def createNewDefaultGame(): """ Create and initialize new default game. """ PlayGameHandler.__currentGame = GameFactory.getDefaultGame() @staticmethod def newHumanPlayerForCurrentGame(name, colour): """ New human player for the current game """ PlayGameHandler.__currentGame.newHumanPlayer(name,colour) @staticmethod def newAIPlayerForCurrentGame(name, colour): """ New AI player for the current game """ pass # wishlist @staticmethod def startCurrentGame(): """ Start the game """ PlayGameHandler.__currentGame.start() class GameFactory: """ Create and initialize different kind of Game, in according to the following patterns: Singleton, Factory, Pure Fabrication, Creator, Information Expert, Low Coupling, High Coesion etc. Every "get" method returns an abstract Game class. """ @staticmethod def getDefaultGame(): """ Create and return a DefaultGame object """ return DefaultGame() @staticmethod def getCustomGame(): """ Create and return a CustomGame object """ return CustomGame() class Game: """ Abstract class wich defines a general game. """ def __init__(self): self.__players = dict() # initialize player dict pass # todo def newHumanPlayer(self,name,colour): self.__players[colour] = PlayerFactory.getHumanPlayer(name,colour) def start(self): abstract class DefaultGame(Game): def __init__(self): Game.__init__(self) def start(self): pass class CustomGame(Game): def start(self): pass class PlayerFactory: """ Create and initialize players, in according to the following patterns: Singleton, Factory, Pure Fabrication, Polymorphism, Creator, Information Expert, Low Coupling, High Coesion etc. Every "get" method returns an abstract Player class. Shall be 2 kind of players: human and artifial intelligence. """ @staticmethod def getHumanPlayer(name,colour): """ Return an HumanPlayer class object """ return HumanPlayer(name, colour) class Player(): """ Class for players. Must be abstract! """ def __init__(self, name, colour): self.__name = name self.__colour = colour class HumanPlayer(Player): def __init__(self, name, colour): Player.__init__(self, name, colour) pass class AIPlayer(Player): """ Wishlist """ pass ################# LAST EDITED ON 3 dec 2007 - END