#include #include #include "input.h" #include "board.h" #define POSITION board[cursorPosX][cursorPosY] char hand = ' '; int turnPart = 1; int turns = 0; 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) { case 'q': endwin(); exit(0); break; case 'h': hand = CheckPiece(hand); break; case 'p': POSITION = CheckPiece(POSITION); 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 */ HandleInput(board); break; } return 0; }