From 2824d08a2ad63c572b7b993ceed8843378d4bf20 Mon Sep 17 00:00:00 2001 From: "Mr. Sam" Date: Mon, 20 Jul 2026 22:58:53 +0100 Subject: change colors, show hand, add some logic to piece movement. --- input.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 20 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index d7c8ffb..37523d8 100644 --- a/input.c +++ b/input.c @@ -2,11 +2,57 @@ #include #include "input.h" #include "board.h" + +#define POSITION board[cursorPosX][cursorPosY] char hand = ' '; int turnPart = 1; int turns = 0; -int InputBoard(char board[8][8], int keypress) { +enum piece { + WHITE, + BLACK, + BOARD, +}; + +enum piece CheckPiece(int hand) { + if (hand >= 'A' && hand <= 'Z' ) { + return WHITE; + } + else if (hand >= 'a' && hand <= 'z' ) { + return BLACK; + } + else { + return BOARD; + } +} + +void HandleInput(char board[8][8]) { + if ( hand == ' ' && POSITION != ' '){ + hand = POSITION; + POSITION = ' '; + turnPart++; + } + + /* Simply doing nothing with these felonius inputs */ + else if ( CheckPiece(hand) == CheckPiece(POSITION) ) {} + else if ( hand == ' ' && POSITION == ' ' ) {} + + + else if ( hand != POSITION) { + board[cursorPosX][cursorPosY] = hand; + hand = ' '; + turnPart++; + } + else if ( hand != ' ' && POSITION == ' ') { + board[cursorPosX][cursorPosY] = hand; + hand = ' '; + turnPart++; + } + if (turnPart > 1 && turnPart & 1) turns++; +} + + +int InputBoard(char board[8][8], int keypress) { /* Handle key input */ switch (keypress) { @@ -14,6 +60,12 @@ int InputBoard(char board[8][8], int keypress) { endwin(); exit(0); break; + case 'h': + hand = CheckPiece(hand); + break; + case 'p': + POSITION = CheckPiece(POSITION); + break; case KEY_UP: if (cursorPosX > 0) cursorPosX--; break; @@ -27,25 +79,7 @@ int InputBoard(char board[8][8], int keypress) { 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++; - - + HandleInput(board); break; } -- cgit v1.2.3