Commit 7a8c3fc0 authored by Erwan's avatar Erwan

Ajout de la condition de victoire fonctionnelle

/!\BESOIN DE FIC SUR LA GENERATION DES MINES/!\
parent b1ab7ffa
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <math.h> #include <string.h>
#define SIZE_OF_HEX 25 #define SIZE_OF_HEX 25
...@@ -12,7 +12,7 @@ struct celluleDemineur{ ...@@ -12,7 +12,7 @@ struct celluleDemineur{
int nearbyMine; int nearbyMine;
Vector2 pos; Vector2 pos;
bool isPressed; bool isPressed;
bool isFlaged; bool ifFlagged;
bool isNeareast; bool isNeareast;
Color couleurCase; Color couleurCase;
}; };
...@@ -94,7 +94,7 @@ bool revelerVoisins(int line, int column, CelluleDemineur** matriceMines, int nb ...@@ -94,7 +94,7 @@ bool revelerVoisins(int line, int column, CelluleDemineur** matriceMines, int nb
bool revelerCase(CelluleDemineur** matriceMines, int line, int column, int nbLigneMatrice, int nbColonneMatrice){ bool revelerCase(CelluleDemineur** matriceMines, int line, int column, int nbLigneMatrice, int nbColonneMatrice){
bool res = false; bool res = false;
if(!matriceMines[line][column]->isFlaged && !matriceMines[line][column]->isPressed){ if(!matriceMines[line][column]->ifFlagged && !matriceMines[line][column]->isPressed){
matriceMines[line][column]->isPressed = true; matriceMines[line][column]->isPressed = true;
if(matriceMines[line][column]->nearbyMine == 0){ if(matriceMines[line][column]->nearbyMine == 0){
...@@ -115,7 +115,7 @@ void generationMines(int nbMines, int nbLigneMatrice, int nbColonneMatrice, Cell ...@@ -115,7 +115,7 @@ void generationMines(int nbMines, int nbLigneMatrice, int nbColonneMatrice, Cell
int lineRand = rand()%nbLigneMatrice; int lineRand = rand()%nbLigneMatrice;
int colRand = rand()%nbColonneMatrice; int colRand = rand()%nbColonneMatrice;
if(!containsMine(lineRand, colRand, matriceMines)){ while(!containsMine(lineRand, colRand, matriceMines)){
matriceMines[lineRand][colRand]->hasMine = true; matriceMines[lineRand][colRand]->hasMine = true;
matriceMines[lineRand][colRand]->nearbyMine = -9; matriceMines[lineRand][colRand]->nearbyMine = -9;
incrementationVoisinMine(lineRand, colRand, matriceMines, nbLigneMatrice, nbColonneMatrice); incrementationVoisinMine(lineRand, colRand, matriceMines, nbLigneMatrice, nbColonneMatrice);
...@@ -131,7 +131,7 @@ void initGrille(int nbLigneMatrice, int nbColonneMatrice, CelluleDemineur** matr ...@@ -131,7 +131,7 @@ void initGrille(int nbLigneMatrice, int nbColonneMatrice, CelluleDemineur** matr
matriceMines[i][j] = malloc(sizeof(struct celluleDemineur)); matriceMines[i][j] = malloc(sizeof(struct celluleDemineur));
matriceMines[i][j]->hasMine = false; matriceMines[i][j]->hasMine = false;
matriceMines[i][j]->isPressed = false; matriceMines[i][j]->isPressed = false;
matriceMines[i][j]->isFlaged = false; matriceMines[i][j]->ifFlagged = false;
matriceMines[i][j]->isNeareast = false; matriceMines[i][j]->isNeareast = false;
matriceMines[i][j]->nearbyMine = 0; matriceMines[i][j]->nearbyMine = 0;
matriceMines[i][j]->line = i; matriceMines[i][j]->line = i;
...@@ -156,7 +156,7 @@ int main(void) ...@@ -156,7 +156,7 @@ int main(void)
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
const int screenWidth = 1280; const int screenWidth = 1280;
const int screenHeight = 1024; const int screenHeight = 800;
int fontSizeBig = screenWidth*screenHeight/30000; int fontSizeBig = screenWidth*screenHeight/30000;
int fontSizeSmall = screenWidth*screenHeight/35000; int fontSizeSmall = screenWidth*screenHeight/35000;
InitWindow(screenWidth, screenHeight, "HexaSweeper - Erwan MERLY"); InitWindow(screenWidth, screenHeight, "HexaSweeper - Erwan MERLY");
...@@ -164,8 +164,8 @@ int main(void) ...@@ -164,8 +164,8 @@ int main(void)
srand(time(NULL)); srand(time(NULL));
int nbLigneMatrice = 10, nbColonneMatrice = 10, nbMines = 20; int nbLigneMatrice = 10, nbColonneMatrice = 10, nbMines = 80;
int curCaseX = 0, curCaseY = 0, remainingMines = nbMines; int curCaseX = 0, curCaseY = 0, flaggedMines = 0;
bool lose = false, win = false; bool lose = false, win = false;
//CREATION DE LA MATRICE DES MINES //CREATION DE LA MATRICE DES MINES
...@@ -187,14 +187,14 @@ int main(void) ...@@ -187,14 +187,14 @@ int main(void)
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON) && !lose && !win){ if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON) && !lose && !win){
if(!matriceMines[curCaseX][curCaseY]->isPressed){ if(!matriceMines[curCaseX][curCaseY]->isPressed){
matriceMines[curCaseX][curCaseY]->isFlaged = !matriceMines[curCaseX][curCaseY]->isFlaged; matriceMines[curCaseX][curCaseY]->ifFlagged = !matriceMines[curCaseX][curCaseY]->ifFlagged;
if(matriceMines[curCaseX][curCaseY]->isFlaged){ if(matriceMines[curCaseX][curCaseY]->ifFlagged){
matriceMines[curCaseX][curCaseY]->couleurCase = GREEN; matriceMines[curCaseX][curCaseY]->couleurCase = GREEN;
remainingMines--; flaggedMines++;
} }
else{ else{
matriceMines[curCaseX][curCaseY]->couleurCase = DARKGRAY; matriceMines[curCaseX][curCaseY]->couleurCase = DARKGRAY;
remainingMines++; flaggedMines--;
} }
} }
} }
...@@ -218,11 +218,22 @@ int main(void) ...@@ -218,11 +218,22 @@ int main(void)
} }
} }
if(flaggedMines == nbMines){
int trueFlagged = 0;
for(int i=0; i<nbLigneMatrice; i++){
for(int j=0; j<nbColonneMatrice; j++){
if(matriceMines[i][j]->hasMine && matriceMines[i][j]->ifFlagged) trueFlagged++;
}
}
if(trueFlagged == nbMines) win = true;
}
if(win || lose){ if(win || lose){
if(IsKeyPressed('R')){ if(IsKeyPressed('R')){
lose = false; lose = false;
win = false;
flaggedMines = 0;
initGrille(nbLigneMatrice, nbColonneMatrice, matriceMines); initGrille(nbLigneMatrice, nbColonneMatrice, matriceMines);
generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines); generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines);
} }
...@@ -244,11 +255,21 @@ int main(void) ...@@ -244,11 +255,21 @@ int main(void)
} }
} }
DrawRectangle(0, screenHeight-75, screenWidth, 75, Fade(LIGHTGRAY, 0.5f));
DrawText(TextFormat("MINE FLAGGED: %d/%d", flaggedMines, nbMines), 50, screenHeight-50, fontSizeBig, GRAY);
if(lose || win){ if(lose || win){
DrawRectangle(0, screenHeight*0.55, screenWidth, screenHeight/8, Fade(GRAY, 0.8f)); DrawRectangle(0, screenHeight*0.55, screenWidth, screenHeight/8, Fade(GRAY, 0.8f));
if(lose) DrawText("GAME OVER", screenWidth/2-4*fontSizeBig, screenHeight*0.58, fontSizeBig, MAROON); if(lose){
if(win) DrawText("YOU WIN!", screenWidth/2-3*fontSizeBig, screenHeight*0.57, fontSizeBig, LIME); DrawText("GAME OVER", screenWidth/2-strlen("GAME OVER")/2*fontSizeBig, screenHeight*0.58, fontSizeBig, MAROON);
DrawText("PRESS R TO REPLAY", screenWidth/2-6*fontSizeSmall, screenHeight*0.62, fontSizeSmall, DARKGRAY); for(int i=0; i<nbLigneMatrice; i++){
for(int j=0; j<nbColonneMatrice; j++){
if(containsMine(i, j, matriceMines)) revelerCase(matriceMines, i, j, nbLigneMatrice, nbColonneMatrice);
}
}
}
if(win) DrawText("YOU WIN!", screenWidth/2-strlen("YOU WIN!")/2*fontSizeBig, screenHeight*0.57, fontSizeBig, LIME);
DrawText("PRESS R TO REPLAY", screenWidth/2-strlen("PRESS R TO REPLAY")/2*fontSizeSmall, screenHeight*0.62, fontSizeSmall, DARKGRAY);
} }
EndDrawing(); EndDrawing();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment