X-Git-Url: https://git.piment-noir.org/?p=Project_algorithmic_C.git;a=blobdiff_plain;f=src%2Fmain.c;h=08c621621dcd56cc33380adfde270055f0993af4;hp=6a56eed094f9393d6c8a598af3873e370a6b7f52;hb=a80646b74eca11c71696dedeb674870437c5bb6f;hpb=45ce2fe369cead248855111baa5fe0c0495acf69 diff --git a/src/main.c b/src/main.c index 6a56eed..08c6216 100644 --- a/src/main.c +++ b/src/main.c @@ -20,9 +20,22 @@ int main() { char* player_msg = "Joueur %d (%s) joue !"; char* winner_msg = "Joueur %d (%s) gagne !"; char* draw_msg = "Egalite !"; - - unsigned int pawns[board_size][board_size] = {{}}; - pawns[board_size][board_size] = init_pawns(pawns); + + /* linked list of the history shots */ + //struct shots_history_list_s shots_history; + //INIT_LIST_HEAD(&shots_history.list); + /* linked list of black playable shots */ + struct shots_list_s black_playable_shots; + INIT_LIST_HEAD(&black_playable_shots.list); + /* linked list of white playable shots */ + struct shots_list_s white_playable_shots; + INIT_LIST_HEAD(&white_playable_shots.list); + + unsigned int pawns[board_size][board_size] = { + {0, 0}, + {0, 0} + }; + init_pawns(pawns); initscr(); if (has_colors() == false) { @@ -34,11 +47,10 @@ int main() { getmaxyx(stdscr, row, col); if (row < min_y || col < min_x) { endwin(); - printf("Votre terminal est trop petit pour afficher le jeu.\n"); + printf("Votre terminal est trop petit pour afficher ce jeu.\n"); printf("Merci d'agrandir la fenetre de votre terminal.\n"); exit(EXIT_FAILURE); } - /* FIXME: fail if the screen size is too small */ echo(); curs_set(0); @@ -63,39 +75,33 @@ int main() { mvprintw(center_y - 26/2 - 2, center_x - snprintf(NULL, 0, player_msg, player, "blanc")/2, player_msg, player, "blanc"); } - nb_white = count_pawn_type(pawns, white); - nb_black = count_pawn_type(pawns, black); + 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); int y; - char x; + char x_char; bool input_ok = false; do { y = 0; - x = (char)""; + x_char = ""; 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); - if (is_valid_input(y, map_col_letter_to_index(x), pawns) && prmt_rt == 1) { + 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); + if (valid_shot(y, x, player, pawns) > 0 && prmt_rt == 1) { input_ok = true; } } while (!input_ok); - pawns[board_size][board_size] = set_pawn(y, map_col_letter_to_index(x), player, pawns); - struct shots_history_list_s shots_history; - INIT_LIST_HEAD(&shots_history.list); - struct shots_history_list_s shots_elmt; - shots_elmt.pawn_array_member = &pawns[y-1][x-1]; - list_add(&shots_elmt.list, &shots_history.list); round++; /* increment the round count */ - refresh(); - /* here are all the end of the game conditions */ - //if (is_board_full(pawns) || (round == 60)) { if (is_board_full(pawns)) { - int winner = eval_winner(nb_white, nb_black); + unsigned int winner = eval_winner(nb_white, nb_black); if (winner != 0) { if (winner == player_one) { mvprintw(center_y - 26/2 - 2, center_x - snprintf(NULL, 0, winner_msg, winner, "noir"), winner_msg, winner, "noir"); @@ -108,6 +114,8 @@ int main() { /* print and implement restart possibility */ exit_condition = true; } + + refresh(); } while (!exit_condition);