Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Mini-Projet-TETRIS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DIDON Maya
Mini-Projet-TETRIS
Commits
013caf42
Commit
013caf42
authored
Oct 28, 2020
by
DIDON Maya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout d'un "high score" avec fichier txt
parent
a7bc7d6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletion
+33
-1
high-score.txt
high-score.txt
+1
-0
tetris.c
tetris.c
+32
-1
tetris.exe
tetris.exe
+0
-0
No files found.
high-score.txt
0 → 100644
View file @
013caf42
9
\ No newline at end of file
tetris.c
View file @
013caf42
...
...
@@ -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
();
}
...
...
tetris.exe
View file @
013caf42
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment