diff options
Diffstat (limited to 'chess.c')
| -rw-r--r-- | chess.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -164,6 +164,14 @@ char* get_readable_coords(vector_t position) { void clear_screen() { system("@cls||clear"); } +void warn_user(char* message) { + clear_screen(); + printf("\n"); + printf(message); + printf("\nPress any key to continue...\n"); + while(getchar() != '\n'); + getchar(); +} int main() { int board[8][8] = { { rook + 6, pawn + 6, 0, 0, 0, 0, pawn, rook }, @@ -175,13 +183,16 @@ int main() { { knight + 6, pawn + 6, 0, 0, 0, 0, pawn, knight }, { rook + 6, pawn + 6, 0, 0, 0, 0, pawn, rook } }; + int turn = 0; while(1) { clear_screen(board); draw_board(board); + printf(turn == 0 ? "\nWhite's turn\n" : "\nBlack's turn\n"); printf("Enter the coordinates of the piece you want to move\n"); vector_t selection = user_input_pos(); int selectedPiece = board[selection.mx][selection.my]; if(selectedPiece == 0) { + warn_user("Invalid selection!"); continue; } printf("Selected piece: "); @@ -189,6 +200,7 @@ int main() { printf("\n"); vectorp_t moves = get_moves(board, selection, selectedPiece); if(moves.length == 0) { + warn_user("That piece has no valid moves!"); continue; } printf("Valid moves: "); @@ -207,6 +219,7 @@ int main() { board[selection.mx][selection.my] = 0; board[target.mx][target.my] = selectedPiece; printf("\n"); + turn = !turn; } return 0; } |
