From 52ad6e1bbb864b2d1ca603c86b8884ede4d624c3 Mon Sep 17 00:00:00 2001 From: abraham Date: Tue, 19 Nov 2024 13:36:11 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Probl=C3=A8me=20afficher=20par=20les=20warn?= =?UTF-8?q?ing=20r=C3=A9gler=20en=20plus=20de=20pouvoir=20rejouer=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 52 --------------------------------------------- comportementJCJ.c | 1 + coordoner.c | 4 ++-- definirMaxXY.c | 4 ++-- effacehaut.c | 2 +- grille.c | 4 ++-- initialisation.c | 8 +++---- jeu.c | 15 +++++++------ main.c | 32 +++++++++++++++++----------- menu.c | 2 +- menu.h | 2 +- nbjoueur.c | 5 +---- nbjoueur.h | 2 +- nbjoueur2.c | 6 +----- nbjoueur2.h | 2 +- taille.c | 6 ++---- verificationblock.c | 2 +- verificationblock.h | 2 +- 18 files changed, 50 insertions(+), 101 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 100c0e7..0000000 --- a/README.md +++ /dev/null @@ -1,52 +0,0 @@ -Dans le code actuel il faut absolument 1 écran - - un où l'on peut choisir la taille de la grille - puis on choisi si il y a un second joueur - -Un écran où - - un ou l'on peut jouer au jeu - - - - et un où l'on a le gagnant et de choisir entre terminer le programme et commancer une nouvelle partie - -dans une partie a un joueur il faudra implémenter un bot pour faire le J2 - - -il faut bien diviser le projet en différent fichier pas plus de une fonction par fichier si possible (VRAIMENT IL FAUT LE FAIRE) - - - -Voici un exemple de tableau pour la grille comme elle est a double entrer donc par exemple si le joueur demande une taille de plateu de 3 ca donnera - - - 11111 - 10001 - 10001 - 10001 - 11111 - - -car on prend en compte les bordure pour la detection des blocs par rapport au joueur - -si il aurais pris 9: - - - 11111111111 - 10000000001 - 10000000001 - 10000000001 - 10000000001 - 10000000001 - 10000000001 - 10000000001 - 10000000001 - 10000000001 - 11111111111 - - -On fait taille du tableau +2 pour prendre en compte la bordure - - -création des fichier nbjoueur pour faire des boutton clicable pour sélectionner le nombre de joueur diff --git a/comportementJCJ.c b/comportementJCJ.c index bf1b97a..4ad2f7e 100644 --- a/comportementJCJ.c +++ b/comportementJCJ.c @@ -195,4 +195,5 @@ int compJCJ(int taille){ tour = 0; } } + return 0; } diff --git a/coordoner.c b/coordoner.c index 56c7702..5fc3f4b 100644 --- a/coordoner.c +++ b/coordoner.c @@ -1,5 +1,5 @@ int coordonerX(int SourisX){ - int x = 0, z = 0; + int x = 0, z = 0; /* Retourne les coordoner précis de X pour l'affichage de l'image */ for(z = 50; z <= 500; z += 50){ if(SourisX > z){ x = z + 5; @@ -10,7 +10,7 @@ int coordonerX(int SourisX){ int coordonerY(int SourisY){ - int x = 0, z = 0; + int x = 0, z = 0; /* Retourn les coordoner précis de Y pour l'affichage de l'image */ for(z = 100; z <= 550; z += 50){ if(SourisY > z){ x = z + 5; diff --git a/definirMaxXY.c b/definirMaxXY.c index eb5980c..dff2175 100644 --- a/definirMaxXY.c +++ b/definirMaxXY.c @@ -10,7 +10,7 @@ * 9 : x = 500 y = 550 */ -int DefMaxX(int taille){ +int DefMaxX(int taille){ /* Retourne les coordonées maximale de X par rapport a la taille du tableau selectionner */ int maxX = 0, x = 0, max = 200; if(taille == 3){ maxX = 200; @@ -24,7 +24,7 @@ int DefMaxX(int taille){ return maxX; } -int DefMaxY(int taille){ +int DefMaxY(int taille){ /* Retourne les coordonées maximale de Y par rapport a la taille du tableau selectionner */ int maxY = 0, x = 0, max = 250; for(x = 3; x < 10; x++){ if(taille == x){ diff --git a/effacehaut.c b/effacehaut.c index aa9c1eb..5f6b66d 100644 --- a/effacehaut.c +++ b/effacehaut.c @@ -1,7 +1,7 @@ #include -void Efface(void){ +void Efface(void){ /* Fonction de feignant qui me permet juste d'effacer le haut de l'affichage de la partie */ ChoisirCouleurDessin(CouleurParNom("white")); RemplirRectangle(0, 0, 650, 50); ChoisirCouleurDessin(CouleurParNom("black")); diff --git a/grille.c b/grille.c index 0d18e7c..7a13ed7 100644 --- a/grille.c +++ b/grille.c @@ -8,13 +8,13 @@ void Grille(int taille){ DessinerSegment(50, 100, x, 100); /* Dessine le bord du haut de la grille */ x += 50; } - x -= 50; /* Enlève le surplus de la fonction for */ + x -= 50; /* Enlève le surplus de la fonction for */ for(bord = 0; bord <= taille; bord++){ DessinerSegment(50, 100, 50 , y); /* Dessine les barre latérale en fonction de la taille choisie */ DessinerSegment(x, 100, x, y); y += 50; } - y -= 50; /* Enlève le surplus de la fonction for */ + y -= 50; /* Enlève le surplus de la fonction for */ DessinerSegment(50, y, x, y); for(bord = 0; bord <= taille; bord++){ DessinerSegment(50, yy, x, yy); /* Dessine les barre horizontale de l'intérieur de la grille */ diff --git a/initialisation.c b/initialisation.c index ec6ce13..98e18ff 100644 --- a/initialisation.c +++ b/initialisation.c @@ -1,4 +1,4 @@ -int initialisationX(int SourisX, int maxX, int taille){ +int initialisationX(int SourisX, int maxX, int taille){ /* Code qui permet de retourner le numéro X de la case ou le joueur veux le pion de base */ int casejoueur = 0, x = 0, y = 50, verou = 0; for(x = 0; x <= taille; x++){ if(SourisX >= 50 && SourisX <= maxX){ @@ -12,7 +12,7 @@ int initialisationX(int SourisX, int maxX, int taille){ return casejoueur; } -int initialisationY(int SourisY, int maxY, int taille){ +int initialisationY(int SourisY, int maxY, int taille){ /* Code qui permet de retourner le numéro Y de la case ou le joueur veux le pion de base */ int casejoueur = 0, x = 0, y = 100, verou = 0; for(x = 0; x <= taille; x++){ if(SourisY >= 100 && SourisY <= maxY){ @@ -28,7 +28,7 @@ int initialisationY(int SourisY, int maxY, int taille){ -int initialisationXbox(int SourisX, int maxX, int taille){ +int initialisationXbox(int SourisX, int maxX, int taille){ /* Retourne X de la case du bloc que l'on veux placer */ int caseblock = 0, x = 0, y = 50, verou = 0; for(x = 0; x <= taille; x++){ if(SourisX >= 50 && SourisX <= maxX){ @@ -43,7 +43,7 @@ int initialisationXbox(int SourisX, int maxX, int taille){ } -int initialisationYbox(int SourisY, int maxY, int taille){ +int initialisationYbox(int SourisY, int maxY, int taille){ /* Retourne Y de la case du bloc que l'on veux placer */ int caseblock = 0, x = 0, y = 100, verou = 0; for(x = 0; x <= taille; x++){ if(SourisY >= 100 && SourisY <= maxY){ diff --git a/jeu.c b/jeu.c index 457ed48..0ee3a15 100644 --- a/jeu.c +++ b/jeu.c @@ -6,21 +6,22 @@ int Jeu(){ int choix[2], taille = 0, victoire = 0; - Menu(choix); + Menu(choix); /* Affiche le menu */ taille = choix[1]; - if(choix[0] == 1){ + if(choix[0] == 1){ /* Si l'utilisateur choisie Player VS Player */ victoire = compJCJ(taille); - if(victoire == 1){ + if(victoire == 1){ /* Si le joueur 1 a gagner alors retourner 1 */ return 1; }else if(victoire == 2){ - return 2; + return 2; /* Si le joueur 2 a gagner alors retourner 2 */ } - }else if (choix[0] == 2){ + }else if (choix[0] == 2){ /* Si l'utilisateur choisie Player VS IA */ compJCIA(taille); if(victoire == 1){ - return 1; + return 1; /* Si le joueur 1 a gagner alors retourner 1 */ }else if(victoire == 3){ - return 3; + return 3; /* Si l'IA a gagner alors retourner 3 */ } } + return 0; } diff --git a/main.c b/main.c index f05909e..3b94634 100644 --- a/main.c +++ b/main.c @@ -1,34 +1,42 @@ #include #include - -#include - #include "jeu.h" int main (void){ - int victoire = 0, choix = 0; + int victoire = 0, choix = 0, SourisX = 0, SourisY = 0; InitialiserGraphique(); CreerFenetre(50, 50, 700, 500); /* Initialise la fenetre puis lance le programme jeu.c qui lancera d'autre programme */ while(1){ + SourisX = 0; + SourisY = 0; + choix = 0; + victoire = 0; EffacerEcran(CouleurParNom("white")); - victoire = Jeu(); - printf("victoire : %d\n", victoire); + victoire = Jeu(); /* Récupération du numéro du vainceur */ FermerGraphique(); InitialiserGraphique(); CreerFenetre(50, 50, 700, 500); - while(choix == 0){ + while(choix == 0){ /* Création de la fenetre qui permet de rejouer ou de quitter */ ChoisirCouleurDessin(CouleurParNom("black")); DessinerRectangle(100, 100, 200, 50); EcrireTexte(120, 135, "Rejouer ?", 2); DessinerRectangle(400, 100, 200, 50); EcrireTexte(420, 135, "Quitter ?", 2); - if(victoire == 1){ - EcrireTexte(300, 235, "Joueur 1 a gagner !", 2); - }else if (victoire == 2){ - EcrireTexte(300, 235, "Joueur 2 a gagner !", 2); + while(SourisCliquee()){ + SourisX = _X; + SourisY = _Y; } - if(choix == 5){ + if(victoire == 1){ + EcrireTexte(200, 235, "Joueur 1 a gagner !", 2); + }else if (victoire == 2){ + EcrireTexte(200, 235, "Joueur 2 a gagner !", 2); + }else if (victoire == 3){ + EcrireTexte(200, 235, "L'IA a gagner !", 2); + } /* Bouton pour quitter ou rejouer */ + if(SourisX > 100 && SourisX < 300 && SourisY < 150 && SourisY > 100){ + choix++; + }else if (SourisX > 400 && SourisX < 600 && SourisY < 150 && SourisY > 100){ return EXIT_SUCCESS; } } diff --git a/menu.c b/menu.c index b50f9d9..a7e65bf 100644 --- a/menu.c +++ b/menu.c @@ -7,7 +7,7 @@ #include "grille.h" -int Menu(int *retour) { +void Menu(int *retour) { int x = 50, y = 50, taille = -5, choix = 0, echotaille = 0, verrou = 0; /* initialisation des variable */ couleur c = CouleurParNom("white"); while(choix == 0){ /* Condition pour que le menu s'arrête quand le joueur aura selectionner le nombre de joueur */ diff --git a/menu.h b/menu.h index 9c318d3..5ed1ba2 100644 --- a/menu.h +++ b/menu.h @@ -4,6 +4,6 @@ -int Menu(int *retour); +void Menu(int *retour); #endif diff --git a/nbjoueur.c b/nbjoueur.c index 18b5f42..33b0248 100644 --- a/nbjoueur.c +++ b/nbjoueur.c @@ -1,13 +1,10 @@ #include - /* * Fonction qui permet de déssiner le bouton du Joueur contre Joueur */ - - -int nbjoueur(){ +void nbjoueur(){ int x = 100, xx = 250, y = 150, l = 30, h = 30, angle1 = 20, angle2 = 30; ChoisirCouleurDessin(CouleurParNom("Black")); DessinerSegment(x, y, xx, y); diff --git a/nbjoueur.h b/nbjoueur.h index c1500f6..b943659 100644 --- a/nbjoueur.h +++ b/nbjoueur.h @@ -2,7 +2,7 @@ #define NBJOUEUR_H -int nbjoueur(); +void nbjoueur(); #endif diff --git a/nbjoueur2.c b/nbjoueur2.c index c880435..8cdde4c 100644 --- a/nbjoueur2.c +++ b/nbjoueur2.c @@ -1,14 +1,10 @@ #include - - /* * Fonction qui permet de déssiner le bouton du joueur contre IA */ - - -int nbjoueur2(){ +void nbjoueur2(){ int x = 400, xx = 550, y = 150, l = 30, h = 30, angle1 = 20, angle2 = 30; ChoisirCouleurDessin(CouleurParNom("Black")); DessinerSegment(x, y, xx, y); diff --git a/nbjoueur2.h b/nbjoueur2.h index 14d06e2..2268229 100644 --- a/nbjoueur2.h +++ b/nbjoueur2.h @@ -2,7 +2,7 @@ #define NBJOUEUR2_H -int nbjoueur2(); +void nbjoueur2(); #endif diff --git a/taille.c b/taille.c index 61f8101..e4eec76 100644 --- a/taille.c +++ b/taille.c @@ -82,7 +82,5 @@ int GererChoixTaille(){ taille = 9; } } - if(taille != 0){ - return taille; - } -} \ No newline at end of file + return taille; +} diff --git a/verificationblock.c b/verificationblock.c index a05b3f3..2c48c54 100644 --- a/verificationblock.c +++ b/verificationblock.c @@ -3,7 +3,7 @@ #include "initialisation.h" -int VerifBlock1(int SourisX, int SourisY, int maxX, int maxY, int taille, int* coordoner){ +void VerifBlock1(int SourisX, int SourisY, int maxX, int maxY, int taille, int* coordoner){ int placementX = 0, placementY = 0; if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){ placementX = initialisationXbox(SourisX, maxX, taille); diff --git a/verificationblock.h b/verificationblock.h index b92faff..fc266fb 100644 --- a/verificationblock.h +++ b/verificationblock.h @@ -1,7 +1,7 @@ #ifndef VERIFICATIONBLOCK_H #define VERIFICATIONBLOCK_H -int VerifBlock1(int SourisX, int SourisY, int maxX, int maxY, int taille, int* coordoner); +void VerifBlock1(int SourisX, int SourisY, int maxX, int maxY, int taille, int* coordoner); #endif From eaf03948bd07e0f10b77858200e881e83114e27f Mon Sep 17 00:00:00 2001 From: khadir Date: Tue, 19 Nov 2024 13:37:41 +0100 Subject: [PATCH 2/3] cp --- comportementJCIA.c | 197 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 2 deletions(-) diff --git a/comportementJCIA.c b/comportementJCIA.c index 5a54869..4ad2f7e 100644 --- a/comportementJCIA.c +++ b/comportementJCIA.c @@ -1,6 +1,199 @@ #include -void compJCIA(int taille){ - DessinerSegment(1, 1, 100, 100); +#include "definirMaxXY.h" +#include "initialisation.h" +#include "coordoner.h" +#include "effacehaut.h" +#include "verificationblock.h" + + +int compJCJ(int taille){ + int fin = 0, tabx = 0, taby = 0, tour = 0, initi = 0, SourisX = 0, SourisY = 0, initialiser = 0; + int maxX = 0, maxY = 0, joueurx1 = 0, joueury1 = 0, joueurx2 = 0, joueury2 = 0, placer = 1; + int emplacementcooX1 = 0, emplacementcooX2 = 0, emplacementcooY1 = 0, emplacementcooY2 = 0; + int grille[taille+2][taille+2]; + int empblock[4] = {0, 0, 0, 0}, empperso[4] = {0, 0, 0, 0}; + maxX = DefMaxX(taille); + maxY = DefMaxY(taille); + for(tabx = 0; tabx < taille + 2; tabx++){ + for(taby = 0; taby < taille + 2; taby++){ + grille[tabx][taby] = 0; + if(taby == 0 || taby == taille + 1 || tabx == 0 || tabx == taille + 1){ + grille[tabx][taby] = 9; + } + } + } + EcrireTexte(30, 40, "Joueur 1 choisissez l'emplacement de base du pion 1", 1); + while(initi == 0){ + if(SourisCliquee()){ + SourisX = _X; + SourisY = _Y; + } + if(initialiser == 0){ + if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){ + ChargerSprite("pion1.png"); + joueurx1 = initialisationX(SourisX, maxX, taille); + joueury1 = initialisationY(SourisY, maxY, taille); + emplacementcooX1 = coordonerX(SourisX); + emplacementcooY1 = coordonerY(SourisY); + AfficherSprite(1, emplacementcooX1, emplacementcooY1); + grille[joueury1][joueurx1] = 1; + initialiser++; + SourisX = 0; + SourisY = 0; + Efface(); + EcrireTexte(30, 40, "Joueur 2 choisissez l'emplacement de base du pion 2", 1); + } + }else if (initialiser == 1){ + if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){ + ChargerSprite("pion2.png"); + joueurx2 = initialisationX(SourisX, maxX, taille); + joueury2 = initialisationY(SourisY, maxY, taille); + if(grille[joueury2][joueurx2] != 1){ + emplacementcooX2 = coordonerX(SourisX); + emplacementcooY2 = coordonerY(SourisY); + AfficherSprite(2, emplacementcooX2, emplacementcooY2); + grille[joueury2][joueurx2] = 2; + initialiser++; + initi++; + } + SourisX = 0; + SourisY = 0; + } + } + } + ChargerSprite("croix1.png"); + ChargerSprite("croix2.png"); + while(fin == 0){ + if(tour == 0){ + Efface(); + EcrireTexte(30, 40, "Tour du joueur 1", 2); + SourisX = 0; + SourisY = 0; + while(placer == 1){ + if(SourisCliquee()){ + SourisX = _X; + SourisY = _Y; + } + VerifBlock1(SourisX, SourisY, maxX, maxY, taille, empperso); + if(grille[joueury1+1][joueurx1] != 0 && grille[joueury1-1][joueurx1] != 0 && grille[joueury1+1][joueurx1+1] != 0 && grille[joueury1-1][joueurx1-1] != 0 && grille[joueury1][joueurx1+1] != 0 && grille[joueury1][joueurx1-1] != 0){ + LibererSprite(1); + LibererSprite(2); + LibererSprite(3); + LibererSprite(4); + return 2; + } + if(empperso[0] != 0){ + if(grille[empperso[1]][empperso[0]] == 0 && (empperso[1] <= joueury1+1 && empperso[1] >= joueury1-1) && (empperso[0] <= joueurx1+1 && empperso[0] >= joueurx1-1)){ + grille[joueury1][joueurx1] = 0; + ChoisirCouleurDessin(CouleurParNom("white")); + RemplirRectangle(emplacementcooX1, emplacementcooY1, 40, 40); + ChoisirCouleurDessin(CouleurParNom("black")); + joueurx1 = empperso[0]; + joueury1 = empperso[1]; + empperso[2] = coordonerX(SourisX); + empperso[3] = coordonerY(SourisY); + grille[empperso[1]][empperso[0]] = 1; + AfficherSprite(1, empperso[2], empperso[3]); + emplacementcooX1 = empperso[2]; + emplacementcooY1 = empperso[3]; + placer = 0; + } + } + } + empperso[0] = 0; + placer = 1; + tour++; + }else if(tour == 1){ + Efface(); + EcrireTexte(30, 40, "Joueur 1 place le bloc", 2); + SourisX = 0; + SourisY = 0; + while(placer == 1){ + if(SourisCliquee()){ + SourisX = _X; + SourisY = _Y; + } + VerifBlock1(SourisX, SourisY, maxX, maxY, taille, empblock); + if(empblock[0] != 0){ + if(grille[empblock[1]][empblock[0]] == 0){ + empblock[2] = coordonerX(SourisX); + empblock[3] = coordonerY(SourisY); + grille[empblock[1]][empblock[0]] = 3; + AfficherSprite(3, empblock[2], empblock[3]); + placer = 0; + } + } + } + empblock[0] = 0; + placer = 1; + tour++; + }else if(tour == 2){ + Efface(); + EcrireTexte(30, 40, "Tour du joueur 2", 2); + SourisX = 0; + SourisY = 0; + while(placer == 1){ + if(SourisCliquee()){ + SourisX = _X; + SourisY = _Y; + } + VerifBlock1(SourisX, SourisY, maxX, maxY, taille, empperso); + if(grille[joueury2+1][joueurx2] != 0 && grille[joueury2-1][joueurx2] != 0 && grille[joueury2+1][joueurx2+1] != 0 && grille[joueury2-1][joueurx2-1] != 0 && grille[joueury2][joueurx2+1] != 0 && grille[joueury2][joueurx2-1] != 0){ + LibererSprite(1); + LibererSprite(2); + LibererSprite(3); + LibererSprite(4); + return 1; + } + if(empperso[0] != 0){ + if(grille[empperso[1]][empperso[0]] == 0 && (empperso[1] <= joueury2+1 && empperso[1] >= joueury2-1) && (empperso[0] <= joueurx2+1 && empperso[0] >= joueurx2-1)){ + grille[joueury2][joueurx2] = 0; + ChoisirCouleurDessin(CouleurParNom("white")); + RemplirRectangle(emplacementcooX2, emplacementcooY2, 40, 40); + ChoisirCouleurDessin(CouleurParNom("black")); + joueurx2 = empperso[0]; + joueury2 = empperso[1]; + empperso[2] = coordonerX(SourisX); + empperso[3] = coordonerY(SourisY); + grille[empperso[1]][empperso[0]] = 2; + AfficherSprite(2, empperso[2], empperso[3]); + emplacementcooX2 = empperso[2]; + emplacementcooY2 = empperso[3]; + placer = 0; + } + } + } + empperso[0] = 0; + placer = 1; + tour++; + + }else if(tour == 3){ + Efface(); + EcrireTexte(30, 40, "Joueur 2 place le bloc", 2); + SourisX = 0; + SourisY = 0; + while(placer == 1){ + if(SourisCliquee()){ + SourisX = _X; + SourisY = _Y; + } + VerifBlock1(SourisX, SourisY, maxX, maxY, taille, empblock); + if(empblock[0] != 0){ + if(grille[empblock[1]][empblock[0]] == 0){ + empblock[2] = coordonerX(SourisX); + empblock[3] = coordonerY(SourisY); + grille[empblock[1]][empblock[0]] = 4; + AfficherSprite(4, empblock[2], empblock[3]); + placer = 0; + } + } + } + empblock[0] = 0; + placer = 1; + tour = 0; + } + } + return 0; } From 78bdfbd44a99983714f3acb43f5d6be5743800dc Mon Sep 17 00:00:00 2001 From: abraham Date: Tue, 19 Nov 2024 17:25:51 +0100 Subject: [PATCH 3/3] changement du comportementJCIA.c --- Makefile | 2 +- comportementJCIA.c | 45 ++++++++++++++++++++++----------------------- comportementJCIA.h | 2 +- comportementJCJ.c | 2 -- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index f50e866..35f317a 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ nbjoueur.o : nbjoueur.h comportementJCJ.o : comportementJCJ.h definirMaxXY.h initialisation.h coordoner.h effacehaut.h verificationblock.h -comportementJCIA.o : comportementJCIA.h +comportementJCIA.o : comportementJCIA.h definirMaxXY.h initialisation.h coordoner.h effacehaut.h verificationblock.h boutonJVJ.o : boutonJVJ.h diff --git a/comportementJCIA.c b/comportementJCIA.c index 4ad2f7e..d0a32f1 100644 --- a/comportementJCIA.c +++ b/comportementJCIA.c @@ -1,4 +1,6 @@ #include +#include +#include #include "definirMaxXY.h" @@ -8,8 +10,8 @@ #include "verificationblock.h" -int compJCJ(int taille){ - int fin = 0, tabx = 0, taby = 0, tour = 0, initi = 0, SourisX = 0, SourisY = 0, initialiser = 0; +int compJCIA(int taille){ + int fin = 0, tabx = 0, taby = 0, tour = 0, initi = 0, SourisX = 0, SourisY = 0, initialiser = 0, inialea = 0; int maxX = 0, maxY = 0, joueurx1 = 0, joueury1 = 0, joueurx2 = 0, joueury2 = 0, placer = 1; int emplacementcooX1 = 0, emplacementcooX2 = 0, emplacementcooY1 = 0, emplacementcooY2 = 0; int grille[taille+2][taille+2]; @@ -39,28 +41,25 @@ int compJCJ(int taille){ emplacementcooY1 = coordonerY(SourisY); AfficherSprite(1, emplacementcooX1, emplacementcooY1); grille[joueury1][joueurx1] = 1; + initialiser = 0; + initi++; + SourisX = 0; + SourisY = 0; + } + } + } + initialiser = 1; + ChargerSprite("pion2.png"); + while(initialiser == 1){ + emplacementcooX2 = rand() % maxX + 95; + emplacementcooY2 = rand() % maxY - 12; + joueurx2 = initialisationX(emplacementcooX2, maxX, taille); + joueury2 = initialisationY(emplacementcooY2, maxY, taille); + printf("%d, %d\n", joueurx2, joueury2); + if(grille[joueury2][joueurx2] == 0){ + AfficherSprite(2, emplacementcooX2, emplacementcooY2); + grille[joueury2][joueurx2] = 2; initialiser++; - SourisX = 0; - SourisY = 0; - Efface(); - EcrireTexte(30, 40, "Joueur 2 choisissez l'emplacement de base du pion 2", 1); - } - }else if (initialiser == 1){ - if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){ - ChargerSprite("pion2.png"); - joueurx2 = initialisationX(SourisX, maxX, taille); - joueury2 = initialisationY(SourisY, maxY, taille); - if(grille[joueury2][joueurx2] != 1){ - emplacementcooX2 = coordonerX(SourisX); - emplacementcooY2 = coordonerY(SourisY); - AfficherSprite(2, emplacementcooX2, emplacementcooY2); - grille[joueury2][joueurx2] = 2; - initialiser++; - initi++; - } - SourisX = 0; - SourisY = 0; - } } } ChargerSprite("croix1.png"); diff --git a/comportementJCIA.h b/comportementJCIA.h index 8d47e13..4d6b77a 100644 --- a/comportementJCIA.h +++ b/comportementJCIA.h @@ -2,7 +2,7 @@ #define COMPORTEMENTJCIA_H -void compJCIA(int taille); +int compJCIA(int taille); #endif diff --git a/comportementJCJ.c b/comportementJCJ.c index 4ad2f7e..07b4e76 100644 --- a/comportementJCJ.c +++ b/comportementJCJ.c @@ -1,6 +1,5 @@ #include - #include "definirMaxXY.h" #include "initialisation.h" #include "coordoner.h" @@ -168,7 +167,6 @@ int compJCJ(int taille){ empperso[0] = 0; placer = 1; tour++; - }else if(tour == 3){ Efface(); EcrireTexte(30, 40, "Joueur 2 place le bloc", 2);