Exemple #1
0
    def post(self):
        replyJson = {}

        user = User.checkUser()
        if not user:
            self.response.set_status(401)
            self.response.write('Need active user to proceed')
            return

        guess = self.request.get('word')
        if not guess:
            self.response.set_status(400)
            self.response.write('Can not process an empty guess')
            return

        word = Word.todaysWord()
        score = WordScore.getScore(user, word)
        score.incAttempts()

        if guess == word.word:
            replyJson['solved'] = True
            replyJson['attempts'] = score.attempts
            score.setSolved()
        else:
            replyJson['solved'] = False
            replyJson['attempts'] = score.attempts

        if score.attempts >= config.ATTEMPTS_FOR_CLUE or replyJson['solved']:
            replyJson['wordLen'] = word.len

        self.response.write(json.dumps(replyJson))
Exemple #2
0
    def get(self):
        template_params = {}
        user = User.checkUser()

        if not user:
            self.redirect('/')
            return

        template_params['user'] = user.email
        template_params['logoutUrl'] = user.logoutUrl()

        word = Word.todaysWord()
        score = WordScore.getScore(user, word)
        logging.info("--------- Wrd score: Word: {}, Solved: {}".format(
            word.word, score.solved))
        template_params['definition'] = word.definition
        if score.attempts >= config.ATTEMPTS_FOR_CLUE:
            template_params['wordLen'] = word.len

        template_params['solved'] = score.solved
        template_params['attempts'] = score.attempts

        html = template.render("web/templates/game.html", template_params)
        self.response.write(html)