X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fmain.c;h=99ed64ea5837c849efdd82c0dc6bbed8e5e21c28;hb=d7813f1e27e72b358e7e616e132b63f35ae7ef29;hp=b0bf5b91dcfbd259bcd87554a78b9b5bf3ec5e36;hpb=7aab9e03ce0779a461044f56bc3f478e1c8d2460;p=Project_algorithmic_C.git diff --git a/src/main.c b/src/main.c index b0bf5b9..99ed64e 100644 --- a/src/main.c +++ b/src/main.c @@ -15,14 +15,14 @@ int main() { bool exit_condition = false; unsigned int nb_white = 0, nb_black = 0; - char* title_msg = "Jeu Othello"; - char* score_msg = "Pions %s: %d"; - char* invalid_move_msg = "Coup invalide"; - char* player_msg = "Joueur %d (%s) joue !"; - char* winner_msg = "Joueur %d (%s) gagne !"; - char* draw_msg = "Egalite !"; - char* exit_msg = "Pressez une touche pour sortir ou \'r\' pour rejouer"; - + const char* title_msg = "Jeu Othello"; + const char* score_msg = "Pions %s: %d"; + const char* invalid_move_msg = "Coup invalide"; + const char* player_msg = "Joueur %d (%s) joue !"; + const char* winner_msg = "Joueur %d (%s) gagne !"; + const char* draw_msg = "Egalite !"; + const char* exit_msg = "Pressez une touche pour sortir ou \'r\' pour rejouer"; + /* linked list of playable shots */ struct shots_list_s playable_shots; INIT_LIST_HEAD(&playable_shots.list); @@ -73,24 +73,29 @@ int main() { nb_white = count_pawns_type(pawns, white); nb_black = count_pawns_type(pawns, black); - + mvprintw(center_y, center_x - 42/2 - snprintf(NULL, 0, score_msg, "noirs", nb_black) - 2, score_msg, "noirs", nb_black); mvprintw(center_y, center_x + 42/2 + 2, score_msg, "blancs", nb_white); - - //display_array(1, 1, pawns); + + build_playable_shots_list(player, &playable_shots, pawns); + print_shots_list(board_center_y, board_center_x, &playable_shots); + + display_array(1, 1, pawns); int y; char x_char; bool input_ok = false; + bool first_run = true; unsigned int nb_pawns_reversed = 0; do { y = 0; - x_char = ""; - char* prompt_msg = "Prochain pion ? (ligne colonne - chiffre lettre):"; + x_char = (char)""; + const char* prompt_msg = "Prochain pion ? (ligne colonne - chiffre lettre):"; int prmt_rt = prompt_values(stdscr, center_y + 26/2 + 1, (center_x - strlen(prompt_msg)/2), prompt_msg, &y, &x_char); int x = map_col_letter_to_index(x_char); - nb_pawns_reversed = valid_shot(y, x, player, pawns); - if (nb_pawns_reversed > 0 && prmt_rt == 1) { + /* TODO: a comparaison to the linked list of playable shots is better */ + if (is_legal_shot(y, x, player, pawns) && prmt_rt == 1) { + nb_pawns_reversed = valid_shot(y, x, player, pawns); input_ok = true; clear(); } else { @@ -98,12 +103,14 @@ int main() { } } while (!input_ok); + free_shots_list(&playable_shots); + round++; /* increment the round count */ /* here are all the end of the game conditions */ if (is_board_full(pawns)) { print_board(board_center_y, board_center_x); - /* print the updated pawns before exiting */ + /* print the updated pawns array before exiting */ print_pawns(board_center_y, board_center_x, pawns); unsigned int winner = eval_winner(nb_white, nb_black); if (winner != 0) { @@ -129,11 +136,11 @@ int main() { clear(); } } - + refresh(); } while (!exit_condition); - + endwin(); exit(EXIT_SUCCESS);