Commit 013caf42 authored by DIDON Maya's avatar DIDON Maya

Ajout d'un "high score" avec fichier txt

parent a7bc7d6a
9
\ No newline at end of file
......@@ -17,6 +17,9 @@
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
......@@ -102,6 +105,10 @@ static bool ResolveTurnMovement();
static void CheckDetection();
static void CheckCompletion();
static int DeleteCompleteLines();
static unsigned int ReadHighScore();
// High score variable
static int highScore = 0;
//------------------------------------------------------------------------------------
// Program main entry point
......@@ -150,6 +157,7 @@ void InitGame(void)
level = 1;
lines = 0;
score = 0;
highScore=ReadHighScore();
fadingColor = GRAY;
......@@ -267,6 +275,14 @@ void UpdateGame(void)
if (grid[i][j] == FULL)
{
gameOver = true;
if(score>highScore){
char *filename = "high-score.txt";
FILE* dataFile;
dataFile = fopen(filename,"w+");
fprintf(dataFile,"%d",score);
fclose(dataFile);
highScore=ReadHighScore();
}
}
}
}
......@@ -302,6 +318,17 @@ void UpdateGame(void)
}
}
// Reads high score in text document
static unsigned int ReadHighScore(){
char *filename = "high-score.txt";
FILE* dataFile;
dataFile = fopen(filename,"r");
unsigned int highScore;
fscanf(dataFile,"%u", &highScore);
fclose(dataFile);
return(highScore);
}
// Draw game (one frame)
void DrawGame(void)
{
......@@ -394,7 +421,11 @@ void DrawGame(void)
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
}
else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
else{
DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
DrawText(TextFormat("HIGH SCORE: %06i", highScore),GetScreenWidth()/2 - MeasureText("HIGH SCORE: 000000", 20)/2, GetScreenHeight()/2 - 90, 20, RED);
DrawText(TextFormat("YOUR SCORE: %06i", score),GetScreenWidth()/2 - MeasureText("YOUR SCORE: 000000", 20)/2, GetScreenHeight()/2 - 130, 20, BLUE);
}
EndDrawing();
}
......
No preview for this file type
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