1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
void jouerJcJ()
{
//initialisation de curses
affichage_init_curses();
//initialisation du plateau
Plateau* P=action_initPlateau();
action_initTigre(P);
//initialisation des joueurs
Joueur* J=action_affecteJoueur();
//si le joueur 0 est Tigre
if(action_estJoueurTigre(&J[0])==VRAI)
{
Joueur Tigre=J[0];
Joueur Chevre=J[1];
}
else
{
Joueur Tigre=J[1];
Joueur Chevre=J[0];
}
int nb_tour=0;
int nb_chevre_place=0;
int posHc=-1;
int posVc=-1;
int posHt=-1;
int posVt=-1;
int new_posHt=-1;
int new_posVt=-1;
int new_posHc=-1;
int new_posVc=-1;
while(nb_chevre_place != NB_CHEVRE)
{
//tant que la phase de placemant n'est pas terminé
affichage_PlateauCurses(P);
if((action_estVainqueurChevre(P,nb_tour)==FAUX) && (action_estVainqueurTigre(P,nb_tour)==FAUX))
{
//S'il n'y a pas un vainqueur la chèvre pose une chèvre
printw("%s: A quel endroit voulez vous placer une chèvre selon une position (x,y) :",Chevre.nom);
printw("("); posHc=getch();printw(",");posVc=getch();printw(")\n");
action_placerChevre(P,posHc,posVc);
affichage_PlateauCurses(P);
//le tigre déplace un tigre
printw("%s: Quel tigre voulez vous déplacer selon une position (x,y) :",Tigre.nom);
printw("("); posHt=getch();printw(",");posVt=getch();printw(")");
printw("%s: Où voulez vous déplacer selon une position (x,y) :",Tigre.nom);
printw("("); new_posHt=getch();printw(",");new_posVt=getch();printw(")\n");
action_deplacer(P,posHt,posVt,new_posHt,new_posVt,Tigre);
nb_tour++;
}
else
{
//s'il y a un vainqueur on force la sortie de boucle
nb_chevre_place= NB_CHEVRE;
if(action_estVainqueurChevre(P,nb_tour)==VRAI)
{
printw("Félicitation %s vous avez gagné en %d tours\n",Chevre.nom,nb_tour);
}
else
{
printw("Félicitation %s vous avez gagné en %d tours\n",Tigre.nom,nb_tour);
}
}
}
//la phase de placement est terminé; on entre dans la phase de déplacement s'il n'y a toujours pas de vainqueur.
while((action_estVainqueurChevre(P,nb_tour)==FAUX) && (action_estVainqueurTigre(P,nb_tour)==FAUX))
{
affichage_PlateauCurses(P);
//le tigre déplace un tigre
printw("%s: Quel tigre voulez vous déplacer selon une position (x,y) :",Tigre.nom);
printw("("); posHt=getch();printw(",");posVt=getch();printw(")");
printw("%s: Où voulez vous déplacer selon une position (x,y) :",Tigre.nom);
printw("("); new_posHt=getch();printw(",");new_posVt=getch();printw(")\n");
action_deplacer(P,posHt,posVt,new_posHt,new_posVt,Tigre);
//la chèvre déplace une chèvre
affichage_PlateauCurses(P);
printw("%s: Quel tigre voulez vous déplacer selon une position (x,y) :",Tigre.nom);
printw("("); posHc=getch();printw(",");posVc=getch();printw(")");
printw("%s: Où voulez vous déplacer selon une position (x,y) :",Tigre.nom);
printw("("); new_posHc=getch();printw(",");new_posVc=getch();printw(")\n");
action_deplacer(P,posHc,posVc,new_posHc,new_posVc,Chevre);
nb_tour++;
}
if(action_estVainqueurChevre(P,nb_tour)==VRAI)
{
printw("Félicitation %s vous avez gagné en %d tours\n",Chevre.nom,nb_tour);
}
else
{
printw("Félicitation %s vous avez gagné en %d tours\n",Tigre.nom,nb_tour);
}
//fermeture de curses
affichage_close_curses();
} |
Partager