Skip to content

Commit

Permalink
Merge pull request #4 from edbourque0/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
edbourque0 authored Feb 13, 2024
2 parents 4a210ac + 4dfa454 commit d70566c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
18 changes: 12 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
tricheur = '' #Variable pour stocker le nom du tricheur temporairement
round_number = 0 #Nombre de round jouées dans la partie
joueurs_en_attente = []
difficulte = ''


def obtenir_question(max_retries=5):
#Va chercher la question sur l'API de opentdb
url = "https://opentdb.com/api.php?amount=1&type=multiple"
url = f"https://opentdb.com/api.php?amount=1&difficulty={difficulte}&type=multiple"
for attempt in range(max_retries):
response = requests.get(url)
if response.status_code == 200:
Expand Down Expand Up @@ -98,6 +99,7 @@ def attendre(nom):
if nom not in joueurs_en_attente:
joueurs_en_attente.append(nom)


@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
Expand All @@ -117,9 +119,9 @@ def reset():
socketio.emit('Nouvelle partie crée')
return redirect(url_for('home'))

@app.route('/salle_attente')
@app.route('/salle_attente', methods=['GET'])
def salle_attente():
global tricheur_revele
global tricheur_revele, difficulte
tricheur_revele = False
socketio.emit('Joueur en attente', joueurs)
attendre(session['nom'])
Expand All @@ -130,8 +132,9 @@ def salle_attente():

@app.route('/lancer_jeu', methods=['POST'])
def lancer_jeu():
global partie_demarree, question_actuelle
global partie_demarree, question_actuelle, difficulte
if 'nom' in session and joueurs and session['nom'] == joueurs[0]:
difficulte = request.form['difficulte_questions']
question_actuelle = obtenir_question()
if len(joueurs_en_attente) == len(joueurs):
if question_actuelle:
Expand Down Expand Up @@ -188,7 +191,10 @@ def verifier_joueur(joueur):
def resultat():
global points, tricheur, partie_demarree
partie_demarree = False
return render_template('resultat.html', tricheur=tricheur, points=points)
nom_gagnant = [k for k, v in points.items() if v == max(points.values())][0]
points_gagnant = points[nom_gagnant]
print(points)
return render_template('resultat.html', tricheur=tricheur, points=points, nom_gagnant=nom_gagnant, points_gagnant=points_gagnant)

@socketio.on('connect')
def handle_connect():
Expand All @@ -197,4 +203,4 @@ def handle_connect():


if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=2827, allow_unsafe_werkzeug=True)
socketio.run(app, host='0.0.0.0', port=2827, debug=True)
29 changes: 3 additions & 26 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,6 @@ button.bouton_retourne {
justify-content: center;
}

.loader {
width: 48px;
height: 48px;
border-radius: 50%;
display: inline-block;
position: relative;
background: linear-gradient(0deg, rgba(255, 61, 0, 0.2) 33%, #ff3d00 100%);
box-sizing: border-box;
animation: rotation 1s linear infinite;
}
.loader::after {
content: '';
box-sizing: border-box;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 44px;
height: 44px;
border-radius: 50%;
background: #263238;
}
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)}
}
input[type="radio"] {
margin-left:32px;
}
1 change: 0 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ <h1>Fish and cheat</h1>
{% else %}
<p></p>
{% endif %}
<p></p>
<form action="{{ url_for('reset') }} " method="POST">
<button id="boutonNouvellePartie" class="reset" type="submit">Créer une nouvelle partie</button>
</form>
Expand Down
5 changes: 3 additions & 2 deletions templates/resultat.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=0.7">
<title>Résultats de la Partie</title>
<title>Résultats de la partie</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<div class="result-container">
<h1>Résultats de la partie</h1>
<p class=text_centre>Le tricheur était : <span class='gros_role'>{{ tricheur }}</span></p>
<p class=text_centre>Vous avez <span class='gros_role'>{{ points[session['nom']] }}</span> points</p>
<div></div>
<form action="{{ url_for('salle_attente') }}" method="get">
<button class='bouton_retourne' type="submit">Prochaine round</button>
</form>
<p></p>
<p class=text_centre>{{ nom_gagnant }} gagne ({{ points_gagnant }} points)</p>
<p></p>
<p></p>
</div>
<form action="{{ url_for('reset') }} " method="POST">
Expand Down
17 changes: 12 additions & 5 deletions templates/salle_attente.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ <h2>Liste des joueurs :</h2>
</ul>
</section>
{% if joueur_session == premier_joueur %}
<div>
<form action="{{ url_for('lancer_jeu') }}" method="post">
<button type="submit" class="start-game">Démarrer la partie</button>
</form>
</div>
<form action="{{ url_for('lancer_jeu') }}" method="post">
<div>
<p>Difficulté des questions :</p>
<input type="radio" name="difficulte_questions" id="facile" value="easy" checked/>
<label for="facile">Facile</label>
<input type="radio" name="difficulte_questions" id="moyen" value="medium"/>
<label for="moyen">Moyen</label>
<input type="radio" name="difficulte_questions" id="difficile" value="hard"/>
<label for="difficile">Difficile</label>
</div>
<button type="submit" class="start-game">Démarrer la partie</button>
</form>
{% else %}
<p>En attente du début de la partie...</p>
{% endif %}
Expand Down
3 changes: 3 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
points = {'Ed': 0, 'Hhjjn': 1, 'Jean': 4}

print([k for k, v in points.items() if v == max(points.values())][0])

0 comments on commit d70566c

Please sign in to comment.