int main() {
int row = 0, col = 0;
- int key_pressed = 0;
+ unsigned int round = 0;
+ unsigned int player = player_one; /* first player is black */
bool exit_condition = false;
+ unsigned int nb_white = 0, nb_black = 0;
+
+ char* player_msg;
+
+ unsigned int pawns[board_size][board_size] = {{}};
+ pawns[board_size][board_size] = init_pawns(pawns);
initscr();
if (has_colors() == false) {
}
start_color();
getmaxyx(stdscr, row, col);
- noecho();
+ //noecho();
+ echo();
curs_set(0);
- /* center the board */
- int center_board_y = row/2 - 23/2;
- int center_board_x = col/2 - 41/2;
+ /* center */
+ int center_y = row/2;
+ int center_x = col/2;
+ /* base coordinates to center the board */
+ int board_center_y = center_y - 26/2;
+ int board_center_x = center_x - 42/2;
do {
- print_board(center_board_y, center_board_x);
+ print_board(board_center_y, board_center_x);
+ print_pawns(board_center_y, board_center_x, pawns);
+
+ char* title_msg = "Jeu othello";
+ mvprintw(center_y - 26/2 - 4, (center_x - strlen(title_msg)/2), title_msg);
- key_pressed = getch();
- if (key_pressed == 'q') {
- exit_condition = true;
+ nb_white = count_pawn_type(pawns, white);
+ nb_black = count_pawn_type(pawns, black);
+
+ char* score_white_msg = "Pions blancs: %d";
+ mvprintw(center_y, center_x - 42/2 - strlen(score_white_msg) - 2, score_white_msg, nb_white);
+ char* score_black_msg = "Pions noirs: %d";
+ mvprintw(center_y, center_x + 42/2 + 2, score_black_msg, nb_black);
+
+ player = current_player(round);
+
+ if (player == player_one) {
+ player_msg = "Joueur un (noir) joue !";
+ } else {
+ player_msg = "Joueur deux (blanc) joue !";
}
- } while (!exit_condition);
+ mvprintw(center_y - 26/2 - 2, (center_x - strlen(player_msg)/2), player_msg);
+ int y;
+ char x;
+ bool input_ok = false;
+ do {
+ y = 0;
+ x = "";
+ char* prompt_msg = "Prochain pion ? - ligne colonne (chiffre lettre):";
+ prompt_values(stdscr, center_y + 26/2 + 1, center_x - strlen(prompt_msg)/2, prompt_msg, &y, &x);
+ /* FIXME: separate the tests to permit to print explicit error messages */
+ if (((y > 0 && y < board_size + 1) || \
+ (map_col_letter_to_int(x) > 0 && map_col_letter_to_int(x) < board_size + 1)) \
+ && is_box_type(y, x, pawns, empty)) {
+ input_ok = true;
+ }
+ } while (!input_ok);
+ pawns[board_size][board_size] = set_pawn(y, map_col_letter_to_int(x), player, pawns);
+
+ round++; /* increment the round count */
+
+ refresh();
+
+ } while (!exit_condition);
+
endwin();
exit(EXIT_SUCCESS);