Commit 2f69a3df authored by Erwan's avatar Erwan

Ajout du timer (incrémentation que lors du jeu)

parent 3d9ce1c2
...@@ -172,6 +172,7 @@ int main(void) ...@@ -172,6 +172,7 @@ int main(void)
int nbLigneMatrice = 17, nbColonneMatrice = 21, nbMines = 80; int nbLigneMatrice = 17, nbColonneMatrice = 21, nbMines = 80;
int curCaseX = 0, curCaseY = 0, flaggedMines = 0; int curCaseX = 0, curCaseY = 0, flaggedMines = 0;
bool lose = false, win = false; bool lose = false, win = false;
float timeEllapsed = 0;
//CREATION DE LA MATRICE DES MINES //CREATION DE LA MATRICE DES MINES
CelluleDemineur** matriceMines = malloc(nbLigneMatrice * sizeof(CelluleDemineur *)); CelluleDemineur** matriceMines = malloc(nbLigneMatrice * sizeof(CelluleDemineur *));
...@@ -186,6 +187,8 @@ int main(void) ...@@ -186,6 +187,8 @@ int main(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if(!win && !lose) timeEllapsed += GetFrameTime();
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !lose && !win){ if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !lose && !win){
lose = revelerCase(matriceMines, curCaseX, curCaseY, nbLigneMatrice, nbColonneMatrice); lose = revelerCase(matriceMines, curCaseX, curCaseY, nbLigneMatrice, nbColonneMatrice);
} }
...@@ -239,6 +242,7 @@ int main(void) ...@@ -239,6 +242,7 @@ int main(void)
lose = false; lose = false;
win = false; win = false;
flaggedMines = 0; flaggedMines = 0;
timeEllapsed = 0;
initGrille(nbLigneMatrice, nbColonneMatrice, matriceMines); initGrille(nbLigneMatrice, nbColonneMatrice, matriceMines);
generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines); generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines);
} }
...@@ -250,6 +254,7 @@ int main(void) ...@@ -250,6 +254,7 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
//AFFICHAGE DE LA GRILLE
for(int i=0; i<nbLigneMatrice; i++){ for(int i=0; i<nbLigneMatrice; i++){
for(int j=0; j<nbColonneMatrice; j++){ for(int j=0; j<nbColonneMatrice; j++){
DrawPoly((Vector2){matriceMines[i][j]->pos.x, matriceMines[i][j]->pos.y}, 6, SIZE_OF_HEX, 0, GRAY); DrawPoly((Vector2){matriceMines[i][j]->pos.x, matriceMines[i][j]->pos.y}, 6, SIZE_OF_HEX, 0, GRAY);
...@@ -260,9 +265,12 @@ int main(void) ...@@ -260,9 +265,12 @@ int main(void)
} }
} }
//AFFICHAGE DE L'INTERFACE
DrawRectangle(0, screenHeight-75, screenWidth, 75, Fade(LIGHTGRAY, 0.5f)); DrawRectangle(0, screenHeight-75, screenWidth, 75, Fade(LIGHTGRAY, 0.5f));
DrawText(TextFormat("MINE FLAGGED: %d/%d", flaggedMines, nbMines), 50, screenHeight-50, fontSizeBig, GRAY); DrawText(TextFormat("MINE FLAGGED: %d/%d", flaggedMines, nbMines), 50, screenHeight-50, fontSizeBig, GRAY);
DrawText(TextFormat("Time: %d s", (int)timeEllapsed), screenWidth-250, screenHeight-50, fontSizeBig, GRAY);
//AFFICHAGE FIN DE PARTIE
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){ if(lose){
...@@ -276,7 +284,7 @@ int main(void) ...@@ -276,7 +284,7 @@ int main(void)
if(win) DrawText("YOU WIN!", screenWidth/2-strlen("YOU WIN!")/2*fontSizeBig, screenHeight*0.57, fontSizeBig, LIME); 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); 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