}
}
+int endofgame (board_t *board)
+{
+ int i, j;
+
+ for (i = 0; i < board->width; i++) {
+ for (j = 0; j < board->height; j++) {
+ if (*getcell (board, i, j) == ' ') {
+ return 0;
+ }
+ }
+ }
+
+ return 1;
+}
+
/* vim: set ts=4 sw=4 et: */
void freeblock (block_t *block);
+int findnext (int i, int n);
+
block_t *mirrorblock (block_t *block, int dir);
block_t *rotateblock (block_t *block, int rot);
void settleblock (board_t *board, block_t *block, int x, int y, int mode);
-int findnext (int i, int n);
+int endofgame (board_t *board);
#endif /* __FUNCTION_H__ */
/* window positions (bench) */
int xbench = bench->xoffset = xboard;
- int ybench = bench->yoffset = yboard + board->ysize + 1 + yoffset;
+ int ybench = bench->yoffset = yboard + max (board->ysize, next->ysize) + 1 + yoffset;
/* window positions (help) */
int xhelp = xbench + bench->xsize + xoffset + 1;
/* event loop */
int stop = 0;
+ int mode = 0;
while (!stop) {
boardwindow (board, 0);
boardwindow (next, 1);
block_t *block = NULL;
- if (cursor >= 0) {
+ switch (mode) {
+ case 0:
block = blocks->block[cursor];
if (blocks->settle[cursor] == 0) {
boardwindow (next, 0);
}
displayblock (next, block, xoffset + (wblock - block->width) / 2, (hblock - block->height) / 2);
msgwindow ("Can you solve this puzzle?", xmsg, ymsg, lmsg);
- } else {
+ break;
+ case 1:
msgwindow ("Puzzle solved", xmsg, ymsg, lmsg);
+ break;
}
int ch = getch ();
+
+ /* record key pressed */
if (maxnbrecords) {
if (nbrecords < maxnbrecords) {
rec[nbrecords++] = ch;
}
/* test end of game */
- if (cursor < 0) {
+ if (mode == 1) {
continue;
}
blocks->settle[cursor] = 1;
blocks->x[cursor] = xcursor;
blocks->y[cursor] = ycursor;
+ mode = endofgame (board);
}
} else {
blocks->settle[cursor] = 0;