コード例 #1
0
    def IPartialRefreshDisplay(self):
        "Refreshes only the volitile time entries (i.e. a game being played or a completed game)"
        
        gameSelector = ptGUIControlRadioGroup(MarkerGameDlg.dialog.getControlFromTag(kRGMarkerGameSelect))
        curGame = gameSelector.getValue()


        #check a completed game
        if self.lastGame > -1:
            if self.debug:
                print "PARTIAL--LASTGAME!"
            fieldID = self.lastGame * 10 + kMarkerGameFieldStart
            timeTB = ptGUIControlTextBox(MarkerGameDlg.dialog.getControlFromTag(fieldID+kMarkerGameNameFieldOffset))
            gameName = grtzMarkerGames.GetCGZGameName(self.lastGame)

            startTime,bestTime = grtzMarkerGames.GetGameTime(gameName)

            if bestTime >= 0.1:
                tuptime = time.gmtime(bestTime)
                modText = ""

                if self.lastGameScore < bestTime or (self.lastGameScore > 0 and bestTime <= 0):
                    modText = "*"
                    #Kill the timer if we were only awaiting a best game update
                    if curGame == -1:
                        self.updateLevel = kNoRefresh
                if tuptime[2] == 1:
                    ostring = modText+"%02d:%02d:%02d"+modText
                    timeTB.setString(ostring % (tuptime[3],tuptime[4],tuptime[5]))
                else:
                    ostring = modText+"%02d:%02d:%02d:%02d"+modText
                    timeTB.setString(ostring % (tuptime[2]-1,tuptime[3],tuptime[4],tuptime[5]))
            else:
                timeTB.setString("--:--:--")

        #Check the current game
        if curGame > -1:
            if self.debug:
                print "PARTIAL--CURRENT!"
            fieldID = curGame * 10 + kMarkerGameFieldStart
            timeTB = ptGUIControlTextBox(MarkerGameDlg.dialog.getControlFromTag(fieldID+kMarkerGameNameFieldOffset))
            gameName = grtzMarkerGames.GetCGZGameName(curGame)

            startTime,bestTime = grtzMarkerGames.GetGameTime(gameName)
            bestTime = PtGetDniTime() - startTime

            if bestTime == 0:
                timeTB.setString("00:00:00")
            elif bestTime >= 0.1:
                tuptime = time.gmtime(bestTime)
                if tuptime[2] == 1:
                    ostring = "%02d:%02d:%02d"
                    timeTB.setString(ostring % (tuptime[3],tuptime[4],tuptime[5]))
                else:
                    ostring = "%02d:%02d:%02d:%02d"
                    timeTB.setString(ostring % (tuptime[2]-1,tuptime[3],tuptime[4],tuptime[5]))
            else:
                timeTB.setString("--:--:--")
コード例 #2
0
    def IRefreshGamesDisplay(self):
        "refresh the number and best time fields for the games"
        if self.debug:
            print "---->FULL UPDATE!"
        gameSelector = ptGUIControlRadioGroup(
            MarkerGameDlg.dialog.getControlFromTag(kRGMarkerGameSelect))
        curGame = gameSelector.getValue()

        curGameName = grtzMarkerGames.GetCGZGameName(curGame)
        for fieldID in range(kMarkerGameFieldStart, kMarkerGameFieldEnd, 10):
            numTB = ptGUIControlTextBox(
                MarkerGameDlg.dialog.getControlFromTag(
                    fieldID + kMarkerGameNumFieldOffset))
            timeTB = ptGUIControlTextBox(
                MarkerGameDlg.dialog.getControlFromTag(
                    fieldID + kMarkerGameNameFieldOffset))
            gameidx = (fieldID - kMarkerGameFieldStart) / 10
            numTB.setString("%d" % (grtzMarkerGames.GetNumMarkers(gameidx)))
            gameName = grtzMarkerGames.GetCGZGameName(gameidx)

            startTime, bestTime = grtzMarkerGames.GetGameTime(gameName)
            showZeros = 0
            if curGameName == gameName:
                # use the currentTime
                bestTime = PtGetDniTime() - startTime
                showZeros = 1

            if showZeros == 1 and bestTime == 0:
                timeTB.setString("00:00:00")
            elif bestTime >= 0.1:
                tuptime = time.gmtime(bestTime)
                preText = ""
                postText = ""

                #Check for best game....
                if self.lastGame == gameidx:
                    if self.lastGameScore < bestTime or (self.lastGameScore > 0
                                                         and bestTime <= 0):
                        preText = "*"
                        postText = "*"
                if tuptime[2] == 1:
                    ostring = preText + "%02d:%02d:%02d" + postText
                    timeTB.setString(ostring %
                                     (tuptime[3], tuptime[4], tuptime[5]))
                else:
                    ostring = preText + "%02d:%02d:%02d:%02d" + postText
                    timeTB.setString(
                        ostring %
                        (tuptime[2] - 1, tuptime[3], tuptime[4], tuptime[5]))
            else:
                timeTB.setString("--:--:--")
コード例 #3
0
    def stopCGZGame(self):
        "Call this to stop a CGZ marker game, it automatically checks for win conditiions"
        gameNum = self.gameData.data['CGZGameNum']
        #check for End Game
        finishTime = 0.0
        if self.gameData.data['numMarkers'] == self.gameData.data[
                'numCapturedMarkers'] and self.gameData.data['numMarkers'] > 0:
            PtDebugPrint(
                "DEBUG: xMarkerGameManager.stopCGZGame():\tGame Completed!  ---Checking for new best score---"
            )
            endTime = PtGetDniTime()
            startTime, bestTime = grtzMarkerGames.GetGameTime(
                grtzMarkerGames.GetCGZGameName(gameNum))
            finishTime = endTime - startTime

        #Update Score Display
        PtDebugPrint(
            "DEBUG: xMarkerGameManager.stopCGZGame(): Attempting to Register score: %s for game: %s"
            % (finishTime, gameNum))
        grtzMarkerGames.UpdateScore(self.gameData.data['CGZGameNum'], 0,
                                    finishTime)

        #Delete Game from the server
        try:
            PtDebugPrint(
                "DEBUG: xMarkerGameManager.stopCGZGame():\t----Dispatching stop CGZ Marker Game----"
            )
            server = GetGameClient(self.gameData.data['svrGameClientID'])
            server.deleteGame()
        except:
            #if we could not process previous statements, we had better clean up a little!
            self.gameData.initDefaultValues()
            self.gameData.save()
コード例 #4
0
    def createCGZMarkerGame(self, gameNum):
        "Initiates the CGZ Marker Game creation process"
        PtDebugPrint(
            "DEBUG: xMarkerGame.createCGZMarkerGame():\tDispatching a new CGZ marker game #%s"
            % gameNum)
        #Get existing game....  We're starting a new game, we better get rid of the old one!
        existingGame = self.gameData.data['svrGameClientID']
        templateID = ""
        if existingGame != self.gameData.default['svrGameClientID']:
            #We've got to load the game again!
            #We must save the templateID as it will not be xmitted again!
            templateID = self.gameData.data['svrGameTemplateID']

        #To be safe, we should delete any existing markers in the marker manager display.  We'll load them later...
        mrkrDisplay = ptMarkerMgr()
        mrkrDisplay.removeAllMarkers()

        PtDebugPrint(
            "xMarkerGameManager.CreateCGZMarkerGame():\tCreating Marker Game Number: %i"
            % gameNum)
        if gameNum < 0 or gameNum > len(grtzMarkerGames.mgs):
            PtDebugPrint(
                "xMarkerGameManager.CreateCGZMarkerGame():\tCannot create game: Invalid Game Number: %s"
                % gameNum)
            return

        #Save some important settings!
        self.gameData.initDefaultValues()
        self.gameData.data[
            'CGZGameNum'] = gameNum  #store this as there's not much hope of us getting it later....
        self.gameData.data['svrGameTemplateID'] = templateID
        self.gameData.save()

        #Create the game! (callback is: registerPlayerJoin)
        PtCreateMarkerGame(self.key, PtMarkerGameTypes.kMarkerGameCGZ,
                           grtzMarkerGames.GetCGZGameName(gameNum), 0,
                           templateID)