diff --git a/Makefile b/Makefile index bbc9870..55f091b 100644 --- a/Makefile +++ b/Makefile @@ -7,16 +7,11 @@ but : game OFILES = taille.o \ menu.o \ nbjoueur.o \ - nbjoueur2.o \ - boutonJVJ.o \ - jeu.o \ comportementJCJ.o \ comportementJCIA.o \ definirMaxXY.o \ initialisation.o \ coordoner.o \ - effacehaut.o \ - verificationblock.o \ main.o @@ -26,31 +21,21 @@ CFLAGS = -Wall -ansi -pedantic # CHAPITRE 3 : DEPENDANCES (REGLES IMPLICITES) -menu.o : taille.h menu.h nbjoueur.h nbjoueur2.h boutonJVJ.h +menu.o : taille.h menu.h nbjoueur.h -taille.o : taille.h jeu.h +taille.o : taille.h -effacehaut.o : effacehaut.h - -coordoner.o : coordoner.h - -verificationblock.o : verificationblock.h +coordoner.o : coordoner.h initialisation.h initialisation.o : initialisation.h nbjoueur.o : nbjoueur.h -comportementJCJ.o : comportementJCJ.h definirMaxXY.h initialisation.h coordoner.h effacehaut.h verificationblock.h +comportementJCJ.o : comportementJCJ.h definirMaxXY.h initialisation.h coordoner.h -comportementJCIA.o : comportementJCIA.h +comportementJCIA.o : comportementJCIA.h definirMaxXY.h initialisation.h coordoner.h -boutonJVJ.o : boutonJVJ.h - -nbjoueur2.o : nbjoueur2.h - -jeu.o : jeu.h menu.h comportementJCJ.h comportementJCIA.h - -main.o : jeu.h +main.o : menu.h comportementJCJ.h comportementJCIA.h # CHAPITRE 4 : DEPENDANCES AVEC COMMANDES diff --git a/boutonJVJ.c b/boutonJVJ.c deleted file mode 100644 index dda3f56..0000000 --- a/boutonJVJ.c +++ /dev/null @@ -1,19 +0,0 @@ -#include - -/* Fonction qui permet de délimiter le clique de la souris pour le bouton de Joueur contre Joueur */ - -int boutonJVJ(){ - int choix = 0, SourisX = 0, SourisY = 0; - while(choix == 0){ /* Boucle effectif tant que le joueur n'a pas fais de choix */ - if (SourisCliquee()){ /* Détecte quand le joueur clique et met les coordonées du clique de SourisX et Souris Y */ - SourisX = _X; - SourisY = _Y; - } - if(SourisX > 100 && SourisX < 250 && SourisY > 150 && SourisY < 200){ - choix = 1; /* Quand le joueur clique dans l'emplacement de Joueur contre Joueur choix = 1 */ - }else if(SourisX > 400 && SourisX < 550 && SourisY > 150 && SourisY < 200){ - choix = 2; /* Quand le joueur cliqye dans l'emplacement de Joueur contre IA choix = 2 */ - } - } - return choix; /* On retourne choix pour que le menu puisse le retourner a jeu.c pour faire la selection de l'ennemie */ -} diff --git a/boutonJVJ.h b/boutonJVJ.h deleted file mode 100644 index e2333c4..0000000 --- a/boutonJVJ.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef BOUTONJVJ_H -#define BOUTONJVIA_H - - -int boutonJVJ(); - -#endif diff --git a/comportementJCIA.c b/comportementJCIA.c index f6603ab..09f689a 100644 --- a/comportementJCIA.c +++ b/comportementJCIA.c @@ -4,8 +4,6 @@ #include "definirMaxXY.h" #include "initialisation.h" #include "coordoner.h" -#include "effacehaut.h" -#include "verificationblock.h" int compJCIA(int taille){ @@ -14,6 +12,7 @@ int compJCIA(int taille){ 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}; + srand(time(NULL)); maxX = DefMaxX(taille); maxY = DefMaxY(taille); for(tabx = 0; tabx < taille + 2; tabx++){ @@ -42,7 +41,7 @@ int compJCIA(int taille){ initialiser++; SourisX = 0; SourisY = 0; - Efface(); + EffaceIA(); EcrireTexte(30, 40, "Joueur 2 choisissez l'emplacement de base du pion 2", 1); } }else if (initialiser == 1){ @@ -69,7 +68,7 @@ int compJCIA(int taille){ ChargerSprite("croix2.png"); while(fin == 0){ if(tour == 0){ - Efface(); + EffaceIA(); EcrireTexte(30, 40, "Tour du joueur 1", 2); SourisX = 0; SourisY = 0; @@ -108,7 +107,7 @@ int compJCIA(int taille){ placer = 1; tour++; }else if(tour == 1){ - Efface(); + EffaceIA(); EcrireTexte(30, 40, "Joueur 1 place le bloc", 2); SourisX = 0; SourisY = 0; @@ -132,7 +131,7 @@ int compJCIA(int taille){ placer = 1; tour++; }else if(tour == 2){ - Efface(); + EffaceIA(); EcrireTexte(30, 40, "Tour du joueur 2", 2); SourisX = 0; SourisY = 0; @@ -170,7 +169,7 @@ int compJCIA(int taille){ tour++; }else if(tour == 3){ - Efface(); + EffaceIA(); EcrireTexte(30, 40, "Joueur 2 place le bloc", 2); SourisX = 0; SourisY = 0; @@ -194,3 +193,10 @@ int compJCIA(int taille){ } } } + + +void EffaceIA(){ + ChoisirCouleurDessin(CouleurParNom("white")); + RemplirRectangle(0, 0, 650, 50); + ChoisirCouleurDessin(CouleurParNom("black")); +} diff --git a/comportementJCIA.h b/comportementJCIA.h index 8d47e13..74ffbc7 100644 --- a/comportementJCIA.h +++ b/comportementJCIA.h @@ -4,5 +4,6 @@ void compJCIA(int taille); +void EffaceIA(); #endif diff --git a/comportementJCJ.c b/comportementJCJ.c index bf1b97a..30448a4 100644 --- a/comportementJCJ.c +++ b/comportementJCJ.c @@ -4,8 +4,6 @@ #include "definirMaxXY.h" #include "initialisation.h" #include "coordoner.h" -#include "effacehaut.h" -#include "verificationblock.h" int compJCJ(int taille){ @@ -195,4 +193,11 @@ int compJCJ(int taille){ tour = 0; } } + return 0; +} + +void Efface(){ + ChoisirCouleurDessin(CouleurParNom("white")); + RemplirRectangle(0, 0, 650, 50); + ChoisirCouleurDessin(CouleurParNom("black")); } diff --git a/comportementJCJ.h b/comportementJCJ.h index 52fb677..b42a2d7 100644 --- a/comportementJCJ.h +++ b/comportementJCJ.h @@ -4,5 +4,6 @@ int compJCJ(int taille); +void Efface(); #endif diff --git a/coordoner.c b/coordoner.c index 56c7702..4c5101c 100644 --- a/coordoner.c +++ b/coordoner.c @@ -1,3 +1,5 @@ +#include "initialisation.h" + int coordonerX(int SourisX){ int x = 0, z = 0; for(z = 50; z <= 500; z += 50){ @@ -18,3 +20,15 @@ int coordonerY(int SourisY){ } return x; } + + +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); + placementY = initialisationYbox(SourisY, maxY, taille); + } + coordoner[0] = placementX; + coordoner[1] = placementY; +} + diff --git a/coordoner.h b/coordoner.h index f4b556f..bf37ac5 100644 --- a/coordoner.h +++ b/coordoner.h @@ -6,4 +6,6 @@ int coordonerX(int SourisX); int coordonerY(int SourisY); +void VerifBlock1(int SourisX, int SourisY, int maxX, int maxY, int taille, int* coordoner); + #endif diff --git a/effacehaut.c b/effacehaut.c deleted file mode 100644 index aa9c1eb..0000000 --- a/effacehaut.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - - -void Efface(void){ - ChoisirCouleurDessin(CouleurParNom("white")); - RemplirRectangle(0, 0, 650, 50); - ChoisirCouleurDessin(CouleurParNom("black")); -} diff --git a/effacehaut.h b/effacehaut.h deleted file mode 100644 index 6f9730d..0000000 --- a/effacehaut.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef EFFACEHAUT_H -#define EFFACEHAUT_H - - -void Efface(); - -#endif diff --git a/grille.c b/grille.c deleted file mode 100644 index 7a13ed7..0000000 --- a/grille.c +++ /dev/null @@ -1,27 +0,0 @@ -#include - - -void Grille(int taille){ - int bord = 0, x = 100, xx = 50, y = 100, yy = 100; - ChoisirCouleurDessin(CouleurParNom("Black")); - for(bord = 0; bord < taille; bord++){ - 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 */ - 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 */ - 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 */ - yy += 50; - } - for(bord = 0; bord <= taille; bord++){ - DessinerSegment(xx, 100, xx, y); /* Dessine les barre verticale de l'intérieur de la grille */ - xx += 50; - } -} diff --git a/jeu.c b/jeu.c deleted file mode 100644 index 457ed48..0000000 --- a/jeu.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -#include "menu.h" -#include "comportementJCJ.h" -#include "comportementJCIA.h" - -int Jeu(){ - int choix[2], taille = 0, victoire = 0; - Menu(choix); - taille = choix[1]; - if(choix[0] == 1){ - victoire = compJCJ(taille); - if(victoire == 1){ - return 1; - }else if(victoire == 2){ - return 2; - } - }else if (choix[0] == 2){ - compJCIA(taille); - if(victoire == 1){ - return 1; - }else if(victoire == 3){ - return 3; - } - } -} diff --git a/jeu.h b/jeu.h deleted file mode 100644 index 8e6c2e3..0000000 --- a/jeu.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef JEU_H -#define JEU_H - - -int Jeu(); - - -#endif diff --git a/main.c b/main.c index 2e57c71..b78788b 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,10 @@ #include #include -#include "jeu.h" + +#include "menu.h" +#include "comportementJCJ.h" +#include "comportementJCIA.h" int main (void){ int victoire = 0, choix = 0, SourisX = 0, SourisY = 0; @@ -32,11 +35,11 @@ int main (void){ choix = 5; } if(victoire == 1){ - EcrireTexte(300, 235, "Joueur 1 a gagner !", 2); + EcrireTexte(200, 235, "Joueur 1 a gagner !", 2); }else if (victoire == 2){ - EcrireTexte(300, 235, "Joueur 2 a gagner !", 2); + EcrireTexte(200, 235, "Joueur 2 a gagner !", 2); }else if (victoire == 3){ - EcrireTexte(300, 235, "L'IA a gagner !", 2); + EcrireTexte(200, 235, "L'IA a gagner !", 2); } if(choix == 5){ return EXIT_SUCCESS; @@ -44,3 +47,16 @@ int main (void){ } } } + + +int Jeu(){ + int choix[2], taille = 0, victoire = 0; + Menu(choix); + taille = choix[1]; + if(choix[0] == 1){ + victoire = compJCJ(taille); + }else if (choix[0] == 2){ + compJCIA(taille); + } + return victoire; +} diff --git a/menu.c b/menu.c index bc5702a..270a9fc 100644 --- a/menu.c +++ b/menu.c @@ -2,11 +2,9 @@ #include "taille.h" #include "nbjoueur.h" -#include "nbjoueur2.h" -#include "boutonJVJ.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 */ @@ -66,3 +64,23 @@ void Grille(int taille){ } } + + +/* Fonction qui permet de délimiter le clique de la souris pour le bouton de Joueur contre Joueur */ + +int boutonJVJ(){ + int choix = 0, SourisX = 0, SourisY = 0; + while(choix == 0){ /* Boucle effectif tant que le joueur n'a pas fais de choix */ + if (SourisCliquee()){ /* Détecte quand le joueur clique et met les coordonées du clique de SourisX et Souris Y */ + SourisX = _X; + SourisY = _Y; + } + if(SourisX > 100 && SourisX < 250 && SourisY > 150 && SourisY < 200){ + choix = 1; /* Quand le joueur clique dans l'emplacement de Joueur contre Joueur choix = 1 */ + }else if(SourisX > 400 && SourisX < 550 && SourisY > 150 && SourisY < 200){ + choix = 2; /* Quand le joueur cliqye dans l'emplacement de Joueur contre IA choix = 2 */ + } + } + return choix; /* On retourne choix pour que le menu puisse le retourner a jeu.c pour faire la selection de l'ennemie */ +} + diff --git a/menu.h b/menu.h index f95f649..27c95de 100644 --- a/menu.h +++ b/menu.h @@ -2,8 +2,10 @@ #define MENU_H -int Menu(int *retour); +void Menu(int *retour); void Grille(int taille); +int boutonJCJ(); + #endif diff --git a/nbjoueur.c b/nbjoueur.c index 18b5f42..23ca12a 100644 --- a/nbjoueur.c +++ b/nbjoueur.c @@ -7,7 +7,7 @@ -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); @@ -20,3 +20,24 @@ int nbjoueur(){ DessinerSegment(x - 8, y + 9, x - 8, y + 43); DessinerSegment(xx + 6, y + 8, xx + 6, y + 43); } + + + +/* + * Fonction qui permet de déssiner le bouton du joueur contre IA + */ + +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); + DessinerSegment(x - 2, y + 50, xx, y + 50); + EcrireTexte(x + 10, y + 35, "J1 VS IA", 2); + DessinerArc(xx - 23, y - 3, l, h, angle1, angle2); + DessinerArc(x - 9, y - 2, l, h, angle1 + 100, angle2 + 10); + DessinerArc(xx - 23, y + 23, l, h, angle1 + 290, angle2); + DessinerArc(x - 9, y + 23, l, h, angle1 + 180, angle2); + DessinerSegment(x - 8, y + 9, x - 8, y + 43); + DessinerSegment(xx + 6, y + 8, xx + 6, y + 43); +} + diff --git a/nbjoueur.h b/nbjoueur.h index c1500f6..e0b8881 100644 --- a/nbjoueur.h +++ b/nbjoueur.h @@ -2,7 +2,8 @@ #define NBJOUEUR_H -int nbjoueur(); +void nbjoueur(); +void nbjoueur2(); #endif diff --git a/nbjoueur2.c b/nbjoueur2.c deleted file mode 100644 index c880435..0000000 --- a/nbjoueur2.c +++ /dev/null @@ -1,23 +0,0 @@ -#include - - - -/* - * Fonction qui permet de déssiner le bouton du joueur contre IA - */ - - - -int nbjoueur2(){ - int x = 400, xx = 550, y = 150, l = 30, h = 30, angle1 = 20, angle2 = 30; - ChoisirCouleurDessin(CouleurParNom("Black")); - DessinerSegment(x, y, xx, y); - DessinerSegment(x - 2, y + 50, xx, y + 50); - EcrireTexte(x + 10, y + 35, "J1 VS IA", 2); - DessinerArc(xx - 23, y - 3, l, h, angle1, angle2); - DessinerArc(x - 9, y - 2, l, h, angle1 + 100, angle2 + 10); - DessinerArc(xx - 23, y + 23, l, h, angle1 + 290, angle2); - DessinerArc(x - 9, y + 23, l, h, angle1 + 180, angle2); - DessinerSegment(x - 8, y + 9, x - 8, y + 43); - DessinerSegment(xx + 6, y + 8, xx + 6, y + 43); -} diff --git a/nbjoueur2.h b/nbjoueur2.h deleted file mode 100644 index 14d06e2..0000000 --- a/nbjoueur2.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef NBJOUEUR2_H -#define NBJOUEUR2_H - - -int 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 deleted file mode 100644 index a05b3f3..0000000 --- a/verificationblock.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "initialisation.h" - - -int 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); - placementY = initialisationYbox(SourisY, maxY, taille); - } - coordoner[0] = placementX; - coordoner[1] = placementY; -} diff --git a/verificationblock.h b/verificationblock.h deleted file mode 100644 index b92faff..0000000 --- a/verificationblock.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef VERIFICATIONBLOCK_H -#define VERIFICATIONBLOCK_H - -int VerifBlock1(int SourisX, int SourisY, int maxX, int maxY, int taille, int* coordoner); - - -#endif