From 384f833e839cf8f5e71b656cf7b390fc80d89e9d Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 1 Jun 2022 15:47:02 +0800 Subject: Help text, wasd/hjkl navigation --- sirtet.c | 18 ++++++++++++++++-- ui.c | 6 ++++++ ui.h | 1 + 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 -- cgit v1.2.3