#include "coordinates.h"
int main() {
- int row, col;
+ int row, col, errno = 0, round = 0, player = 0, key_pressed;
char* top_msg = "";
char* back_msg = "";
/* array of the active coordinates in the entered order */
coordinates_t coordinates_array[MAX_COORDINATES];
init_coordinates(coordinates_array);
+ coordinates_t new_coordinates = {0, 0, 0};
/* center base coordinates for the board */
int base_y = row/2 - 4;
int base_x = col/2 - 7;
- if (!top_msg) mvprintw(base_y - 2, (base_x + 7 - strlen(top_msg)/2), top_msg);
print_board(base_y, base_x);
- if (!back_msg) mvprintw(base_y + 10, (base_x + 7 - strlen(back_msg)/2), back_msg);
- int errno = add_coordinates(set_coordinates(1, 3, 0), coordinates_array);
- errno = add_coordinates(set_coordinates(1, 3, 0), coordinates_array);
- errno = add_coordinates(set_coordinates(2, 3, 1), coordinates_array);
- errno = add_coordinates(set_coordinates(1, 1, 0), coordinates_array);
+ do {
+ if (round % 2 == 0 || round == 0) {
+ player = 0;
+ top_msg = "Joueur 1 joue";
+ } else {
+ player = 1;
+ top_msg = "Joueur 2 joue";
+ }
- print_coordinates(coordinates_array, base_y, base_x);
-
- refresh();
+ mvprintw(base_y - 2, (base_x + 7 - strlen(top_msg)/2), top_msg);
+ mvprintw(base_y + 10, (base_x + 7 - strlen(back_msg)/2), back_msg);
- while (getch() != 'q');
+ print_coordinates(coordinates_array, base_y, base_x);
+
+ key_pressed = getch();
+ switch (key_pressed) {
+ case 'a':
+ new_coordinates = set_coordinates(1, 1, player);
+ break;
+ case 'z':
+ new_coordinates = set_coordinates(1, 2, player);
+ break;
+ case 'e':
+ new_coordinates = set_coordinates(1, 3, player);
+ break;
+ case 'q':
+ new_coordinates = set_coordinates(2, 1, player);
+ break;
+ case 's':
+ new_coordinates = set_coordinates(2, 2, player);
+ break;
+ case 'd':
+ new_coordinates = set_coordinates(2, 3, player);
+ break;
+ case 'w':
+ new_coordinates = set_coordinates(3, 1, player);
+ break;
+ case 'x':
+ new_coordinates = set_coordinates(3, 2, player);
+ break;
+ case 'c':
+ new_coordinates = set_coordinates(3, 3, player);
+ break;
+ default:
+ continue;
+ break;
+ }
+
+ errno = add_coordinates(new_coordinates, coordinates_array);
+
+ if (errno == 2) {
+ back_msg = "Choisir une case vide";
+ continue;
+ } else if (errno == 3) {
+ back_msg = "Coordonnees invalides";
+ continue;
+ } else if (errno == 0) {
+ back_msg = "";
+ }
+
+ round++;
+
+ } while (errno == 0 || errno == 2);
endwin();