def make_guess(self, request): """Makes a move. Returns a game state with message""" game = get_by_urlsafe(request.urlsafe_game_key, Game) if game.game_over: return game.to_form('Game already over!') guess = request.guess[0].upper() """The Guess is only a character""" if not guess.isalpha(): msg = 'Should put an alphabet!' return game.to_form(msg) """The Guess is already used""" if guess in game.matches + game.misses: msg = 'Already used!' return game.to_form(msg) """The Guess is in the taget word""" if guess in list(game.target): game.matches.append(guess) msg = "Wonderful!" # Set the Guess is in the output words list""" i = 0 for x in list(game.target): if x == guess: game.output_words[i] = x i += 1 if '_' not in game.output_words: game.end_game(True) return game.to_form(msg + ' You win!') else: # The Guess is not in the taget word""" game.misses.append(guess) msg = "You missed!" if len(game.misses) >= 6: game.end_game(False) return game.to_form(msg + ' Game over!') game.put() History.push(game.key, guess, msg) return game.to_form(msg)