From 8897a69e3e2e5eb3cbabb9f944855e72661da3ef Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 19 Sep 2024 22:19:56 +0200 Subject: [PATCH] show/hide positions --- display.c | 2 +- reversi.c | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/display.c b/display.c index 98021de..2b9f495 100644 --- a/display.c +++ b/display.c @@ -85,7 +85,7 @@ void _put_color_block (int y, int x, char symb) mvaddcb (y, x, lighterred); break; case '4': - mvaddcb (y, x, lightergreen); + mvaddcb (y, x, yellow); break; } } diff --git a/reversi.c b/reversi.c index 67ffb36..5eb26a7 100644 --- a/reversi.c +++ b/reversi.c @@ -20,13 +20,14 @@ char *version = "0.1"; char *filename = NULL; int scale = 1; -char *boardname = "12x12"; +char *boardname = "8x8"; char *help = " Move up cursor\n" " Move left cursor\n" " Move down cursor\n" " Move right cursor\n" + " Show/Hide positions\n" " Hold/Release piece\n" " Quit\n" " Save file\n" @@ -171,17 +172,31 @@ int main (int argc, char *argv[]) /* main loop */ int stop = 0; + int showpos = 0; int id = 0; int mode = 0; while (!stop) { + /* board */ board_t *boardturn = copyboard (board); - int ret = find (boardturn, id); - boardwindow (boardturn, 0); + if (!find (boardturn, id)) { + id = id ? 0 : 1; + if (!find (boardturn, id)) { + mode = 1; + } + } + boardwindow ((showpos) ? boardturn : board, 0); freeboard (boardturn); - displaycursor (board, id, xcursor, ycursor); + /* cursor */ + if (!mode) { + displaycursor (board, id, xcursor, ycursor); + } + + /* message */ + + /* get key press */ int ch = getch (); /* general controls */ @@ -214,7 +229,7 @@ int main (int argc, char *argv[]) case KEY_DELETE: case 127: case 'u': - id = (id == 0) ? 1 : 0; + id = id ? 0 : 1; break; case KEY_UP: case 'i': @@ -240,12 +255,15 @@ int main (int argc, char *argv[]) xcursor++; } break; + case 'm': + showpos = showpos ? 0 : 1; + break; case '\n': case '\r': case ' ': case 'o': if (putdisk (board, xcursor, ycursor, id)) { - id = (id == 0) ? 1 : 0; + id = id ? 0 : 1; } break; } -- 2.30.2