def enterScoreMatch(self): sortedByDistance = [] for avId in self.avIdList: index = self.avIdList.index(avId) pos = Point3(*self.finalEndingPositions[index]) pos.setZ(0) sortedByDistance.append((avId, pos.length())) def compareDistance(x, y): if x[1] - y[1] > 0: return 1 elif x[1] - y[1] < 0: return -1 else: return 0 sortedByDistance.sort(cmp=compareDistance) self.scoresAsList = [] totalPointsAdded = 0 for index in xrange(len(self.avIdList)): pos = Point3(*self.finalEndingPositions[index]) pos.setZ(0) length = pos.length() points = length / IceGameGlobals.FarthestLength * (IceGameGlobals.PointsInCorner - IceGameGlobals.PointsDeadCenter[self.numPlayers]) points += IceGameGlobals.PointsDeadCenter[self.numPlayers] self.notify.debug('length = %s points=%s avId=%d' % (length, points, avId)) avId = self.avIdList[index] bonusIndex = 0 for sortIndex in xrange(len(sortedByDistance)): if sortedByDistance[sortIndex][0] == avId: bonusIndex = sortIndex bonusIndex += 4 - len(self.avIdList) pointsToAdd = int(points + 0.5) + IceGameGlobals.BonusPointsForPlace[bonusIndex] totalPointsAdded += pointsToAdd self.scoreDict[avId] += pointsToAdd self.scoresAsList.append(self.scoreDict[avId]) self.curMatch += 1 self.curRound = 0 self.sendUpdate('setScores', [self.curMatch, self.curRound, self.scoresAsList]) self.sendUpdate('setNewState', ['scoring']) def allToonsScoringMovieDone(self = self): self.notify.debug('allToonsScoringMovieDone') if self.curMatch == IceGameGlobals.NumMatches: self.gameFSM.request('finalResults') else: self.gameFSM.request('waitClientsChoices') def handleTimeout(avIds, self = self): self.notify.debug('handleTimeout: avatars %s did not report "done"' % avIds) if self.curMatch == IceGameGlobals.NumMatches: self.gameFSM.request('finalResults') else: self.gameFSM.request('waitClientsChoices') scoreMovieDuration = IceGameGlobals.FarthestLength * IceGameGlobals.ExpandFeetPerSec scoreMovieDuration += totalPointsAdded * IceGameGlobals.ScoreCountUpRate self.scoringMovieDoneBarrier = ToonBarrier('waitScoringMovieDone', self.uniqueName('waitScoringMovieDone'), self.avIdList, scoreMovieDuration + MinigameGlobals.latencyTolerance, allToonsScoringMovieDone, handleTimeout)
def enterPlay(self): self.notify.debug('enterPlay') def allToonsDone(self = self): self.notify.debug('allToonsDone') self.sendUpdate('setEveryoneDone') if not PairingGameGlobals.EndlessGame: self.gameOver() def handleTimeout(avIds, self = self): self.notify.debug('handleTimeout: avatars %s did not report "done"' % avIds) self.setGameAbort() self.gameDuration = PairingGameGlobals.calcGameDuration(self.getDifficulty()) self.doneBarrier = ToonBarrier('waitClientsDone', self.uniqueName('waitClientsDone'), self.avIdList, self.gameDuration + MinigameGlobals.latencyTolerance, allToonsDone, handleTimeout)
def enterScoreMatch(self): """Showing the clients final score from the 3 rounds.""" #self.scoreCopy = self.scoreDict.deepCopy() sortedByDistance = [] for avId in self.avIdList: # center is 0,0,0, so distance is pos.length() index = self.avIdList.index(avId) pos = Point3(*self.finalEndingPositions[index]) pos.setZ(0) sortedByDistance.append((avId, pos.length())) def compareDistance(x, y): if x[1] - y[1] > 0: return 1 elif x[1] - y[1] < 0: return -1 else: return 0 sortedByDistance.sort(key=functools.cmp_to_key(compareDistance)) self.scoresAsList = [] totalPointsAdded = 0 for index in range(len(self.avIdList)): # since the center is at 0,0,0 just query the length pos = Point3(*self.finalEndingPositions[index]) pos.setZ(0) length = pos.length() points = length / IceGameGlobals.FarthestLength * \ (IceGameGlobals.PointsInCorner - \ IceGameGlobals.PointsDeadCenter[self.numPlayers]) points += IceGameGlobals.PointsDeadCenter[self.numPlayers] self.notify.debug('length = %s points=%s avId=%d' % (length, points, avId)) avId = self.avIdList[index] bonusIndex = 0 for sortIndex in range(len(sortedByDistance)): if sortedByDistance[sortIndex][0] == avId: bonusIndex = sortIndex bonusIndex += 4 - len(self.avIdList) pointsToAdd = int( points + 0.5) + IceGameGlobals.BonusPointsForPlace[bonusIndex] totalPointsAdded += pointsToAdd self.scoreDict[avId] += pointsToAdd self.scoresAsList.append(self.scoreDict[avId]) self.curMatch += 1 self.curRound = 0 self.sendUpdate('setScores', [self.curMatch, self.curRound, self.scoresAsList]) self.sendUpdate('setNewState', ['scoring']) # set up a barrier to wait for the 'game done' msgs def allToonsScoringMovieDone(self=self): self.notify.debug('allToonsScoringMovieDone') if self.curMatch == IceGameGlobals.NumMatches: self.gameFSM.request('finalResults') else: self.gameFSM.request('waitClientsChoices') def handleTimeout(avIds, self=self): self.notify.debug( 'handleTimeout: avatars %s did not report "done"' % avIds) #self.setGameAbort() if self.curMatch == IceGameGlobals.NumMatches: self.gameFSM.request('finalResults') else: self.gameFSM.request('waitClientsChoices') scoreMovieDuration = IceGameGlobals.FarthestLength * IceGameGlobals.ExpandFeetPerSec #scoreMovieDuration += len(self.avIdList) * IceGameGlobals.ScoreIncreaseDuration scoreMovieDuration += totalPointsAdded * IceGameGlobals.ScoreCountUpRate self.scoringMovieDoneBarrier = ToonBarrier( 'waitScoringMovieDone', self.uniqueName('waitScoringMovieDone'), self.avIdList, scoreMovieDuration + MinigameGlobals.latencyTolerance, allToonsScoringMovieDone, handleTimeout) pass