本文整理匯總了Python中GameState.init_new方法的典型用法代碼示例。如果您正苦於以下問題:Python GameState.init_new方法的具體用法?Python GameState.init_new怎麽用?Python GameState.init_new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類GameState
的用法示例。
在下文中一共展示了GameState.init_new方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: players
# 需要導入模塊: import GameState [as 別名]
# 或者: from GameState import init_new [as 別名]
class OhHellServer:
"""
Oh Hell server class
Attributes:
serverAddress
address of server
serverPort
port server is listening on
serverSocket
socket that server uses for listening to incoming connections
sockets
list of all sockets maintained by server
players
list of players (Player instances)
numReadyPlayers
number of players ready to play
numPlayers
number of players in game
state
state of game, one of:
REGISTRATION - new game, waiting for all players to register
RESTART - recovering and restarting old game, waiting for players
PLAYING - game is under way
gameState
state of the game, really a history of the hands
trickNums
a list of the num of tricks for each hand to play
numHands
how many hands to play
handNum
the number of the current hand
dealer
the index of the dealer for the current hand
trump
the trump for the current hand
deck
the deck of cards for the current hand
"""
def __init__(self, port = 7000):
"""
Constructor
Parameter:
port - TCP port for server to listen on
"""
self.serverAddress = ''
self.serverPort = port
self.players = []
self.numReadyPlayers = 0
#
# start a brand new game
# Parameter:
# numPlayers - number of players in game
#
def newGame( self, numPlayers ):
print 'New Game of', numPlayers, 'players'
self.gameState = GameState()
self.gameState.init_new(numPlayers, now())
self.state = 'REGISTRATION'
self.findXMLFileName()
self.mainloop(numPlayers)
#
# restart a game
# Parameter:
# fileName - name of file with state of old game (in XML)
#
def restart( self, fileName ):
parser = GameXMLParser()
self.xmlFileName = fileName
self.gameState = parser.parse(fileName)
self.incomingPlayers = self.gameState.getPlayers()
for p in self.incomingPlayers:
self.players.append( Player(None, p[1]) )
self.state = 'RESTART'
self.mainloop(len(self.incomingPlayers))
#
# the main loop for the game
#.........這裏部分代碼省略.........