diff --git a/src/2048_engine.c b/src/2048_engine.c index a183c70..5001f1b 100644 --- a/src/2048_engine.c +++ b/src/2048_engine.c @@ -83,13 +83,14 @@ void merge(struct gamestate *g, direction d, void (*callback)(struct gamestate * if (g->grid[x][y] && (g->grid[x][y] == g->grid[x+xoff][y+yoff])) {\ g->grid[x][y] += g->grid[x+xoff][y+yoff];\ g->grid[x+xoff][y+yoff] = 0;\ - g->score_last = g->grid[x][y];\ + g->score_last += g->grid[x][y];\ g->score += g->grid[x][y];\ g->moved = 1;\ }\ } while (0) int x, y; + g->score_last = 0; if (d == dir_left) { for (x = 0; x < g->opts->grid_width - 1; ++x) { diff --git a/src/2048_rewrite.c b/src/2048_rewrite.c index bc7c6b5..98ccc52 100644 --- a/src/2048_rewrite.c +++ b/src/2048_rewrite.c @@ -70,9 +70,7 @@ int get_keypress(void) return getch(); } -#elif VT100_COMPATIBLE - -#else +#else /* vt100 and standard shared functions */ struct termios sattr; void drawstate_clear() { @@ -90,8 +88,19 @@ void drawstate_init(void) tcsetattr(STDOUT_FILENO, TCSANOW, &tattr); } +int get_keypress(void) +{ + return fgetc(stdin); +} + + void draw_screen(struct gamestate *g) { + /* Clear the screen each draw if we are able to */ +#ifdef VT100_COMPATIBLE + printf("\033[2J\033[H"); +#endif + printf("HISCORE: %ld |", g->score_high); printf("| SCORE: %ld ", g->score); if (g->score_last) printf("(+%ld)", g->score_last); @@ -114,13 +123,7 @@ void draw_screen(struct gamestate *g) ITER(g->opts->grid_width, printf("------")); printf("-\n\n"); } - -int get_keypress(void) -{ - return fgetc(stdin); -} - -#endif +#endif /* CURSES */ void ddraw(struct gamestate *g) {