summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sirtet.c21
-rw-r--r--ui.c8
-rw-r--r--ui.h1
3 files changed, 16 insertions, 14 deletions
diff --git a/sirtet.c b/sirtet.c
index 79685ae..b3945fb 100644
--- a/sirtet.c
+++ b/sirtet.c
@@ -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();
diff --git a/ui.c b/ui.c
index 70bfe5c..1df1a33 100644
--- a/ui.c
+++ b/ui.c
@@ -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");
diff --git a/ui.h b/ui.h
index 0a4c2e1..04fc27b 100644
--- a/ui.h
+++ b/ui.h
@@ -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