Exemplo n.º 1
0
def partieVs(j2):
    """ Fait jouer un joueur humain contre un autre joueur ou une IA
    (dépend de la nature de j2)
    """
    multi = isinstance(j2, jr.JoueurHumain)
    effect = 0
    j1 = jr.JoueurHumain(j2)
    if multi:
        j2.setAdversaire(j1)
    laps = 1
    jeu_j2 = btl.Bataille()
    jeu_j1 = btl.Bataille()

    time.sleep(laps)
    cpt = 0
    while (not jeu_j2.victoire() and not jeu_j1.victoire()):
        cpt += 1
        if multi:
            cls()
            input("\n=-- Tour de J1 :" + j1.nom +
                  " --=\n(appuyez sur entrer quand vous êtes prêt...)")
        effect = 1
        while effect > 0 and not (jeu_j2.victoire() or jeu_j1.victoire()):
            cls()
            print("\n ~~~===> JOUEUR 1\n")

            jeu_j2.affiche(humain=True, cacher=True)
            print()
            jeu_j1.affiche(humain=True)
            dply.afficherLegende()
            effect = j1.joue(jeu_j2)
            cls()
            print("\n ~~~===> JOUEUR 1\n")

            jeu_j2.affiche(humain=True, cacher=True)
            print()
            jeu_j1.affiche(humain=True)
            if effect > 0:
                input(
                    "    Touché ! Vous pouvez rejouer !(appuyez sur entrer)\n")
            else:
                input("Manqué...(appuyez sur entrer)\n")
        if multi:
            cls()
            input("\n=-- Tour de J2 :" + j2.nom +
                  " --=\n(appuyez sur entrer quand vous êtes prêt...)")
            effect = 1
            while effect > 0 and not (jeu_j2.victoire() or jeu_j1.victoire()):
                cls()
                print("\n ~~~===> JOUEUR 2\n")
                jeu_j1.affiche(humain=True, cacher=True)
                print()
                jeu_j2.affiche(humain=True)
                dply.afficherLegende()
                effect = j2.joue(jeu_j1)
                cls()
                print("\n ~~~===> JOUEUR 2\n")

                jeu_j1.affiche(humain=True, cacher=True)
                print()
                jeu_j2.affiche(humain=True)
                if effect > 0:
                    input(
                        "    Touché ! Vous pouvez rejouer ! (appuyez sur entrer)\n"
                    )
                else:
                    input("Manqué...(appuyez sur entrer)\n")

        else:
            input(
                "Au tour de l'IA !\n(appuyez sur entrer quand vous êtes prêt...)"
            )
            effect = 1
            while effect > 0 and not (jeu_j2.victoire() or jeu_j1.victoire()):
                effect = j2.joue(jeu_j1)
                cls()
                print("\n ~~~===> IA\n")
                jeu_j2.affiche(humain=True, cacher=True)
                print()
                jeu_j1.affiche(humain=True)
                if effect > 0:
                    input("    Touché ! L'IA rejoue ! (appuyez sur entrer)\n")
                else:
                    input("Manqué...(appuyez sur entrer)\n")
        input("Nouvelle manche ...(appuyez sur entrer)\n")

    cls()
    input("\n\\\\\\\\ Fin de la partie ! ////\n\n(" + str(cpt) +
          " manches) (appuyez sur entrer)")
    if jeu_j2.victoire():
        if multi:
            print("Joueur J1 : " + j1.nom + " a gagné !")
        else:
            print("     !! Victoire contre l'IA : " + j2.nom + " !!")
    else:
        if multi:
            print("Joueur J2 : " + j2.nom + " a gagné !")
        else:
            print("\n..:: Défaite ! ::..")
    return cpt
Exemplo n.º 2
0
def vs_multi():
    partieVs(jr.JoueurHumain(None))