mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-26 09:02:16 +11:00
Update the game logic to take note of high scores
This commit is contained in:
parent
fc11d95fbb
commit
f18b23b08a
4 changed files with 32 additions and 18 deletions
43
src/main.c
43
src/main.c
|
|
@ -11,6 +11,19 @@
|
|||
#include "game_graphics.h"
|
||||
#include "monitor_subroutines.h"
|
||||
|
||||
// Make sure the loading screen is included
|
||||
#pragma require __loading_screen
|
||||
|
||||
#define MOVES_TEXT_X 32
|
||||
#define MOVES_TEXT_Y 61
|
||||
#define MOVES_TEXT_WIDTH 5
|
||||
|
||||
#define SCORE_TEXT_X 32
|
||||
#define SCORE_TEXT_Y 29
|
||||
#define SCORE_TEXT_WIDTH 5
|
||||
|
||||
#define WIN_SCORE_BONUS 10000
|
||||
|
||||
void init(void);
|
||||
|
||||
// Low level initialization
|
||||
|
|
@ -26,25 +39,21 @@ void init(void) {
|
|||
memset((void*)DISPLAY_PAGE_2, 0, DISPLAY_PAGE_SIZE);
|
||||
}
|
||||
|
||||
#define MOVES_TEXT_X 32
|
||||
#define MOVES_TEXT_Y 61
|
||||
#define MOVES_TEXT_WIDTH 5
|
||||
|
||||
#define SCORE_TEXT_X 32
|
||||
#define SCORE_TEXT_Y 29
|
||||
#define SCORE_TEXT_WIDTH 5
|
||||
#pragma require __loading_screen
|
||||
|
||||
__task int main(void) {
|
||||
uint16_t moves_count;
|
||||
uint16_t score;
|
||||
uint8_t done;
|
||||
uint16_t score = 0;
|
||||
uint16_t hi_score = 0;
|
||||
int8_t done = 0;
|
||||
|
||||
init();
|
||||
|
||||
while(1){ // Outer loop
|
||||
moves_count = 0;
|
||||
|
||||
// Check if we have a new high-score
|
||||
if (score > hi_score) hi_score = score;
|
||||
|
||||
// Reset the game, calculate the initial score depending on which tiles we randomly get
|
||||
score = reset_game();
|
||||
|
||||
// Draw the initial state of the game
|
||||
|
|
@ -88,8 +97,11 @@ __task int main(void) {
|
|||
moves_count++;
|
||||
|
||||
// If we have won, break out of this loop
|
||||
if(done) break;
|
||||
|
||||
if(done) {
|
||||
score += WIN_SCORE_BONUS;
|
||||
break;
|
||||
}
|
||||
|
||||
// Draw the number of moves
|
||||
draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y);
|
||||
|
||||
|
|
@ -98,7 +110,10 @@ __task int main(void) {
|
|||
|
||||
// Unable to add a tile: we ran out of space and lost!!!
|
||||
uint8_t random_tile_off = add_random_tile();
|
||||
if(!random_tile_off) break;
|
||||
if(!random_tile_off) {
|
||||
done = -1; // Lost the game
|
||||
break;
|
||||
}
|
||||
|
||||
score = calculate_score();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue