コード例 #1
0
ファイル: ScoreBoard.py プロジェクト: pahvenai/pyDiceGame
 def markScore(self):
     '''
     This function should be used when a player is trying to mark a score.
     Only current player can mark scores and only if the score is not
     already used.
     '''
     # Only marked available scores
     if not self.score.locked:
         # Only mark scores for current player
         if self.player == self.score_board.game.currentPlayer:
             # Mark the score in the score board of the game
             self.player.score_list.value = self.row-1
             UsedFont = tkFont.Font(family="Times", size=10, weight=tkFont.BOLD)
             self.config(text=self.score.value, font=UsedFont)
             self.grid(row = self.row, column = self.column)
             # Update total values of all players
             for label in self.score_board.totals:
                 label.updateScore()
             # Print new dices and update state values
             self.score_board.master.dices.createDices()
             self.score_board.master.states.updateStateValues()
             self.master.master.states.keyBoardFocus()
             if self.score_board.game.end:
                 G.viewHighScores(self.score_board.master)
         # Log a warning if trying to access non-current player scores
         else:
             try:
                 warningstring = '\n\tAttempting to give scores to non-current player.\n ' + \
                                  '\tTried to access player \'%s\' when current player is \'%s\'' % \
                                  (self.player.name, self.master.game.currentPlayer.name)
                 self.score_board.logger.warning(warningstring)
                 print warningstring
             # if there is no current player, catch resulting AttributeError and log a warning
             except AttributeError:
                 warningstring = '\n\tAttempting to give scores to player when no player is up.\n ' + \
                                  '\tTried to access player \'%s\' ' % self.player.name
                 self.score_board.logger.warning(warningstring)
                 print warningstring 
     else:
         warningstring = 'The score is already marked and cannot be used again in this game'
         self.score_board.logger.warning(warningstring)
         print warningstring