diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-06-06 12:36:14 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-06-06 12:36:14 +0800 |
commit | e5711dbe6dc7f38314971e154b57f49450e68a7c (patch) | |
tree | ef085c6ad29e2067c428bf5c71bfd1947fa33553 | |
parent | 5c43e5da6e3768b9c734fbd6a4a4b824f953d842 (diff) |
-rw-r--r-- | sirtet.c | 21 | ||||
-rw-r--r-- | ui.c | 8 | ||||
-rw-r--r-- | ui.h | 1 |
3 files changed, 16 insertions, 14 deletions
@@ -9,12 +9,6 @@ #include "ui.h" #include "util.h" -void clearmap(char* map, int mapH, int mapW) { - for (int b = 0; b < mapH * mapW; b++) { - map[b] = ' '; - } -} - struct clearfull_data { int rows; int cols; @@ -75,12 +69,16 @@ void sirtet(int H, int W, int P) { if (map == NULL) mallocfail(); + for (int b = 0; b < H * W; b++) { + // fill map with blank blocks + map[b] = ' '; + } + struct piece** hand = malloc(P * sizeof(struct piece*)); if (hand == NULL) mallocfail(); srand(time(NULL)); - clearmap(map, H, W); refillpieces(hand, P); bool over = false; @@ -106,13 +104,7 @@ void sirtet(int H, int W, int P) { printrect(0, 0, H, W); printmap(map, 1, 1, H, W); printhelp(4, 2 * W + 8); - - // display game stats - mvprintw(1, 2 * W + 8, "Points: %d", points); - if (combo) - mvprintw(2, 2 * W + 8, "Combo: %d", combo); - - refresh(); + printstats(points, combo, 1, 2 * W + 8); // select piece and position bool confirmed = false; @@ -247,6 +239,7 @@ void sirtet(int H, int W, int P) { if (!has_placeable) { // game over printmap(map, 1, 1, H, W); + printstats(points, combo, 1, 2 * W + 8); mvprintw(8, 2 * W + 8, "Game over"); mvprintw(9, 2 * W + 8, "Press any key to exit"); refresh(); @@ -67,6 +67,14 @@ void printpieces(struct piece** hand, int y, int x, int nhand, int highlight) { refresh(); } +void printstats(int points, int combo, int y, int x) { + mvprintw(y, x, "Points: %d", points); + if (combo) + mvprintw(y + 1, x, "Combo: %d", combo); + + refresh(); +} + void printhelp(int y, int x) { mvprintw(y, x, "Press arrow keys / wasd / hjkl to navigate"); mvprintw(y + 1, x, "[ or ] to switch pieces"); @@ -4,6 +4,7 @@ void printrect(int y, int x, int h, int w); void printmap(char* map, int y, int x, int mapH, int mapW); void printpiece(struct piece* pc, int y, int x, int color_pair); void printpieces(struct piece** hand, int y, int x, int nhand, int highlight); +void printstats(int points, int combo, int y, int x); void printhelp(int y, int x); #endif |