2 * 'same game' -- try to remove all the coloured squares by
3 * selecting regions of contiguous colours.
15 #define TILE_INNER (ds->tileinner)
16 #define TILE_GAP (ds->tilegap)
17 #define TILE_SIZE (TILE_INNER + TILE_GAP)
18 #define PREFERRED_TILE_SIZE 32
19 #define BORDER (TILE_SIZE / 2)
20 #define HIGHLIGHT_WIDTH 2
22 #define FLASH_FRAME 0.13F
24 #define COORD(x) ( (x) * TILE_SIZE + BORDER )
25 #define FROMCOORD(x) ( ((x) - BORDER + TILE_SIZE) / TILE_SIZE - 1 )
27 #define X(state, i) ( (i) % (state)->params.w )
28 #define Y(state, i) ( (i) / (state)->params.w )
29 #define C(state, x, y) ( (y) * (state)->w + (x) )
33 COL_1
, COL_2
, COL_3
, COL_4
, COL_5
, COL_6
, COL_7
, COL_8
, COL_9
,
34 COL_IMPOSSIBLE
, COL_SEL
, COL_HIGHLIGHT
, COL_LOWLIGHT
,
38 /* scoresub is 1 or 2 (for (n-1)^2 or (n-2)^2) */
40 int w
, h
, ncols
, scoresub
;
43 /* These flags must be unique across all uses; in the game_state,
44 * the game_ui, and the drawstate (as they all get combined in the
46 #define TILE_COLMASK 0x00ff
47 #define TILE_SELECTED 0x0100 /* used in ui and drawstate */
48 #define TILE_JOINRIGHT 0x0200 /* used in drawstate */
49 #define TILE_JOINDOWN 0x0400 /* used in drawstate */
50 #define TILE_JOINDIAG 0x0800 /* used in drawstate */
51 #define TILE_HASSEL 0x1000 /* used in drawstate */
53 #define TILE(gs,x,y) ((gs)->tiles[(gs)->params.w*(y)+(x)])
54 #define COL(gs,x,y) (TILE(gs,x,y) & TILE_COLMASK)
55 #define ISSEL(gs,x,y) (TILE(gs,x,y) & TILE_SELECTED)
57 #define SWAPTILE(gs,x1,y1,x2,y2) do { \
58 int t = TILE(gs,x1,y1); \
59 TILE(gs,x1,y1) = TILE(gs,x2,y2); \
63 static int npoints(game_params
*params
, int nsel
)
65 int sdiff
= nsel
- params
->scoresub
;
66 return (sdiff
> 0) ? sdiff
* sdiff
: 0;
70 struct game_params params
;
72 int *tiles
; /* colour only */
74 int complete
, impossible
;
77 static game_params
*default_params(void)
79 game_params
*ret
= snew(game_params
);
87 static const struct game_params samegame_presets
[] = {
95 static int game_fetch_preset(int i
, char **name
, game_params
**params
)
100 if (i
< 0 || i
>= lenof(samegame_presets
))
103 ret
= snew(game_params
);
104 *ret
= samegame_presets
[i
];
106 sprintf(str
, "%dx%d, %d colours", ret
->w
, ret
->h
, ret
->ncols
);
113 static void free_params(game_params
*params
)
118 static game_params
*dup_params(game_params
*params
)
120 game_params
*ret
= snew(game_params
);
121 *ret
= *params
; /* structure copy */
125 static void decode_params(game_params
*params
, char const *string
)
127 char const *p
= string
;
130 while (*p
&& isdigit((unsigned char)*p
)) p
++;
134 while (*p
&& isdigit((unsigned char)*p
)) p
++;
136 params
->h
= params
->w
;
139 params
->ncols
= atoi(p
);
140 while (*p
&& isdigit((unsigned char)*p
)) p
++;
145 params
->scoresub
= atoi(p
);
146 while (*p
&& isdigit((unsigned char)*p
)) p
++;
148 params
->scoresub
= 2;
152 static char *encode_params(game_params
*params
, int full
)
156 sprintf(ret
, "%dx%dc%ds%d",
157 params
->w
, params
->h
, params
->ncols
, params
->scoresub
);
161 static config_item
*game_configure(game_params
*params
)
166 ret
= snewn(5, config_item
);
168 ret
[0].name
= "Width";
169 ret
[0].type
= C_STRING
;
170 sprintf(buf
, "%d", params
->w
);
171 ret
[0].sval
= dupstr(buf
);
174 ret
[1].name
= "Height";
175 ret
[1].type
= C_STRING
;
176 sprintf(buf
, "%d", params
->h
);
177 ret
[1].sval
= dupstr(buf
);
180 ret
[2].name
= "No. of colours";
181 ret
[2].type
= C_STRING
;
182 sprintf(buf
, "%d", params
->ncols
);
183 ret
[2].sval
= dupstr(buf
);
186 ret
[3].name
= "Scoring system";
187 ret
[3].type
= C_CHOICES
;
188 ret
[3].sval
= ":(n-1)^2:(n-2)^2";
189 ret
[3].ival
= params
->scoresub
-1;
199 static game_params
*custom_params(config_item
*cfg
)
201 game_params
*ret
= snew(game_params
);
203 ret
->w
= atoi(cfg
[0].sval
);
204 ret
->h
= atoi(cfg
[1].sval
);
205 ret
->ncols
= atoi(cfg
[2].sval
);
206 ret
->scoresub
= cfg
[3].ival
+ 1;
211 static char *validate_params(game_params
*params
)
213 if (params
->w
< 1 || params
->h
< 1)
214 return "Width and height must both be positive";
215 if (params
->ncols
< 2)
216 return "It's too easy with only one colour...";
217 if (params
->ncols
> 9)
218 return "Maximum of 9 colours";
220 /* ...and we must make sure we can generate at least 2 squares
221 * of each colour so it's theoretically soluble. */
222 if ((params
->w
* params
->h
) < (params
->ncols
* 2))
223 return "Too many colours makes given grid size impossible";
225 if ((params
->scoresub
< 1) || (params
->scoresub
> 2))
226 return "Scoring system not recognised";
231 /* Currently this is a very very dumb game-generation engine; it
232 * just picks randomly from the tile space. I had a look at a few
233 * other same game implementations, and none of them attempt to do
234 * anything to try and make sure the grid started off with a nice
235 * set of large blocks.
237 * It does at least make sure that there are >= 2 of each colour
238 * present at the start.
241 static char *new_game_desc(game_params
*params
, random_state
*rs
,
242 game_aux_info
**aux
, int interactive
)
245 int n
, i
, j
, c
, retlen
, *tiles
;
247 debug(("new_game_desc: %dx%d, %d colours",
248 params
->w
, params
->h
, params
->ncols
));
249 n
= params
->w
* params
->h
;
250 tiles
= snewn(n
, int);
251 memset(tiles
, 0, n
*sizeof(int));
253 /* randomly place two of each colour */
254 for (c
= 0; c
< params
->ncols
; c
++) {
255 for (j
= 0; j
< 2; j
++) {
257 i
= (int)random_upto(rs
, n
);
258 } while (tiles
[i
] != 0);
263 /* fill in the rest randomly */
264 for (i
= 0; i
< n
; i
++) {
266 tiles
[i
] = (int)random_upto(rs
, params
->ncols
)+1;
271 for (i
= 0; i
< n
; i
++) {
275 k
= sprintf(buf
, "%d,", tiles
[i
]);
276 ret
= sresize(ret
, retlen
+ k
+ 1, char);
277 strcpy(ret
+ retlen
, buf
);
280 ret
[retlen
-1] = '\0'; /* delete last comma */
286 static void game_free_aux_info(game_aux_info
*aux
)
288 assert(!"Shouldn't happen");
291 static char *validate_desc(game_params
*params
, char *desc
)
293 int area
= params
->w
* params
->h
, i
;
296 for (i
= 0; i
< area
; i
++) {
301 return "Not enough numbers in string";
302 while (isdigit(*p
)) p
++;
304 if (i
< area
-1 && *p
!= ',')
305 return "Expected comma after number";
306 else if (i
== area
-1 && *p
)
307 return "Excess junk at end of string";
310 if (n
< 0 || n
> params
->ncols
)
311 return "Colour out of range";
313 if (*p
) p
++; /* eat comma */
318 static game_state
*new_game(midend_data
*me
, game_params
*params
, char *desc
)
320 game_state
*state
= snew(game_state
);
324 state
->params
= *params
; /* struct copy */
325 state
->n
= state
->params
.w
* state
->params
.h
;
326 state
->tiles
= snewn(state
->n
, int);
328 for (i
= 0; i
< state
->n
; i
++) {
330 state
->tiles
[i
] = atoi(p
);
331 while (*p
&& *p
!= ',')
333 if (*p
) p
++; /* eat comma */
335 state
->complete
= state
->impossible
= 0;
341 static game_state
*dup_game(game_state
*state
)
343 game_state
*ret
= snew(game_state
);
345 *ret
= *state
; /* structure copy, except... */
347 ret
->tiles
= snewn(state
->n
, int);
348 memcpy(ret
->tiles
, state
->tiles
, state
->n
* sizeof(int));
353 static void free_game(game_state
*state
)
359 static game_state
*solve_game(game_state
*state
, game_aux_info
*aux
,
365 static char *game_text_format(game_state
*state
)
370 maxlen
= state
->params
.h
* (state
->params
.w
+ 1);
371 ret
= snewn(maxlen
+1, char);
374 for (y
= 0; y
< state
->params
.h
; y
++) {
375 for (x
= 0; x
< state
->params
.w
; x
++) {
376 int t
= TILE(state
,x
,y
);
377 if (t
<= 0) *p
++ = ' ';
378 else if (t
< 10) *p
++ = '0'+t
;
379 else *p
++ = 'a'+(t
-10);
383 assert(p
- ret
== maxlen
);
389 struct game_params params
;
390 int *tiles
; /* selected-ness only */
392 int xsel
, ysel
, displaysel
;
395 static game_ui
*new_ui(game_state
*state
)
397 game_ui
*ui
= snew(game_ui
);
399 ui
->params
= state
->params
; /* structure copy */
400 ui
->tiles
= snewn(state
->n
, int);
401 memset(ui
->tiles
, 0, state
->n
*sizeof(int));
404 ui
->xsel
= ui
->ysel
= ui
->displaysel
= 0;
409 static void free_ui(game_ui
*ui
)
415 static void sel_clear(game_ui
*ui
, game_state
*state
)
419 for (i
= 0; i
< state
->n
; i
++)
420 ui
->tiles
[i
] &= ~TILE_SELECTED
;
422 debug(("sel_clear"));
426 static void game_changed_state(game_ui
*ui
, game_state
*oldstate
,
427 game_state
*newstate
)
429 sel_clear(ui
, newstate
);
432 static void sel_remove(game_ui
*ui
, game_state
*state
)
436 state
->score
+= npoints(&state
->params
, ui
->nselected
);
438 for (i
= 0; i
< state
->n
; i
++) {
439 if (ui
->tiles
[i
] & TILE_SELECTED
) {
442 ui
->tiles
[i
] &= ~TILE_SELECTED
;
446 debug(("sel_remove: removed %d selected tiles", nremoved
));
449 static void sel_expand(game_ui
*ui
, game_state
*state
, int tx
, int ty
)
451 int ns
= 1, nadded
, x
, y
, c
;
453 TILE(ui
,tx
,ty
) |= TILE_SELECTED
;
454 debug(("sel_expand, selected initial tile"));
458 for (x
= 0; x
< state
->params
.w
; x
++) {
459 for (y
= 0; y
< state
->params
.h
; y
++) {
460 if (x
== tx
&& y
== ty
) continue;
461 if (ISSEL(ui
,x
,y
)) continue;
465 ISSEL(ui
,x
-1,y
) && COL(state
,x
-1,y
) == c
) {
466 TILE(ui
,x
,y
) |= TILE_SELECTED
;
471 if ((x
+1 < state
->params
.w
) &&
472 ISSEL(ui
,x
+1,y
) && COL(state
,x
+1,y
) == c
) {
473 TILE(ui
,x
,y
) |= TILE_SELECTED
;
479 ISSEL(ui
,x
,y
-1) && COL(state
,x
,y
-1) == c
) {
480 TILE(ui
,x
,y
) |= TILE_SELECTED
;
485 if ((y
+1 < state
->params
.h
) &&
486 ISSEL(ui
,x
,y
+1) && COL(state
,x
,y
+1) == c
) {
487 TILE(ui
,x
,y
) |= TILE_SELECTED
;
494 debug(("sel_expand, new pass, selected %d more tiles", nadded
));
495 } while (nadded
> 0);
500 sel_clear(ui
, state
);
504 static int sg_emptycol(game_state
*ret
, int x
)
507 for (y
= 0; y
< ret
->params
.h
; y
++) {
508 if (COL(ret
,x
,y
)) return 0;
514 static void sg_snuggle(game_state
*ret
)
518 /* make all unsupported tiles fall down. */
521 for (x
= 0; x
< ret
->params
.w
; x
++) {
522 for (y
= ret
->params
.h
-1; y
> 0; y
--) {
523 if (COL(ret
,x
,y
) != 0) continue;
524 if (COL(ret
,x
,y
-1) != 0) {
525 SWAPTILE(ret
,x
,y
,x
,y
-1);
532 /* shuffle all columns as far left as they can go. */
535 for (x
= 0; x
< ret
->params
.w
-1; x
++) {
536 if (sg_emptycol(ret
,x
) && !sg_emptycol(ret
,x
+1)) {
537 debug(("column %d is empty, shuffling from %d", x
, x
+1));
539 for (y
= 0; y
< ret
->params
.h
; y
++) {
540 SWAPTILE(ret
,x
,y
,x
+1,y
);
547 static void sg_check(game_state
*ret
)
549 int x
,y
, complete
= 1, impossible
= 1;
551 for (x
= 0; x
< ret
->params
.w
; x
++) {
552 for (y
= 0; y
< ret
->params
.h
; y
++) {
553 if (COL(ret
,x
,y
) == 0)
556 if (x
+1 < ret
->params
.w
) {
557 if (COL(ret
,x
,y
) == COL(ret
,x
+1,y
))
560 if (y
+1 < ret
->params
.h
) {
561 if (COL(ret
,x
,y
) == COL(ret
,x
,y
+1))
566 ret
->complete
= complete
;
567 ret
->impossible
= impossible
;
570 struct game_drawstate
{
571 int started
, bgcolour
;
572 int tileinner
, tilegap
;
573 int *tiles
; /* contains colour and SELECTED. */
576 static game_state
*make_move(game_state
*from
, game_ui
*ui
, game_drawstate
*ds
,
577 int x
, int y
, int button
)
580 game_state
*ret
= from
;
584 if (button
== RIGHT_BUTTON
|| button
== LEFT_BUTTON
) {
585 tx
= FROMCOORD(x
); ty
= FROMCOORD(y
);
586 } else if (button
== CURSOR_UP
|| button
== CURSOR_DOWN
||
587 button
== CURSOR_LEFT
|| button
== CURSOR_RIGHT
) {
590 dx
= (button
== CURSOR_LEFT
) ?
-1 : ((button
== CURSOR_RIGHT
) ?
+1 : 0);
591 dy
= (button
== CURSOR_DOWN
) ?
+1 : ((button
== CURSOR_UP
) ?
-1 : 0);
592 ui
->xsel
= (ui
->xsel
+ from
->params
.w
+ dx
) % from
->params
.w
;
593 ui
->ysel
= (ui
->ysel
+ from
->params
.h
+ dy
) % from
->params
.h
;
594 debug(("cursor pressed, d=(%d,%d), sel=(%d,%d)",dx
,dy
,ui
->xsel
,ui
->ysel
));
596 } else if (button
== CURSOR_SELECT
|| button
== ' ' || button
== '\r' ||
601 debug(("cursor select, t=(%d,%d)", tx
, ty
));
605 if (tx
< 0 || tx
>= from
->params
.w
|| ty
< 0 || ty
>= from
->params
.h
)
607 if (COL(from
, tx
, ty
) == 0) return NULL
;
609 if (ISSEL(ui
,tx
,ty
)) {
610 if (button
== RIGHT_BUTTON
)
613 /* this is the actual move. */
614 ret
= dup_game(from
);
616 sg_snuggle(ret
); /* shifts blanks down and to the left */
617 sg_check(ret
); /* checks for completeness or impossibility */
620 sel_clear(ui
, from
); /* might be no-op */
621 sel_expand(ui
, from
, tx
, ty
);
623 if (ret
->complete
|| ret
->impossible
)
629 /* ----------------------------------------------------------------------
633 static void game_size(game_params
*params
, game_drawstate
*ds
, int *x
, int *y
,
639 * We could choose the tile gap dynamically as well if we
640 * wanted to; for example, at low tile sizes it might be
641 * sensible to leave it out completely. However, for the moment
642 * and for the sake of simplicity I'm just going to fix it at
648 * Each window dimension equals the tile size (inner plus gap)
649 * times the grid dimension, plus another tile size (border is
650 * half the width of a tile), minus one tile gap.
652 * We must cast to unsigned before adding to *x and *y, since
653 * they might be INT_MAX!
655 tsx
= (unsigned)(*x
+ ds
->tilegap
) / (params
->w
+ 1);
656 tsy
= (unsigned)(*y
+ ds
->tilegap
) / (params
->h
+ 1);
660 ds
->tileinner
= ts
- ds
->tilegap
;
662 ds
->tileinner
= min(ts
, PREFERRED_TILE_SIZE
) - ds
->tilegap
;
664 *x
= TILE_SIZE
* params
->w
+ 2 * BORDER
- TILE_GAP
;
665 *y
= TILE_SIZE
* params
->h
+ 2 * BORDER
- TILE_GAP
;
668 static float *game_colours(frontend
*fe
, game_state
*state
, int *ncolours
)
670 float *ret
= snewn(3 * NCOLOURS
, float);
672 frontend_default_colour(fe
, &ret
[COL_BACKGROUND
* 3]);
674 ret
[COL_1
* 3 + 0] = 0.0F
;
675 ret
[COL_1
* 3 + 1] = 0.0F
;
676 ret
[COL_1
* 3 + 2] = 1.0F
;
678 ret
[COL_2
* 3 + 0] = 0.0F
;
679 ret
[COL_2
* 3 + 1] = 0.5F
;
680 ret
[COL_2
* 3 + 2] = 0.0F
;
682 ret
[COL_3
* 3 + 0] = 1.0F
;
683 ret
[COL_3
* 3 + 1] = 0.0F
;
684 ret
[COL_3
* 3 + 2] = 0.0F
;
686 ret
[COL_4
* 3 + 0] = 0.5F
;
687 ret
[COL_4
* 3 + 1] = 0.5F
;
688 ret
[COL_4
* 3 + 2] = 1.0F
;
690 ret
[COL_5
* 3 + 0] = 0.5F
;
691 ret
[COL_5
* 3 + 1] = 1.0F
;
692 ret
[COL_5
* 3 + 2] = 0.5F
;
694 ret
[COL_6
* 3 + 0] = 1.0F
;
695 ret
[COL_6
* 3 + 1] = 0.5F
;
696 ret
[COL_6
* 3 + 2] = 0.5F
;
698 ret
[COL_7
* 3 + 0] = 1.0F
;
699 ret
[COL_7
* 3 + 1] = 1.0F
;
700 ret
[COL_7
* 3 + 2] = 0.0F
;
702 ret
[COL_8
* 3 + 0] = 1.0F
;
703 ret
[COL_8
* 3 + 1] = 0.0F
;
704 ret
[COL_8
* 3 + 2] = 1.0F
;
706 ret
[COL_9
* 3 + 0] = 0.0F
;
707 ret
[COL_9
* 3 + 1] = 1.0F
;
708 ret
[COL_9
* 3 + 2] = 1.0F
;
710 ret
[COL_IMPOSSIBLE
* 3 + 0] = 0.0F
;
711 ret
[COL_IMPOSSIBLE
* 3 + 1] = 0.0F
;
712 ret
[COL_IMPOSSIBLE
* 3 + 2] = 0.0F
;
714 ret
[COL_SEL
* 3 + 0] = 1.0F
;
715 ret
[COL_SEL
* 3 + 1] = 1.0F
;
716 ret
[COL_SEL
* 3 + 2] = 1.0F
;
718 ret
[COL_HIGHLIGHT
* 3 + 0] = 1.0F
;
719 ret
[COL_HIGHLIGHT
* 3 + 1] = 1.0F
;
720 ret
[COL_HIGHLIGHT
* 3 + 2] = 1.0F
;
722 ret
[COL_LOWLIGHT
* 3 + 0] = ret
[COL_BACKGROUND
* 3 + 0] * 2.0 / 3.0;
723 ret
[COL_LOWLIGHT
* 3 + 1] = ret
[COL_BACKGROUND
* 3 + 1] * 2.0 / 3.0;
724 ret
[COL_LOWLIGHT
* 3 + 2] = ret
[COL_BACKGROUND
* 3 + 2] * 2.0 / 3.0;
726 *ncolours
= NCOLOURS
;
730 static game_drawstate
*game_new_drawstate(game_state
*state
)
732 struct game_drawstate
*ds
= snew(struct game_drawstate
);
736 ds
->tileinner
= ds
->tilegap
= 0; /* not decided yet */
737 ds
->tiles
= snewn(state
->n
, int);
738 for (i
= 0; i
< state
->n
; i
++)
744 static void game_free_drawstate(game_drawstate
*ds
)
750 /* Drawing routing for the tile at (x,y) is responsible for drawing
751 * itself and the gaps to its right and below. If we're the same colour
752 * as the tile to our right, then we fill in the gap; ditto below, and if
753 * both then we fill the teeny tiny square in the corner as well.
756 static void tile_redraw(frontend
*fe
, game_drawstate
*ds
,
757 int x
, int y
, int dright
, int dbelow
,
758 int tile
, game_state
*state
, int bgcolour
)
760 int outer
= bgcolour
, inner
= outer
, col
= tile
& TILE_COLMASK
;
763 if (state
->impossible
) {
765 inner
= COL_IMPOSSIBLE
;
766 } else if (tile
& TILE_SELECTED
) {
773 draw_rect(fe
, COORD(x
), COORD(y
), TILE_INNER
, TILE_INNER
, outer
);
774 draw_rect(fe
, COORD(x
)+TILE_INNER
/4, COORD(y
)+TILE_INNER
/4,
775 TILE_INNER
/2, TILE_INNER
/2, inner
);
778 draw_rect(fe
, COORD(x
)+TILE_INNER
, COORD(y
), TILE_GAP
, TILE_INNER
,
779 (tile
& TILE_JOINRIGHT
) ? outer
: bgcolour
);
781 draw_rect(fe
, COORD(x
), COORD(y
)+TILE_INNER
, TILE_INNER
, TILE_GAP
,
782 (tile
& TILE_JOINDOWN
) ? outer
: bgcolour
);
783 if (dright
&& dbelow
)
784 draw_rect(fe
, COORD(x
)+TILE_INNER
, COORD(y
)+TILE_INNER
, TILE_GAP
, TILE_GAP
,
785 (tile
& TILE_JOINDIAG
) ? outer
: bgcolour
);
787 if (tile
& TILE_HASSEL
) {
788 int sx
= COORD(x
)+2, sy
= COORD(y
)+2, ssz
= TILE_INNER
-5;
789 int scol
= (outer
== COL_SEL
) ? COL_LOWLIGHT
: COL_HIGHLIGHT
;
790 draw_line(fe
, sx
, sy
, sx
+ssz
, sy
, scol
);
791 draw_line(fe
, sx
+ssz
, sy
, sx
+ssz
, sy
+ssz
, scol
);
792 draw_line(fe
, sx
+ssz
, sy
+ssz
, sx
, sy
+ssz
, scol
);
793 draw_line(fe
, sx
, sy
+ssz
, sx
, sy
, scol
);
796 draw_update(fe
, COORD(x
), COORD(y
), TILE_SIZE
, TILE_SIZE
);
799 static void game_redraw(frontend
*fe
, game_drawstate
*ds
, game_state
*oldstate
,
800 game_state
*state
, int dir
, game_ui
*ui
,
801 float animtime
, float flashtime
)
805 debug(("samegame redraw: dir %d, oldstate 0x%lx, animtime %f, flashtime %f",
806 dir
, oldstate
, animtime
, flashtime
));
808 /* This was entirely cloned from fifteen.c; it should probably be
809 * moved into some generic 'draw-recessed-rectangle' utility fn. */
814 TILE_SIZE
* state
->params
.w
+ 2 * BORDER
,
815 TILE_SIZE
* state
->params
.h
+ 2 * BORDER
, COL_BACKGROUND
);
816 draw_update(fe
, 0, 0,
817 TILE_SIZE
* state
->params
.w
+ 2 * BORDER
,
818 TILE_SIZE
* state
->params
.h
+ 2 * BORDER
);
821 * Recessed area containing the whole puzzle.
823 coords
[0] = COORD(state
->params
.w
) + HIGHLIGHT_WIDTH
- 1 - TILE_GAP
;
824 coords
[1] = COORD(state
->params
.h
) + HIGHLIGHT_WIDTH
- 1 - TILE_GAP
;
825 coords
[2] = COORD(state
->params
.w
) + HIGHLIGHT_WIDTH
- 1 - TILE_GAP
;
826 coords
[3] = COORD(0) - HIGHLIGHT_WIDTH
;
827 coords
[4] = coords
[2] - TILE_SIZE
;
828 coords
[5] = coords
[3] + TILE_SIZE
;
829 coords
[8] = COORD(0) - HIGHLIGHT_WIDTH
;
830 coords
[9] = COORD(state
->params
.h
) + HIGHLIGHT_WIDTH
- 1 - TILE_GAP
;
831 coords
[6] = coords
[8] + TILE_SIZE
;
832 coords
[7] = coords
[9] - TILE_SIZE
;
833 draw_polygon(fe
, coords
, 5, TRUE
, COL_HIGHLIGHT
);
834 draw_polygon(fe
, coords
, 5, FALSE
, COL_HIGHLIGHT
);
836 coords
[1] = COORD(0) - HIGHLIGHT_WIDTH
;
837 coords
[0] = COORD(0) - HIGHLIGHT_WIDTH
;
838 draw_polygon(fe
, coords
, 5, TRUE
, COL_LOWLIGHT
);
839 draw_polygon(fe
, coords
, 5, FALSE
, COL_LOWLIGHT
);
844 if (flashtime
> 0.0) {
845 int frame
= (int)(flashtime
/ FLASH_FRAME
);
846 bgcolour
= (frame
% 2 ? COL_LOWLIGHT
: COL_HIGHLIGHT
);
848 bgcolour
= COL_BACKGROUND
;
850 for (x
= 0; x
< state
->params
.w
; x
++) {
851 for (y
= 0; y
< state
->params
.h
; y
++) {
852 int i
= (state
->params
.w
* y
) + x
;
853 int col
= COL(state
,x
,y
), tile
= col
;
854 int dright
= (x
+1 < state
->params
.w
);
855 int dbelow
= (y
+1 < state
->params
.h
);
857 tile
|= ISSEL(ui
,x
,y
);
858 if (dright
&& COL(state
,x
+1,y
) == col
)
859 tile
|= TILE_JOINRIGHT
;
860 if (dbelow
&& COL(state
,x
,y
+1) == col
)
861 tile
|= TILE_JOINDOWN
;
862 if ((tile
& TILE_JOINRIGHT
) && (tile
& TILE_JOINDOWN
) &&
863 COL(state
,x
+1,y
+1) == col
)
864 tile
|= TILE_JOINDIAG
;
866 if (ui
->displaysel
&& ui
->xsel
== x
&& ui
->ysel
== y
)
869 /* For now we're never expecting oldstate at all (because we have
870 * no animation); when we do we might well want to be looking
871 * at the tile colours from oldstate, not state. */
872 if ((oldstate
&& COL(oldstate
,x
,y
) != col
) ||
874 (ds
->bgcolour
!= bgcolour
) ||
875 (tile
!= ds
->tiles
[i
])) {
876 tile_redraw(fe
, ds
, x
, y
, dright
, dbelow
,
877 tile
, state
, bgcolour
);
882 ds
->bgcolour
= bgcolour
;
885 char status
[255], score
[80];
887 sprintf(score
, "Score: %d", state
->score
);
890 sprintf(status
, "COMPLETE! %s", score
);
891 else if (state
->impossible
)
892 sprintf(status
, "Cannot move! %s", score
);
893 else if (ui
->nselected
)
894 sprintf(status
, "%s Selected: %d (%d)",
895 score
, ui
->nselected
, npoints(&state
->params
, ui
->nselected
));
897 sprintf(status
, "%s", score
);
898 status_bar(fe
, status
);
902 static float game_anim_length(game_state
*oldstate
, game_state
*newstate
,
903 int dir
, game_ui
*ui
)
908 static float game_flash_length(game_state
*oldstate
, game_state
*newstate
,
909 int dir
, game_ui
*ui
)
911 if ((!oldstate
->complete
&& newstate
->complete
) ||
912 (!oldstate
->impossible
&& newstate
->impossible
))
913 return 2 * FLASH_FRAME
;
918 static int game_wants_statusbar(void)
923 static int game_timing_state(game_state
*state
)
929 #define thegame samegame
932 const struct game thegame
= {
940 TRUE
, game_configure
, custom_params
,
949 TRUE
, game_text_format
,
961 game_wants_statusbar
,
962 FALSE
, game_timing_state
,
963 0, /* mouse_priorities */