/branches/dd/uspace/app/tetris/scores.c |
---|
196,5 → 196,38 |
} |
} |
int loadscores(void) |
{ |
FILE *f; |
size_t cnt; |
int rc; |
f = fopen("/data/tetris.sco", "rb"); |
if (f == NULL) |
return ENOENT; |
cnt = fread(scores, sizeof(struct highscore), NUMSPOTS, f); |
rc = fclose(f); |
if (cnt != NUMSPOTS || rc != 0) |
return EIO; |
return EOK; |
} |
void savescores(void) |
{ |
FILE *f; |
size_t cnt; |
int rc; |
f = fopen("/data/tetris.sco", "wb"); |
cnt = fwrite(scores, sizeof(struct highscore), NUMSPOTS, f); |
rc = fclose(f); |
if (cnt != NUMSPOTS || rc != 0) |
printf("Error saving score table\n"); |
} |
/** @} |
*/ |
/branches/dd/uspace/app/tetris/screen.c |
---|
62,6 → 62,8 |
static int curscore; |
static int isset; /* true => terminal is in game mode */ |
static int use_color; /* true => use colors */ |
static const struct shape *lastshape; |
77,11 → 79,14 |
static void start_standout(uint32_t color) |
{ |
console_set_rgb_color(fphone(stdout), 0xf0f0f0, color); |
fflush(stdout); |
console_set_rgb_color(fphone(stdout), 0xf0f0f0, |
use_color ? color : 0x000000); |
} |
static void resume_normal(void) |
{ |
fflush(stdout); |
console_set_rgb_color(fphone(stdout), 0, 0xf0f0f0); |
} |
114,6 → 119,7 |
void moveto(int r, int c) |
{ |
fflush(stdout); |
console_goto(fphone(stdout), c, r); |
} |
124,6 → 130,18 |
return console_get_size(fphone(stdout), &ws->ws_col, &ws->ws_row); |
} |
static int get_display_color_sup(void) |
{ |
int rc; |
int ccap; |
rc = console_get_color_cap(fphone(stdout), &ccap); |
if (rc != 0) |
return 0; |
return (ccap >= CONSOLE_CCAP_RGB); |
} |
/* |
* Set up screen mode. |
*/ |
138,6 → 156,8 |
Rows = ws.ws_row; |
Cols = ws.ws_col; |
} |
use_color = get_display_color_sup(); |
if ((Rows < MINROWS) || (Cols < MINCOLS)) { |
char smallscr[55]; |
/branches/dd/uspace/app/tetris/scores.h |
---|
64,6 → 64,8 |
extern void showscores(int); |
extern void initscores(void); |
extern void insertscore(int score, int level); |
extern int loadscores(void); |
extern void savescores(void); |
/** @} |
*/ |
/branches/dd/uspace/app/tetris/tetris.c |
---|
49,6 → 49,7 |
#include <sys/time.h> |
#include <sys/types.h> |
#include <err.h> |
#include <errno.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
206,6 → 207,7 |
printf("off"); |
break; |
case 'h': |
loadscores(); |
showscores(firstgame); |
tetris_menu_draw(*level); |
break; |
297,7 → 299,9 |
key_write[4], key_write[5]); |
scr_init(); |
initscores(); |
if (loadscores() != EOK) |
initscores(); |
while (tetris_menu(&level)) { |
fallrate = 1000000 / level; |
415,7 → 419,9 |
} |
scr_clear(); |
loadscores(); |
insertscore(score, level); |
savescores(); |
score = 0; |
} |