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. --- board.c | 4 ++-- input.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++------------------ main.c | 2 +- 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/board.c b/board.c index a4faad3..b14f225 100644 --- a/board.c +++ b/board.c @@ -41,8 +41,8 @@ void PrintBoard(char board[8][8]){ } attron(A_BOLD | COLOR_PAIR(4)); - if ( i == 1) printw(" BLACK "); - if ( i == 6) printw(" WHITE "); + if ( i == 1) printw(" HAND: %d ", hand); + if ( i == 6) printw(" POSITION: %d ", board[cursorPosX][cursorPosY]); attroff(A_BOLD | COLOR_PAIR(4)); printw("\n"); } 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; } diff --git a/main.c b/main.c index 78ff95d..c7c05ed 100644 --- a/main.c +++ b/main.c @@ -23,7 +23,7 @@ int main(void) { init_color(COLOR_WHITE, 820, 840, 880); init_pair(1, COLOR_RED, COLOR_WHITE); init_pair(2, COLOR_WHITE, COLOR_RED); - init_pair(3, COLOR_YELLOW, COLOR_MAGENTA); + init_pair(3, COLOR_YELLOW, COLOR_BLUE); init_pair(4, COLOR_CYAN, COLOR_BLACK); while (turns < 1000){ -- cgit v1.2.3