diff options
| author | sumuel <samuel@yakubos.org> | 2026-07-15 06:46:24 +0100 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-07-15 06:46:24 +0100 |
| commit | f29f867a18ee82d6c79900420b6a6d5f66a75f18 (patch) | |
| tree | 900a0cf9f59f2485e1eb0c190f7c16ef5082babb /input.c | |
init
Diffstat (limited to 'input.c')
| -rw-r--r-- | input.c | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -0,0 +1,54 @@ +#include <ncurses.h> +#include <stdlib.h> +#include "input.h" +#include "board.h" +char hand = ' '; +int turnPart = 1; +int turns = 0; + +int InputBoard(char board[8][8], int keypress) { + + /* Handle key input */ + switch (keypress) { + case 'q': + endwin(); + exit(0); + break; + case KEY_UP: + if (cursorPosX > 0) cursorPosX--; + break; + case KEY_DOWN: + if (cursorPosX < 7) cursorPosX++; + break; + case KEY_LEFT: + if (cursorPosY > 0 ) cursorPosY--; + break; + case KEY_RIGHT: + if (cursorPosY < 7) cursorPosY++; + break; + case '\n': /* This is the ENTER key. KEY_ENTER does not work */ + if ( hand == ' ' && board[cursorPosX][cursorPosY] != ' '){ + hand = board[cursorPosX][cursorPosY]; + board[cursorPosX][cursorPosY] = ' '; + turnPart++; + } + + else if ( hand != ' ' && board[cursorPosX][cursorPosY] != ' ') { + board[cursorPosX][cursorPosY] = hand; + hand = ' '; + turnPart++; + } + else if ( hand != ' ' && board[cursorPosX][cursorPosY] == ' ') { + board[cursorPosX][cursorPosY] = hand; + hand = ' '; + turnPart++; + } + if (turnPart & 1) turns++; + + + break; + } + + + return 0; +} |