"<k> Move down cursor\n"
"<l> Move right cursor\n"
"<q> Quit\n"
-// "<x> Undo last move\n"
+ "<v> validate turn\n"
+ "<x> Undo last move\n"
"<s> Save file\n"
;
int stop = 0;
int player = 0;
while (!stop) {
+ char msg[128] = {0};
char *ptr = NULL;
+ int nbmaxjumps = 0;
int jump = 0;
boardwindow (board);
if (1) { /* not end of game */
- char msg[128] = {0};
- jump = cursorwindow (board, xcursor, ycursor, mode);
- int nb = globalmaxjumps (board, player);
- sprintf (msg, "Player %s (%d)", (player == 0) ? "One": "Two", nb);
+ sprintf (msg, "Player %s: ", (player == 0) ? "One": "Two");
+ switch (mode) {
+ case 0:
+ jump = cursorwindow (board, xcursor, ycursor, 0);
+ nbmaxjumps = globalmaxjumps (board, player);
+ sprintf (msg + strlen (msg), "Begin turn (%d)", nbmaxjumps);
+ break;
+ case 1:
+ case 2:
+ jump = cursorwindow (board, xcursor, ycursor, 1);
+ sprintf (msg + strlen (msg), "Choose next (%d)", nbmaxjumps);
+ break;
+ case 3:
+ sprintf (msg + strlen (msg), "Validate turn");
+ break;
+ }
msgwindow (msg, xmsg, ymsg, lmsg);
} else {
msgwindow ("End of game", xmsg, ymsg, lmsg);
int ch = getch ();
switch (ch) {
case ' ':
- case '\n':
- case '\r':
case 'c':
- if (mode == 1) {
+ switch (mode) {
+ case 0:
+ if (getvalue (board, xcursor, ycursor) == ((player == 0) ? '0' : '1')) {
+ mode = 1;
+ }
+ break;
+ case 1:
mode = 0;
- } else if ((getvalue (board, xcursor, ycursor) != ' ') && ((getvalue (board, xcursor, ycursor) - '0') % 2 == player)) {
- mode = 1;
+ break;
}
break;
case KEY_UP:
case 'i':
- if (mode == 0) {
+ switch (mode) {
+ case 0:
domove (board, &xcursor, &ycursor, 0);
- } else if ((jump) && (testjump (board, xcursor, ycursor, 0))) {
- dopetjump (board, &xcursor, &ycursor, 0);
- if (!testalljumps (board, xcursor, ycursor)) {
- mode = 0;
- player ^= 1;
+ break;
+ case 1:
+ case 2:
+ if ((jump) && (testjump (board, xcursor, ycursor, 0))) {
+ dopetjump (board, &xcursor, &ycursor, 0);
+ mode = (testalljumps (board, xcursor, ycursor)) ? 2 : 3;
+ } else if ((player == 1) && (!jump) && (getvalue (board, xcursor + 1, ycursor - 1) == '.')) {
+ dopetmove (board, &xcursor, &ycursor, 0);
+ mode = 3;
}
- } else if ((player == 1) && (!jump) && (getvalue (board, xcursor + 1, ycursor - 1) == '.')) {
- dopetmove (board, &xcursor, &ycursor, 0);
- mode = 0;
- player ^= 1;
+ break;
}
break;
case KEY_LEFT:
case 'j':
- if (mode == 0) {
+ switch (mode) {
+ case 0:
domove (board, &xcursor, &ycursor, 1);
- } else if ((jump) && (testjump (board, xcursor, ycursor, 1))) {
- dopetjump (board, &xcursor, &ycursor, 1);
- if (!testalljumps (board, xcursor, ycursor)) {
- mode = 0;
- player ^= 1;
+ break;
+ case 1:
+ case 2:
+ if ((jump) && (testjump (board, xcursor, ycursor, 1))) {
+ dopetjump (board, &xcursor, &ycursor, 1);
+ mode = (testalljumps (board, xcursor, ycursor)) ? 2 : 3;
+ } else if ((player == 1) && (!jump) && (getvalue (board, xcursor - 1, ycursor - 1) == '.')) {
+ dopetmove (board, &xcursor, &ycursor, 1);
+ mode = 3;
}
- } else if ((player == 1) && (!jump) && (getvalue (board, xcursor - 1, ycursor - 1) == '.')) {
- dopetmove (board, &xcursor, &ycursor, 1);
- mode = 0;
- player ^= 1;
+ break;
}
break;
case KEY_DOWN:
case 'k':
- if (mode == 0) {
+ switch (mode) {
+ case 0:
domove (board, &xcursor, &ycursor, 2);
- } else if ((jump) && (testjump (board, xcursor, ycursor, 2))) {
- dopetjump (board, &xcursor, &ycursor, 2);
- if (!testalljumps (board, xcursor, ycursor)) {
- mode = 0;
- player ^= 1;
+ break;
+ case 1:
+ case 2:
+ if ((jump) && (testjump (board, xcursor, ycursor, 2))) {
+ dopetjump (board, &xcursor, &ycursor, 2);
+ mode = (testalljumps (board, xcursor, ycursor)) ? 2 : 3;
+ } else if ((player == 0) && (!jump) && (getvalue (board, xcursor - 1, ycursor + 1) == '.')) {
+ dopetmove (board, &xcursor, &ycursor, 2);
+ mode = 3;
}
- } else if ((player == 0) && (!jump) && (getvalue (board, xcursor - 1, ycursor + 1) == '.')) {
- dopetmove (board, &xcursor, &ycursor, 2);
- mode = 0;
- player ^= 1;
+ break;
}
break;
case KEY_RIGHT:
case 'l':
- if (mode == 0) {
+ switch (mode) {
+ case 0:
domove (board, &xcursor, &ycursor, 3);
- } else if ((jump) && (testjump (board, xcursor, ycursor, 3))) {
- dopetjump (board, &xcursor, &ycursor, 3);
- if (!testalljumps (board, xcursor, ycursor)) {
- mode = 0;
- player ^= 1;
+ break;
+ case 1:
+ case 2:
+ if ((jump) && (testjump (board, xcursor, ycursor, 3))) {
+ dopetjump (board, &xcursor, &ycursor, 3);
+ mode = (testalljumps (board, xcursor, ycursor)) ? 2 : 3;
+ } else if ((player == 0) && (!jump) && (getvalue (board, xcursor + 1, ycursor + 1) == '.')) {
+ dopetmove (board, &xcursor, &ycursor, 3);
+ mode = 3;
}
- } else if ((player == 0) && (!jump) && (getvalue (board, xcursor + 1, ycursor + 1) == '.')) {
- dopetmove (board, &xcursor, &ycursor, 3);
- mode = 0;
- player ^= 1;
+ break;
}
break;
case KEY_ESC:
free (savename);
}
break;
+ case KEY_ENTER:
+ case '\n':
+ case '\r':
+ case 'v':
+ if (mode == 3) {
+ player = (player == 0) ? 1 : 0;
+ mode = 0;
+ }
+ break;
case KEY_BACKSPACE:
case KEY_DELETE:
case 127: