You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import random
  2. import json
  3. def lire_scores():
  4. with open("scores.json") as f:
  5. scores = json.load(f)
  6. return scores
  7. def enregistrer_scores(scores):
  8. with open("scores.json", "w") as f:
  9. scores = json.dump(scores, f, indent=2)
  10. return scores
  11. def choisir_mot_au_hasard():
  12. fichier = open("mots.txt")
  13. contenu = fichier.read()
  14. fichier.close()
  15. mots = contenu.splitlines()
  16. n = len(mots)
  17. index = random.randint(0, n - 1)
  18. return mots[index]
  19. def demander_joueur():
  20. joueur = input("donnez votre nom: ")
  21. return joueur
  22. def jeu():
  23. mot = choisir_mot_au_hasard()
  24. # pour débugger:
  25. print(mot)
  26. tentatives = []
  27. while True:
  28. afficher_indice(mot, tentatives)
  29. lettre = demander_lettre()
  30. tentatives += [lettre]
  31. score = len(tentatives)
  32. if a_gagné(mot, tentatives):
  33. print("Gagné")
  34. print(mot)
  35. return score
  36. def a_gagné(mot, tentatives):
  37. for c in mot:
  38. if c not in tentatives:
  39. return False
  40. return True
  41. def demander_lettre():
  42. print("entrer une lettre")
  43. lettre = input()
  44. return lettre
  45. def afficher_indice(mot, tentatives):
  46. for c in mot:
  47. if c in tentatives:
  48. print(c, end="")
  49. else:
  50. print("_", end="")
  51. print()
  52. def ajouter_resultat(scores, joueur_courant, score_courant):
  53. record = None
  54. for nom in scores:
  55. score = scores[nom]
  56. if record is None:
  57. record = score
  58. elif score < record:
  59. record = score
  60. if record is None:
  61. record = score_courant
  62. print(joueur_courant + ", vous avez établi le record à ", record)
  63. elif score_courant < record:
  64. print(joueur_courant + ", vous avez battu le record de ", record)
  65. scores[joueur_courant] = record
  66. return scores
  67. # main()
  68. anciens_scores = {"Bob": 30}
  69. joueur_courant = "Alice"
  70. score_courant = 28
  71. nouveaux_scores = ajouter_resultat(anciens_scores, joueur_courant, score_courant)
  72. print(nouveaux_scores)