From 7cced61b52cef944494d55657df6bcdf4a670cb2 Mon Sep 17 00:00:00 2001 From: Anis BEKKOUCHE Date: Sun, 24 Nov 2024 10:37:26 +0100 Subject: [PATCH 1/2] fdfdfq --- DEV1.1/SAE1.1/graphics.c | 32 +++++++++++++++++++ DEV1.1/SAE1.1/ia.c | 50 +++++++++++++++++++++++++++++ DEV1.1/SAE1.1/makefile | 33 +++++++++++++++++++ DEV1.1/SAE1.1/menu.c | 68 ++++++++++++++++++++++++++++++++++++++++ DEV1.1/SAE1.1/utils.c | 24 ++++++++++++++ 5 files changed, 207 insertions(+) create mode 100644 DEV1.1/SAE1.1/graphics.c create mode 100644 DEV1.1/SAE1.1/ia.c create mode 100644 DEV1.1/SAE1.1/makefile create mode 100644 DEV1.1/SAE1.1/menu.c create mode 100644 DEV1.1/SAE1.1/utils.c diff --git a/DEV1.1/SAE1.1/graphics.c b/DEV1.1/SAE1.1/graphics.c new file mode 100644 index 0000000..b80b7c1 --- /dev/null +++ b/DEV1.1/SAE1.1/graphics.c @@ -0,0 +1,32 @@ +#include "blocus.h" + +void EffacerAncienSprite(int x_ancien, int y_ancien, int largeur, int hauteur) { + ChoisirCouleurDessin(CouleurParNom("white")); + RemplirRectangle(x_ancien + 1, y_ancien + 1, largeur - 1, hauteur - 1); +} + +int ecran_de_fin(int gagnant) { + FermerGraphique(); + InitialiserGraphique(); + CreerFenetre(posx, posy, 400, 400); + if (gagnant == 1) { /* 1 = bleu*/ + EcrireTexte(90, 100, "Le joueur bleu gagne", 1); + } else if (gagnant == 2) { /* 2 = rouge*/ + EcrireTexte(90, 100, "Le joueur rouge gagne", 1); + } + DessinerRectangle(50, 150, 100, 50); + DessinerRectangle(250, 150, 100, 50); /*Nouvelle fenetre avec boutons quitter et rejouer*/ + EcrireTexte(70, 175, "Rejouer", 1); + EcrireTexte(270, 175, "Quitter", 1); + while (1) { + if (SourisCliquee()) { + SourisPosition(); + if (_X >= 50 && _X <= 150 && _Y >= 150 && _Y <= 200) { + FermerGraphique(); /*si coos clique = coos rectangle rejouer, fermer fenetre et relancer le jeu*/ + return main(); + } else if (_X >= 250 && _X <= 350 && _Y >= 150 && _Y <= 200) { + FermerGraphique(); /*si coos clique = coos rectangle quitter, fermer fenetre*/ + } + } + } +} \ No newline at end of file diff --git a/DEV1.1/SAE1.1/ia.c b/DEV1.1/SAE1.1/ia.c new file mode 100644 index 0000000..724c4f7 --- /dev/null +++ b/DEV1.1/SAE1.1/ia.c @@ -0,0 +1,50 @@ +#include "blocus.h" + +void CoordIA(int grille, int *coordX, int *coordY) { + int aleatoirex, aleatoirey; + srand(time(NULL)); + aleatoirex = rand(); + do { + aleatoirex = aleatoirex / 4; + } while (aleatoirex > grille); + aleatoirey = rand(); + do { + aleatoirey = aleatoirey / 4; + } while (aleatoirey > grille); + + *coordX = aleatoirex; + *coordY = aleatoirey; +} + +void CoordBlocageIA(int grille, int *blocX, int *blocY) { + int aleatoirex, aleatoirey; + srand(time(NULL)); + aleatoirex = rand(); + do { + aleatoirex = aleatoirex / 3; + } while (aleatoirex > grille); + aleatoirey = rand(); + do { + aleatoirey = aleatoirey / 3; + } while (aleatoirey > grille); + *blocX = aleatoirex; + *blocY = aleatoirey; +} + +void DeplacementIAX(int grille, int *deplacementX) { + int aleatoirex; + srand(time(NULL)); + do { + aleatoirex = rand() % 3 - 1; /*Génère -1, 0 ou 1*/ + } while (aleatoirex > grille); + *deplacementX = aleatoirex; +} + +void DeplacementIAY(int grille, int *deplacementY) { + int aleatoirey; + srand(time(NULL)); + do { + aleatoirey = rand() % 3 - 1; /*Génère -1, 0 ou 1*/ + } while (aleatoirey > grille); + *deplacementY = aleatoirey; +} \ No newline at end of file diff --git a/DEV1.1/SAE1.1/makefile b/DEV1.1/SAE1.1/makefile new file mode 100644 index 0000000..44f762d --- /dev/null +++ b/DEV1.1/SAE1.1/makefile @@ -0,0 +1,33 @@ +CC = gcc +CFLAGS = -ansi -pedantic -g +OFILES = menu.o blocus.o utils.o graphics.o ia.o +EXE = exe +LIBS = -lgraph + +install : $(EXE) + +$(EXE) : $(OFILES) + $(CC) $(CFLAGS) -o $(EXE) $(OFILES) $(LIBS) + +blocus.o : blocus.h menu.c graphics.c utils.c ia.c + +menu.o : blocus.h + $(CC) $(CFLAGS) -c menu.c $(END) + +graphics.o : blocus.h + $(CC) $(CFLAGS) -c graphics.c $(END) + +utils.o : blocus.h + $(CC) $(CFLAGS) -c utils.c $(END) + +ia.o : blocus.h + $(CC) $(CFLAGS) -c ia.c $(END) + +run : install + ./$(EXE) + +clean : + rm -r *.o + +cleanall : clean + rm -r $(EXE) diff --git a/DEV1.1/SAE1.1/menu.c b/DEV1.1/SAE1.1/menu.c new file mode 100644 index 0000000..ccc74ea --- /dev/null +++ b/DEV1.1/SAE1.1/menu.c @@ -0,0 +1,68 @@ +#include "blocus.h" + +char* textes[] = {"3x3", "4x4", "5x5", "6x6", "7x7", "8x8", "9x9"}; /*Tableau pour grille*/ + +void creer_menu(int *solo, int *multi, int *mode_grille, int *grille) { + int i; + + InitialiserGraphique(); + CreerFenetre(posx,posy,500,500); + EcrireTexte(200, 200, "Blocus", 2); + sleep(1); + EffacerEcran(CouleurParNom("white")); + sleep(1); + + DessinerRectangle(75, 75, 350, 100); + DessinerRectangle(75, 250, 350, 100); + + EcrireTexte(185, 135, "1 Joueur", 2); + EcrireTexte(180, 310, "2 Joueurs", 2); + + while (1) { + if (SourisCliquee()) { + SourisPosition(); + if (_X >= 75 && _X <= 425 && _Y >= 75 && _Y <= 175) { /*Si clique = rectangle 1 joueur*/ + EffacerEcran(CouleurParNom("white")); + *solo = 1; + *mode_grille = 1; + break; + } else if (_X >= 75 && _X <= 425 && _Y >= 250 && _Y <= 350) { /*Si clique = rectangle 2 joueurs*/ + EffacerEcran(CouleurParNom("white")); + *multi = 1; + *mode_grille = 1; + break; + } + } + } + + if (*mode_grille == 1) { + EcrireTexte(125, 100, "Taille de la grille", 2); + for (i = 0; i < 7; i++) { + DessinerRectangle(45 + i * 60, 150, 50, 50); /*Tracer rectangles pour choisir taille grille*/ + EcrireTexte(45 + i * 60 + 15, 175, textes[i], 1); /*Ecris texte tableau dans rectangles*/ + } + + while (*grille == 0) { + if (SourisCliquee()) { + SourisPosition(); + if (_Y >= 150 && _Y <= 200) { /*regarde si coordonnées clique = coos rectangle pour choisir taille grille*/ + if (_X >= 45 && _X <= 95) { + *grille = 3; + } else if (_X >= 105 && _X <= 155) { + *grille = 4; + } else if (_X >= 165 && _X <= 215) { + *grille = 5; + } else if (_X >= 225 && _X <= 275) { + *grille = 6; + } else if (_X >= 285 && _X <= 335) { + *grille = 7; + } else if (_X >= 345 && _X <= 395) { + *grille = 8; + } else if (_X >= 405 && _X <= 455) { + *grille = 9; + } + } + } + } + } +} \ No newline at end of file diff --git a/DEV1.1/SAE1.1/utils.c b/DEV1.1/SAE1.1/utils.c new file mode 100644 index 0000000..953ca56 --- /dev/null +++ b/DEV1.1/SAE1.1/utils.c @@ -0,0 +1,24 @@ +#include "blocus.h" + +int estAdjacent(int x1, int y1, int x2, int y2) { /*Fonction qui vérifie si deux cases sont adjacentes*/ + return (x1 == x2 + 1 && y1 == y2 + 1) || (x1 == x2 - 1 && y1 == y2 - 1) || + (x1 == x2 + 1 && y1 == y2 - 1) || (x1 == x2 - 1 && y1 == y2 + 1) || + (x1 == x2 + 1 && y1 == y2) || (x1 == x2 - 1 && y1 == y2) || + (x1 == x2 && y1 == y2 - 1) || (x1 == x2 && y1 == y2 + 1); +} + +void initialiser_grille(int grille) { + int i, j; + int ty = grille * taille_case; /*Taille en y de la grille choisie*/ + int tx = grille * taille_case; /*Taille en x de la grille choisie*/ + + FermerGraphique(); + InitialiserGraphique(); /* creation nouvelles fenetre aux dimensions de la grille choisie*/ + CreerFenetre(posx,posy,tx,ty+100); /*+100 pour indiquer tour joueur*/ + + for(i = 0; i < grille; i++){ + for(j = 0; j < grille; j++){ /*Tracer grille*/ + DessinerRectangle(j*taille_case, i*taille_case, taille_case, taille_case); + } + } +} \ No newline at end of file -- 2.47.0 From 44cf461f971d78b8ee2818f01e1892226819dc23 Mon Sep 17 00:00:00 2001 From: Anis BEKKOUCHE Date: Sun, 24 Nov 2024 10:40:37 +0100 Subject: [PATCH 2/2] fin --- DEV1.1/SAE1.1/bleu.bmp | Bin 0 -> 14894 bytes DEV1.1/SAE1.1/blocage.bmp | Bin 0 -> 14894 bytes DEV1.1/SAE1.1/blocus.c | 289 ++++++++++++++++++++++++++++++++++++++ DEV1.1/SAE1.1/blocus.h | 23 +++ DEV1.1/SAE1.1/rouge.bmp | Bin 0 -> 14894 bytes 5 files changed, 312 insertions(+) create mode 100644 DEV1.1/SAE1.1/bleu.bmp create mode 100644 DEV1.1/SAE1.1/blocage.bmp create mode 100644 DEV1.1/SAE1.1/blocus.c create mode 100644 DEV1.1/SAE1.1/blocus.h create mode 100644 DEV1.1/SAE1.1/rouge.bmp diff --git a/DEV1.1/SAE1.1/bleu.bmp b/DEV1.1/SAE1.1/bleu.bmp new file mode 100644 index 0000000000000000000000000000000000000000..30cb41131093eac1264d871d8919a3ef11c6dafe GIT binary patch literal 14894 zcmd6u2Y6LQ7RSl!y-h+0BqTuEYY8PlC=m#VAPErA1QbP0K!n9g7ewlc6e$7X3Wg#q zAi7G4Wl@Sk3|)!~8&G%gQ&;%bT|ak47T5jXH+hqJx4ictgm3u{m$`H2&Ya(zGiSg?OXRZrb)9v{?#sle{TNLyosuTa`SCB)|(9kqOVJpi@sXvyA8{c zw%n|V3X%{oUSbnfi=Y*e!#|R~$P|%2iYAA>-r$6&wU#leJe}rVvu>nCS8CObwdu>O zx`(a0hpf6`X5CDm&VDNV(5UYT3Ogl;W1>%w;{c{ehe~Aq4BF_1RCox{Q!L@0 zcHDrSprcn3ulPD)DyT^%DMpp0QDYhTe83w;WU%5xRz3eN(h7DGm7=$3ii+r|Fr=eq zg0(P{!3Oa`tx+c`gagAo=pNL@1VD&^6w#+v-)GUyC4x^f0np3rjjys)@sluRw`JO;EI+z>ol}~aRn&yMP9)O zWD_V%2R}_9&4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xT|9`U(=D5xJ4VBwS1CqCEvna(Y# zc35S6oarvJE;I03*Dy4V1{4O1vO+0(AOp*F(rf!$bi*Bn(Zo15woXPm4foph@UFHx z4Sx9u*Ol(lq}?X#G`Bia+N>xi5Tok!rCRe>pre4&h!ItFt91`kpQz==xDC^KV?JsO K6x4aMD*q3+Mj#dd literal 0 HcmV?d00001 diff --git a/DEV1.1/SAE1.1/blocage.bmp b/DEV1.1/SAE1.1/blocage.bmp new file mode 100644 index 0000000000000000000000000000000000000000..fc136c457ea3eb5b0835665db67de79f145b57f4 GIT binary patch literal 14894 zcmeH_!A=7)3`EOc@ClqaBGDrUZv6kRa4V~Aca)11I+sQ4de!L1OI0Om+kdXkvFJ|ooXMw9_#{?2_IE8y*yGN zEuwCuR^WGIfp|bNmY+iCg_1zU1mL4Gfq@`-l%lw&xzmIT_}-E1OP22>3ULfExrGb# zim{4uDgGL4L$-bqr9AR%dCDcfaAue@GzEOAj77kzNz95m3IwI2K-RSQar_DzPGgS; z$}?-kw6@Qo%}rU^9Q{^6Yrg}{GpfhbcY1h0vl>`U4+sY(Ge#cYq8JD|61Y?+ATT7m z_-&D4&D3lYR28N>=6%&y=a$=BO%6bB1<>FFi7>Ihx%B zi2icJ<-~7e50?n5uypa#T3GM{RVT9f#lmRN%qgB^HBp?|z_E95(r`0%e mrQf@eDgipM&cIEz3+ViUx*n4%D16%F266+rf!x4f-oOvaGh#ge literal 0 HcmV?d00001 diff --git a/DEV1.1/SAE1.1/blocus.c b/DEV1.1/SAE1.1/blocus.c new file mode 100644 index 0000000..577f85a --- /dev/null +++ b/DEV1.1/SAE1.1/blocus.c @@ -0,0 +1,289 @@ +#include +#include +#include +#include +#include "blocus.h" + + +#define posx 250 +#define posy 100 +#define taille_case 70 + + + +int main(void){ + + int case_click[9][9] = {0}; + int game = 1; + int joueur = 1; + int last_case_x_j1, last_case_y_j1; + int last_case_x_j2, last_case_y_j2; + int sprite = 0; + int sprite2 = 0; + int placement1 = 0; + int placement2 = 0; + int solo = 0; + int multi = 0; + int x = 0, y = 0, i, j; + int mode_grille = 0; + int grille = 0; + int tx = 0, ty = 0; + int case_x = 0, case_y = 0; + int rouge; + int bleu; + int blocage; + int gagnant = 0; + int aleatoirex; + int aleatoirey; + int coordX, coordY; + int blocX, blocY; + int deplacementX, deplacementY; + + + /* Pointeurs de fichiers pour les sprites */ + FILE *spriteRouge = fopen("rouge.bmp","r"); + FILE *spriteBleu = fopen("bleu.bmp","r"); + FILE *spriteBlocage = fopen("blocage.bmp","r"); + if(spriteRouge == NULL){ + printf("Le fichier 'rouge.bmp' est introuvable.\n"); + } else{ + printf("Le fichier 'rouge.bmp' est trouvé !\n"); + fclose(spriteRouge); + } + if(spriteBleu == NULL){ + printf("Le fichier 'bleu.bmp' est introuvable.\n"); + } else{ + printf("Le fichier 'bleu.bmp' est trouvé.\n"); + fclose(spriteBleu); + } + if(spriteBlocage == NULL){ + printf("Le fichier 'blocage.bmp' est introuvable.\n"); + } else{ + printf("Le fichier 'blocage.bmp' est trouvé.\n"); + fclose(spriteBlocage); + } + + + creer_menu(&solo,&multi,&mode_grille,&grille); + initialiser_grille(grille); + + /* Chargement des sprites du jeu*/ + ChargerImage("spriteBlocage", case_x*taille_case, case_y*taille_case,70,70, 70, 70); + blocage = ChargerSprite("blocage.bmp"); + if(blocage == -1){ + printf("Erreur lors du chargement du sprite");} + ChargerImage("spriteBleu", case_x*taille_case, case_y*taille_case,70,70, 70, 70); + bleu = ChargerSprite("bleu.bmp"); + if(bleu == -1){ + printf("Erreur lors du chargement du sprite");} + ChargerImage("spriteRouge", case_x*taille_case, case_y*taille_case,70,70, 70, 70); + rouge = ChargerSprite("rouge.bmp"); + if(rouge == -1){ + printf("Erreur lors du chargement du sprite");} + + +while(game==1){ + + while(placement1!=1 || placement2 != 1){ + + if(SourisCliquee()){ + x = _X; + y = _Y; + + case_x = x / taille_case; + case_y = y / taille_case; + + printf("case choisie : %d, %d\n", case_x, case_y); + + + + + + /* Premier tour */ + + if(case_x < grille && case_y < grille && case_click[case_x][case_y] != 1) { + + if(sprite == 0 && case_click[case_x][case_y] != 3){ + AfficherSprite(rouge, case_x*taille_case, case_y*taille_case); + sprite = 1; + last_case_x_j2 = case_x; /*j2 car il sera le deuxième à joueur sauf au placement pour pas le désavantager*/ + last_case_y_j2 = case_y; + case_click[case_x][case_y]=2; + if(solo == 1){ + CoordIA(grille, &coordX, &coordY); + AfficherSprite(bleu, (coordX-1)*taille_case, (coordY-1)*taille_case); + sprite2 =1; + placement1 = 1; + last_case_x_j1 = coordX-1; + last_case_y_j1 = coordY-1; + + + } + } + + else if(multi == 1 && sprite2 == 0 && case_click[case_x][case_y] != 2){ + AfficherSprite(bleu, case_x*taille_case, case_y*taille_case); + sprite2 = 1; + placement2 = 1; + last_case_x_j1 = case_x; + last_case_y_j1 = case_y; + case_click[case_x][case_y]=3; + ChoisirCouleurDessin(CouleurParNom("blue")); /*Affichage de l'indication de tour pour le joueur rouge en début de partie*/ + RemplirRectangle(0,ty+1,tx,ty-100); + } + + + + + + + + if(case_click[case_x][case_y] !=1 && case_click[case_x][case_y] !=2 && sprite == 1 && sprite2 == 1 && placement1!=1 && estAdjacent(last_case_x_j1, last_case_y_j1, case_x, case_y)) { + EffacerAncienSprite(last_case_x_j1*taille_case, last_case_y_j1*taille_case, taille_case, taille_case); + case_click[last_case_x_j1][last_case_y_j1]=0; + AfficherSprite(bleu, case_x*taille_case, case_y*taille_case); + last_case_x_j1 = case_x; /*recupère la coordonnée*/ + last_case_y_j1 = case_y; + placement1=1; + case_click[case_x][case_y]=3; + } + else if(case_click[case_x][case_y] != 1 && case_click[case_x][case_y] !=3 && sprite == 1 && sprite2 == 1 && placement2!= 1 && estAdjacent(last_case_x_j2, last_case_y_j2, case_x, case_y)) { + EffacerAncienSprite(last_case_x_j2*taille_case, last_case_y_j2*taille_case, taille_case, taille_case); + case_click[last_case_x_j2][last_case_y_j2]=0; + AfficherSprite(rouge, case_x*taille_case, case_y*taille_case); + last_case_x_j2 = case_x; + last_case_y_j2 = case_y; + placement2=1; + case_click[case_x][case_y]=2; + + } + } + } + } + if(SourisCliquee()){ + x = _X; + y = _Y; + + case_x = x / taille_case; + case_y = y / taille_case; + + printf("case choisie : %d, %d\n", case_x, case_y); + + + if(case_x < grille && case_y < grille && case_click[case_x][case_y] != 1) { + if(joueur == 1 && placement1 == 1 && case_click[case_x][case_y] != 1 && case_click[case_x][case_y]!=2 && case_click[case_x][case_y]!=3){ + AfficherSprite(blocage, case_x*taille_case+1, case_y*taille_case+1); + case_click[case_x][case_y]=1; + placement2-=1; + ChoisirCouleurDessin(CouleurParNom("red")); + RemplirRectangle(0,ty+1,tx,ty-100); + if(solo == 1){ + + for (i = 0; i < grille; i++) { + for (j = 0; j < grille; j++) { + if (case_click[j][i] == 3 && (j + 1 >= grille || case_click[j + 1][i] != 0) && + (j - 1 < 0 || case_click[j - 1][i] != 0) && + (i + 1 >= grille || case_click[j][i + 1] != 0) && + (i - 1 < 0 || case_click[j][i - 1] != 0) && + (j + 1 >= grille || i + 1 >= grille || case_click[j + 1][i + 1] != 0) && + (j + 1 >= grille || i - 1 < 0 || case_click[j + 1][i - 1] != 0) && + (j - 1 < 0 || i + 1 >= grille || case_click[j - 1][i + 1] != 0) && + (j - 1 < 0 || i - 1 < 0 || case_click[j - 1][i - 1] != 0)) { + printf("GG ROUGE\n"); + sleep(1); + gagnant = 2; + ecran_de_fin(gagnant); + } + } + } + do{ + do{ + DeplacementIAX(grille, &deplacementX); + }while(last_case_x_j1+deplacementX < 0 || last_case_x_j1+deplacementX >= grille); + do{ + DeplacementIAY(grille, &deplacementY); + }while((last_case_y_j1+deplacementY < 0 || last_case_y_j1+deplacementY >= grille)); + }while(case_click[last_case_x_j1+deplacementX][last_case_y_j1+deplacementY] != 0 || (deplacementX == 0 && deplacementY == 0)); + EffacerAncienSprite(last_case_x_j1*taille_case, last_case_y_j1*taille_case, taille_case, taille_case); + case_click[last_case_x_j1][last_case_y_j1]=0; + AfficherSprite(bleu, (last_case_x_j1+deplacementX)*taille_case, (last_case_y_j1+deplacementY)*taille_case); + last_case_x_j1 = last_case_x_j1 + deplacementX; /*recupère la coordonnée*/ + last_case_y_j1 = last_case_y_j1 + deplacementY; + placement1=1; + case_click[last_case_x_j1][last_case_y_j1]=3; + + do{ + CoordBlocageIA(grille, &blocX, &blocY); + }while(case_click[blocX-1][blocY-1] != 0); + AfficherSprite(blocage, (blocX-1)*taille_case, (blocY-1)*taille_case); + case_click[blocX-1][blocY-1] = 1; + } + } + + else if(joueur == -1 && placement2 == 1 && case_click[case_x][case_y] != 1 && case_click[case_x][case_y]!=2 && case_click[case_x][case_y]!=3){ + if(multi == 1){ + AfficherSprite(blocage, case_x*taille_case, case_y*taille_case); + case_click[case_x][case_y]=1; + placement1-=1; + ChoisirCouleurDessin(CouleurParNom("blue")); + RemplirRectangle(0,ty+1,tx,ty-100); + } + + } + + /*Vérification si les joueurs peuvent encore bouger*/ + for (i = 0; i < grille; i++) { + for (j = 0; j < grille; j++) { + if (case_click[j][i] == 2 && (j + 1 >= grille || case_click[j + 1][i] != 0) && + (j - 1 < 0 || case_click[j - 1][i] != 0) && + (i + 1 >= grille || case_click[j][i + 1] != 0) && + (i - 1 < 0 || case_click[j][i - 1] != 0) && + (j + 1 >= grille || i + 1 >= grille || case_click[j + 1][i + 1] != 0) && + (j + 1 >= grille || i - 1 < 0 || case_click[j + 1][i - 1] != 0) && + (j - 1 < 0 || i + 1 >= grille || case_click[j - 1][i + 1] != 0) && + (j - 1 < 0 || i - 1 < 0 || case_click[j - 1][i - 1] != 0)) { + printf("GG BLEU\n"); + sleep(1); + gagnant = 1; + ecran_de_fin(gagnant); + } + if (case_click[j][i] == 3 && (j + 1 >= grille || case_click[j + 1][i] != 0) && + (j - 1 < 0 || case_click[j - 1][i] != 0) && + (i + 1 >= grille || case_click[j][i + 1] != 0) && + (i - 1 < 0 || case_click[j][i - 1] != 0) && + (j + 1 >= grille || i + 1 >= grille || case_click[j + 1][i + 1] != 0) && + (j + 1 >= grille || i - 1 < 0 || case_click[j + 1][i - 1] != 0) && + (j - 1 < 0 || i + 1 >= grille || case_click[j - 1][i + 1] != 0) && + (j - 1 < 0 || i - 1 < 0 || case_click[j - 1][i - 1] != 0)) { + printf("GG ROUGE\n"); + sleep(1); + gagnant = 2; + ecran_de_fin(gagnant); + + } + + } + } + } + if(multi == 1){ + /*Changement de joueur sauf lors des placements des pions*/ + + joueur=-(joueur); + } + } + + } + + + + + + + + + /*Fermeture des fichiers*/ + fclose(spriteRouge); + fclose(spriteBleu); + fclose(spriteBlocage); + +} diff --git a/DEV1.1/SAE1.1/blocus.h b/DEV1.1/SAE1.1/blocus.h new file mode 100644 index 0000000..25f2173 --- /dev/null +++ b/DEV1.1/SAE1.1/blocus.h @@ -0,0 +1,23 @@ +#ifndef BLOCUS_H +#define BLOCUS_H + +#include +#include +#include +#include + +#define posx 250 +#define posy 100 +#define taille_case 70 + +void EffacerAncienSprite(int x_ancien, int y_ancien, int largeur, int hauteur); +int estAdjacent(int x1, int y1, int x2, int y2); +int ecran_de_fin(int gagnant); +void creer_menu(int *solo, int *multi, int *mode_grille, int *grille); +void initialiser_grille(int grille); +void CoordIA(int grille, int *coordX, int *coordY); +void CoordBlocageIA(int grille, int *blocX, int *blocY); +void DeplacementIAX(int grille, int *deplacementX); +void DeplacementIAY(int grille, int *deplacementY); + +#endif /*BLOCUS_H*/ \ No newline at end of file diff --git a/DEV1.1/SAE1.1/rouge.bmp b/DEV1.1/SAE1.1/rouge.bmp new file mode 100644 index 0000000000000000000000000000000000000000..cb0ae9cb983933f5e7570f54931718ca2fba44d1 GIT binary patch literal 14894 zcmeHOd3aRS6`wcr_SxPfLlP1~_DuF=lG!J0mK~(BsJLQ41Vj*libFuDxPyRfYQ?2e zt)O*Z*aaa0QKVnh`iU&xSGCouwYAz(3hnQ`mw9>fX30w+(m$H-Fy43HUC!^GbI&>V z+~=UtH9>>)=f!Us{tapWM;NlC`hNzb|LFY*hrOYoL?K@&8I>Ymvc@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