def show_game(gameid): import game as game_lib game = game_lib.find(unique=int(gameid)) user = current_user() if game is None: return "No game with that ID", 400 if user is None: return "Not logged in", 400 joined = user in game is_creator = (user.unique == game.creator_unique) started = game.started if started and not joined: return "You can't play this game. Sorry. :(", 400 elif started and joined: return render_template( 'game.html', game=game, player=game.player_for_user(user) ) else: return render_template( 'lobby.html', user=user, game=game, joined=joined, is_creator=is_creator )
def web_entire_galaxy(): """ This function is called when the client needs to update its local galaxy information. This method therefore reads outputs the `Galaxy` dict as JSON along with some other useful information such as funds available and current turn number. Request Fields: game (int): The unique id for the game that is being played. Returns: A JSON `str` including the JSON for the galaxy in the "galaxy" field, the amount of money the player has in the "money" field, and the game's turn number in the "turn" field. """ # Get the current user. from interstellarage import current_user user = current_user() if user is None: return "Not logged in", 400 # Get the desired game import game as game_lib game_unique = int(request.form['game']) game = game_lib.find(unique=game_unique) if game is None: return "Invalid game", 400 elif user not in game: return "You are not part of this game", 400 # Return the galaxy as JSON return json.dumps({ 'galaxy' : game.galaxy.as_list(for_user=user), 'turn' : game.on_turn, 'money' : game.player_for_user(user).money })
def main(): """ Methode principale du programme, porte l'initialisation, la boucle de jeu et le calcul du résultat. """ # Demander le nom du joueur print("Bonjour ! Prêt pour une nouvelle partie de pendu ?") name = input("Entrez votre nom :") score.init(name) format_print("Votre score actuel est de : {}", score.get()) game.init(random_word.get()) print("Mot choisi !\nC'est parti !") # Tant que pas trouver afficher le # mot decomposé first = True while game.can_play(): if first: first = False else: print("Rejouez !") format_print("Il vous reste {} coups", game.get_countdown()) format_print("Mot à trouver : {}", game.get_found()) # On cherhche la proposition du # joueur dans le mot à trouver proposal = input("Proposez une lettre :") try: # Proposition trouvée : on # l'affiche et on peut rejouer if game.find(proposal): format_print("Oui ! Il y a bien un {} dans le mot.", proposal) # Sinon on perd un tour else: format_print("Et non, pas de {} dans le mot !", proposal) # Si la proposition n'est pas # correcte except ValueError as error: format_print("Erreur de proposition : {}", error) # Si trouvé en moins de 8 coups # enregistre le score if game.result(): format_print( "Gagné !\nLe mot était bien {word}\nVous gagnez {score} points de score", word=game.get_to_find(), score=game.get_countdown()) score.add(game.get_countdown()) score.save() # Sinon, perdu ! else: format_print("Perdu !\nLe mot était : {}", game.get_to_find())