diff --git a/client/client.c b/client/client.c index 8fe8634..068efff 100644 --- a/client/client.c +++ b/client/client.c @@ -86,6 +86,14 @@ void play_game(int sock) case MSG_SHOT: // Received shot from opponent int hit =receive_shot(msg.x, msg.y, &b_own); + + if (hit == -1) { + printf("You lost!\n"); + Message game_over_msg = {.type = MSG_GAME_OVER}; + send(sock, &game_over_msg, sizeof(Message), 0); + game_over = true; + break; + } // Send result back Message result = { @@ -103,6 +111,7 @@ void play_game(int sock) break; case MSG_GAME_OVER: + printf("You win!\n"); game_over = true; break; } diff --git a/server/server.c b/server/server.c index 4714138..d59fad9 100644 --- a/server/server.c +++ b/server/server.c @@ -160,6 +160,10 @@ void *handle_client(void *arg) Message turn_msg = {.type = MSG_YOUR_TURN}; send(client_socket, &turn_msg, sizeof(Message), 0); break; + + case MSG_GAME_OVER: + send(opponent_socket, &msg, sizeof(Message), 0); + break; } } diff --git a/source/board.c b/source/board.c index d67c3e8..50990be 100644 --- a/source/board.c +++ b/source/board.c @@ -27,7 +27,7 @@ void board_destroy(board* b) void board_display(board* b_own, board* b_enemy) { - //clear_screen(); + clear_screen(); printf(" Your board | Enemy board\n"); printf(" A B C D E F G H I J | A B C D E F G H I J\n"); for (int j = 0; j < b_own->size_; j++) @@ -166,7 +166,6 @@ void place_ships(board* b) printf("Ships cannot be adjacent to other ships\n"); printf("-------------------------------\n"); printf("Press any key to continue...\n"); - getchar(); while (getchar() != '\n'); board_display(b, b); char* position = calloc(4, sizeof(char));