Fix curses not displaying until keypress. Callback example demonstrating some pseudo-animation
This commit is contained in:
parent
2b1d230330
commit
01af91121b
|
@ -13,19 +13,6 @@
|
|||
} while (0)
|
||||
|
||||
#ifdef HAVE_CURSES
|
||||
void drawstate_init(void)
|
||||
{
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
curs_set(FALSE);
|
||||
}
|
||||
|
||||
void drawstate_clear(void)
|
||||
{
|
||||
endwin();
|
||||
}
|
||||
|
||||
void draw_screen(struct gamestate *g)
|
||||
{
|
||||
static WINDOW *gamewin;
|
||||
|
@ -64,6 +51,20 @@ void draw_screen(struct gamestate *g)
|
|||
wrefresh(gamewin);
|
||||
}
|
||||
|
||||
void drawstate_init(void)
|
||||
{
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
curs_set(FALSE);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void drawstate_clear(void)
|
||||
{
|
||||
endwin();
|
||||
}
|
||||
|
||||
int get_keypress(void)
|
||||
{
|
||||
return getch();
|
||||
|
@ -104,7 +105,7 @@ void draw_screen(struct gamestate *g)
|
|||
printf("|");
|
||||
for (x = 0; x < g->opts->grid_width; x++) {
|
||||
if (g->grid[x][y])
|
||||
printf("%*ld |", 4, g->grid[x][y]);
|
||||
printf("%*ld |", g->print_width, g->grid[x][y]);
|
||||
else
|
||||
printf(" |");
|
||||
}
|
||||
|
@ -121,6 +122,12 @@ int get_keypress(void)
|
|||
|
||||
#endif
|
||||
|
||||
void ddraw(struct gamestate *g)
|
||||
{
|
||||
draw_screen(g);
|
||||
usleep(30000);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct gamestate *g = gamestate_init(gameoptions_default());
|
||||
|
@ -137,12 +144,12 @@ int main(int argc, char **argv)
|
|||
if (ch == 'q') { goto endloop; }
|
||||
} while (strchr("hjkl", ch) == NULL);
|
||||
|
||||
gamestate_tick(g, ch, NULL);
|
||||
|
||||
if (!moves_available(g)) {
|
||||
printf("You lose\n");
|
||||
break;
|
||||
}
|
||||
|
||||
gamestate_tick(g, ch, ddraw);
|
||||
}
|
||||
endloop:
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user