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 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#define SIZE_OF_HEX 25
......@@ -12,7 +12,7 @@ struct celluleDemineur{
int nearbyMine;
Vector2 pos;
bool isPressed;
bool isFlaged;
bool ifFlagged;
bool isNeareast;
Color couleurCase;
};
......@@ -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 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;
if(matriceMines[line][column]->nearbyMine == 0){
......@@ -115,7 +115,7 @@ void generationMines(int nbMines, int nbLigneMatrice, int nbColonneMatrice, Cell
int lineRand = rand()%nbLigneMatrice;
int colRand = rand()%nbColonneMatrice;
if(!containsMine(lineRand, colRand, matriceMines)){
while(!containsMine(lineRand, colRand, matriceMines)){
matriceMines[lineRand][colRand]->hasMine = true;
matriceMines[lineRand][colRand]->nearbyMine = -9;
incrementationVoisinMine(lineRand, colRand, matriceMines, nbLigneMatrice, nbColonneMatrice);
......@@ -131,7 +131,7 @@ void initGrille(int nbLigneMatrice, int nbColonneMatrice, CelluleDemineur** matr
matriceMines[i][j] = malloc(sizeof(struct celluleDemineur));
matriceMines[i][j]->hasMine = false;
matriceMines[i][j]->isPressed = false;
matriceMines[i][j]->isFlaged = false;
matriceMines[i][j]->ifFlagged = false;
matriceMines[i][j]->isNeareast = false;
matriceMines[i][j]->nearbyMine = 0;
matriceMines[i][j]->line = i;
......@@ -156,7 +156,7 @@ int main(void)
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 1280;
const int screenHeight = 1024;
const int screenHeight = 800;
int fontSizeBig = screenWidth*screenHeight/30000;
int fontSizeSmall = screenWidth*screenHeight/35000;
InitWindow(screenWidth, screenHeight, "HexaSweeper - Erwan MERLY");
......@@ -164,8 +164,8 @@ int main(void)
srand(time(NULL));
int nbLigneMatrice = 10, nbColonneMatrice = 10, nbMines = 20;
int curCaseX = 0, curCaseY = 0, remainingMines = nbMines;
int nbLigneMatrice = 10, nbColonneMatrice = 10, nbMines = 80;
int curCaseX = 0, curCaseY = 0, flaggedMines = 0;
bool lose = false, win = false;
//CREATION DE LA MATRICE DES MINES
......@@ -187,14 +187,14 @@ int main(void)
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON) && !lose && !win){
if(!matriceMines[curCaseX][curCaseY]->isPressed){
matriceMines[curCaseX][curCaseY]->isFlaged = !matriceMines[curCaseX][curCaseY]->isFlaged;
if(matriceMines[curCaseX][curCaseY]->isFlaged){
matriceMines[curCaseX][curCaseY]->ifFlagged = !matriceMines[curCaseX][curCaseY]->ifFlagged;
if(matriceMines[curCaseX][curCaseY]->ifFlagged){
matriceMines[curCaseX][curCaseY]->couleurCase = GREEN;
remainingMines--;
flaggedMines++;
}
else{
matriceMines[curCaseX][curCaseY]->couleurCase = DARKGRAY;
remainingMines++;
flaggedMines--;
}
}
}
......@@ -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(IsKeyPressed('R')){
lose = false;
win = false;
flaggedMines = 0;
initGrille(nbLigneMatrice, nbColonneMatrice, matriceMines);
generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines);
}
......@@ -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){
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(win) DrawText("YOU WIN!", screenWidth/2-3*fontSizeBig, screenHeight*0.57, fontSizeBig, LIME);
DrawText("PRESS R TO REPLAY", screenWidth/2-6*fontSizeSmall, screenHeight*0.62, fontSizeSmall, DARKGRAY);
if(lose){
DrawText("GAME OVER", screenWidth/2-strlen("GAME OVER")/2*fontSizeBig, screenHeight*0.58, fontSizeBig, MAROON);
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();
......
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