當前位置: 首頁>>代碼示例>>Python>>正文


Python History.message方法代碼示例

本文整理匯總了Python中models.History.message方法的典型用法代碼示例。如果您正苦於以下問題:Python History.message方法的具體用法?Python History.message怎麽用?Python History.message使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.History的用法示例。


在下文中一共展示了History.message方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: cancel_game

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import message [as 別名]
    def cancel_game(self, request):
        """ Cancels a game from it's urlsafe key """
        game = get_by_urlsafe(request.urlsafe_game_key, Game)
        if not game:
            raise endpoints.NotFoundException("Game not found")

        if not game.game_over and not game.canceled:
            game.canceled = True
            msg = "Game canceled"
            hist = History()
            hist.guess = "-1"
            hist.message = msg
            print hist
            game.history.append(hist)
            game.put()
            return game.to_form(msg)
        else:
            return game.to_form("You cannot cancel a game that is already over")
開發者ID:illusionalsagacity,項目名稱:FSND-P4-Design-A-Game,代碼行數:20,代碼來源:api.py

示例2: make_guess

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import message [as 別名]
    def make_guess(self, request):
        """ Guess a letter for the word to guess in a game.
            A letter can only be guessed once.
            Returns a game form with a list of characters that have been guessed and a list with letters in the correct
            place for the word.
        """
        game = get_by_urlsafe(request.urlsafe_game_key, Game);

        if not game:
            raise endpoints.NotFoundException("Game not found!")

        if game.game_over:
            return game.to_form("Game is already over!")

        if request.guess not in string.ascii_letters:
            raise endpoints.BadRequestException("Guess must be a letter!")

        if len(request.guess) > 1:
            raise endpoints.BadRequestException("You can only guess a single letter!")

        if string.upper(request.guess) in game.guesses:
            raise endpoints.BadRequestException("You cannot guess the same letter twice!")

        game.guesses.append(string.upper(request.guess))
        hist = History()
        hist.guess = string.upper(request.guess)

        if string.upper(request.guess) in string.upper(game.word_to_guess):
            msg = "Good Guess!"
            index = string.find(string.upper(game.word_to_guess), string.upper(request.guess))

            while index is not -1:
                game.correct_guesses[index] = string.upper(request.guess)
                index = string.find(string.upper(game.word_to_guess), string.upper(request.guess), index + 1)

            if "".join(game.correct_guesses) == string.upper(game.word_to_guess):
                user = game.user.get()
                user.games_won += 1
                user.win_percentage = (user.games_won / user.games_won + user.games_lost) * 100
                user.put()
                msg = "Game Won!"
                hist.message = msg
                game.history.append(hist)
                game.put()
                game.end_game(True)
                return game.to_form(msg)

        else:
            msg = "Try Again!"
            game.attempts_remaining -= 1

        if game.attempts_remaining < 1:
            game.end_game(False)
            user = game.user.get()
            if user is not None:
              user.games_lost += 1
              user.win_percentage = user.games_won / user.games_won + user.games_lost
              user.put()
              msg = "Game Over"
            else:
              return game.to_form("Could not find User associated with game.")

        hist.message = msg
        game.history.append(hist)
        game.put()
        return game.to_form(msg)
開發者ID:illusionalsagacity,項目名稱:FSND-P4-Design-A-Game,代碼行數:68,代碼來源:api.py


注:本文中的models.History.message方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。