def set_ecran(new, t=False): """ Change d'écran sur la fenêtre turtle @new : str = le nouvel écran @t : int = temps de chargement [opts] @return : None """ global ecran if new == "plateau": if t != False: chargement.run(t, "arc") if moteur.est_en_partie() == True: moteur.reprendre_partie() else: affichage.plateau() elif new == "regles": if t != False: chargement.run(t, "cercle") regles.regles(moteur.get_next_mode()) elif new == "scores": if t != False: chargement.run(t, "ligne") affichage.high_score() elif new == "fond": if t != False: chargement.run(t, "ligne") else: raise EcranInvalide ecran = new
def humain_joue(rep): """ Une fonction qui permet de faire jouer l'humain quand on est dans l'état « Humain-Joue » @rep : str = l'évènement à gérer @return : None @throw : LeProgrammeurEstCon ErreurFatale """ global tableau_tampon if get_etat() != "Humain-Joue": raise LeProgrammeurEstCon if rep == "abandon": # Abandon de la partie -> retour au menu afficher("Vous avez abandonné la partie ...") set_etat("Menu") elif rep == "score": try: afficher(scores.calcul_score()) except moteur.PasEnCoursDePartie: raise ErreurFatale elif rep == "plateau": afficher("Le plateau est affiché, vous pouvez proposer des solutions") try: moteur.reprendre_partie() except moteur.PasEnCoursDePartie: raise ErreurFatale set_ecran("plateau") elif rep == "historique": try: h = moteur.get_historique() except moteur.PasEnCoursDePartie: raise ErreurFatale else: def generateur_historique(hist): for i in hist: # i = [[a,b,c,d], (e,f)] coup = i[0] resultat = i[1] sa = "" if resultat[0] > 1: sa = "s" sb = "" if resultat[1] > 1: sb = "s" string = "{0} rouge{1}, {2} blanche{3}".format(resultat[0], sa, resultat[1], sb) yield (coup, string) afficher_liste("Historique", generateur_historique(h)) elif rep == "valider": afficher("Valide le nouveau code ...") if ecran != "plateau": set_ecran("plateau") try: r = moteur.verification_solution(tableau_tampon) except moteur.TableauInvalide as exception: afficher("Le tableau est invalide : {0}".format(exception.message)) else: if r == "gagne": afficher("Vous avez gagné !!!") nom = demander("Nom du joueur") try: scores.enregistre_score(nom) except moteur.PasEnCoursDePartie: raise ErreurFatale set_etat("Menu") elif r == "perdu": afficher("Vous avez perdu !!!") set_etat("Menu") else: a, b = r # On fait un joli affichage qui dit si on doit mettre un S ou pas ... sa = "" sb = "" if a > 1: sa = "s" if b > 1: sb = "s" messaga = "Il y a {0} bonne{1} couleur{1} bien placée{1}".format(a, sa) messagb = "Il y a {0} bonne{1} couleur{1} mal placée{1}".format(b, sb) tableau_tampon = [] iconsole.separateur() afficher(messaga) afficher(messagb) else: gestion_tableau(rep) # Gère l'ajout/suppression dans le tableau