summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-06-01 15:47:02 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-06-01 15:47:02 +0800
commit384f833e839cf8f5e71b656cf7b390fc80d89e9d (patch)
tree35a3bba6131018624cd2bd3d8c2c4d3eee106b11
parentd191870068f89293353a67b164b4dbb3b3a71661 (diff)
Help text, wasd/hjkl navigation
-rw-r--r--sirtet.c18
-rw-r--r--ui.c6
-rw-r--r--ui.h1
3 files changed, 23 insertions, 2 deletions
diff --git a/sirtet.c b/sirtet.c
index 9e9d0b2..3dc76f3 100644
--- a/sirtet.c
+++ b/sirtet.c
@@ -95,6 +95,7 @@ void sirtet() {
clear();
printrect(0, 0, H, W);
printmap(map, 1, 1, H, W);
+ printhelp(3, 2 * W + 8);
// display game stats
mvprintw(1, 2 * W + 8, "Points: %d", points);
@@ -133,15 +134,23 @@ void sirtet() {
break;
// arrow keys: move piece on map
case KEY_LEFT:
+ case 'a':
+ case 'h':
if (col > 0) col--;
break;
case KEY_RIGHT:
+ case 'd':
+ case 'l':
if (col + pc->w < W) col++;
break;
case KEY_UP:
+ case 'w':
+ case 'k':
if (row > 0) row--;
break;
case KEY_DOWN:
+ case 's':
+ case 'j':
if (row + pc->h < H) row++;
break;
// [ and ]: switch pieces
@@ -165,6 +174,11 @@ void sirtet() {
}
}
break;
+ // q: quit
+ case 'q':
+ confirmed = true;
+ over = true;
+ break;
}
}
@@ -203,8 +217,8 @@ void sirtet() {
}
if (!has_placeable) {
// game over
- mvprintw(3, 2 * W + 8, "Game over");
- mvprintw(4, 2 * W + 8, "Press any key to exit");
+ mvprintw(7, 2 * W + 8, "Game over");
+ mvprintw(8, 2 * W + 8, "Press any key to exit");
refresh();
while (getch() == 0);
over = true;
diff --git a/ui.c b/ui.c
index 1b1cb74..1c1eea3 100644
--- a/ui.c
+++ b/ui.c
@@ -67,3 +67,9 @@ void printpieces(struct piece** hand, int y, int x, int nhand, int highlight) {
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");
+ mvprintw(y + 2, x, "Press q to quit");
+}
+
diff --git a/ui.h b/ui.h
index 09bed98..8d25ab0 100644
--- a/ui.h
+++ b/ui.h
@@ -4,5 +4,6 @@ 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 printhelp(int y, int x);
#endif