diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2022-12-01 23:33:09 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2022-12-01 23:33:09 -0800 |
| commit | b0928a2d8072f30849aac3a9e684410b434b4b3f (patch) | |
| tree | 4e6e3f12a84bbcee0a20807689ab583f1fecc397 | |
| parent | 7e63656b6159cd991e287c925b6a4ba6b055eaa0 (diff) | |
warning system
| -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; } |
