| @@ -1,5 +1,19 @@ | |||
| import random | |||
| import json | |||
| def lire_scores(): | |||
| with open("scores.json") as f: | |||
| scores = json.load(f) | |||
| return scores | |||
| def enregistrer_scores(scores): | |||
| with open("scores.json", "w") as f: | |||
| scores = json.dump(scores, f, indent=2) | |||
| return scores | |||
| def choisir_mot_au_hasard(): | |||
| fichier = open("mots.txt") | |||
| @@ -11,19 +25,24 @@ def choisir_mot_au_hasard(): | |||
| return mots[index] | |||
| def main(): | |||
| def demander_joueur(): | |||
| joueur = input("donnez votre nom: ") | |||
| return joueur | |||
| def jeu(): | |||
| mot = choisir_mot_au_hasard() | |||
| # pour debuggage | |||
| # print(mot) | |||
| print(mot) | |||
| tentatives = [] | |||
| while True: | |||
| afficher_indice(mot, tentatives) | |||
| lettre = demander_lettre() | |||
| tentatives += [lettre] | |||
| score = len(tentatives) | |||
| if a_gagné(mot, tentatives): | |||
| print("Gagné") | |||
| print(mot) | |||
| break | |||
| return score | |||
| def a_gagné(mot, tentatives): | |||
| @@ -48,4 +67,28 @@ def afficher_indice(mot, tentatives): | |||
| print() | |||
| main() | |||
| def ajouter_resultat(scores, joueur_courant, score_courant): | |||
| record = None | |||
| for nom in scores: | |||
| score = scores[nom] | |||
| if record is None: | |||
| record = score | |||
| elif score < record: | |||
| record = score | |||
| if record is None: | |||
| record = score_courant | |||
| print(joueur_courant + ", vous avez établi le record à ", record) | |||
| elif score_courant < record: | |||
| print(joueur_courant + ", vous avez battu le record de ", record) | |||
| scores[joueur_courant] = record | |||
| return scores | |||
| # main() | |||
| anciens_scores = {"Bob": 30} | |||
| joueur_courant = "Alice" | |||
| score_courant = 28 | |||
| nouveaux_scores = ajouter_resultat(anciens_scores, joueur_courant, score_courant) | |||
| print(nouveaux_scores) | |||