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 */
52 #define TILE_IMPOSSIBLE 0x2000 /* used in drawstate */
54 #define TILE(gs,x,y) ((gs)->tiles[(gs)->params.w*(y)+(x)])
55 #define COL(gs,x,y) (TILE(gs,x,y) & TILE_COLMASK)
56 #define ISSEL(gs,x,y) (TILE(gs,x,y) & TILE_SELECTED)
58 #define SWAPTILE(gs,x1,y1,x2,y2) do { \
59 int t = TILE(gs,x1,y1); \
60 TILE(gs,x1,y1) = TILE(gs,x2,y2); \
64 static int npoints(game_params
*params
, int nsel
)
66 int sdiff
= nsel
- params
->scoresub
;
67 return (sdiff
> 0) ? sdiff
* sdiff
: 0;
71 struct game_params params
;
73 int *tiles
; /* colour only */
75 int complete
, impossible
;
78 static game_params
*default_params(void)
80 game_params
*ret
= snew(game_params
);
88 static const struct game_params samegame_presets
[] = {
96 static int game_fetch_preset(int i
, char **name
, game_params
**params
)
101 if (i
< 0 || i
>= lenof(samegame_presets
))
104 ret
= snew(game_params
);
105 *ret
= samegame_presets
[i
];
107 sprintf(str
, "%dx%d, %d colours", ret
->w
, ret
->h
, ret
->ncols
);
114 static void free_params(game_params
*params
)
119 static game_params
*dup_params(game_params
*params
)
121 game_params
*ret
= snew(game_params
);
122 *ret
= *params
; /* structure copy */
126 static void decode_params(game_params
*params
, char const *string
)
128 char const *p
= string
;
131 while (*p
&& isdigit((unsigned char)*p
)) p
++;
135 while (*p
&& isdigit((unsigned char)*p
)) p
++;
137 params
->h
= params
->w
;
140 params
->ncols
= atoi(p
);
141 while (*p
&& isdigit((unsigned char)*p
)) p
++;
146 params
->scoresub
= atoi(p
);
147 while (*p
&& isdigit((unsigned char)*p
)) p
++;
149 params
->scoresub
= 2;
153 static char *encode_params(game_params
*params
, int full
)
157 sprintf(ret
, "%dx%dc%ds%d",
158 params
->w
, params
->h
, params
->ncols
, params
->scoresub
);
162 static config_item
*game_configure(game_params
*params
)
167 ret
= snewn(5, config_item
);
169 ret
[0].name
= "Width";
170 ret
[0].type
= C_STRING
;
171 sprintf(buf
, "%d", params
->w
);
172 ret
[0].sval
= dupstr(buf
);
175 ret
[1].name
= "Height";
176 ret
[1].type
= C_STRING
;
177 sprintf(buf
, "%d", params
->h
);
178 ret
[1].sval
= dupstr(buf
);
181 ret
[2].name
= "No. of colours";
182 ret
[2].type
= C_STRING
;
183 sprintf(buf
, "%d", params
->ncols
);
184 ret
[2].sval
= dupstr(buf
);
187 ret
[3].name
= "Scoring system";
188 ret
[3].type
= C_CHOICES
;
189 ret
[3].sval
= ":(n-1)^2:(n-2)^2";
190 ret
[3].ival
= params
->scoresub
-1;
200 static game_params
*custom_params(config_item
*cfg
)
202 game_params
*ret
= snew(game_params
);
204 ret
->w
= atoi(cfg
[0].sval
);
205 ret
->h
= atoi(cfg
[1].sval
);
206 ret
->ncols
= atoi(cfg
[2].sval
);
207 ret
->scoresub
= cfg
[3].ival
+ 1;
212 static char *validate_params(game_params
*params
, int full
)
214 if (params
->w
< 1 || params
->h
< 1)
215 return "Width and height must both be positive";
216 if (params
->ncols
< 2)
217 return "It's too easy with only one colour...";
218 if (params
->ncols
> 9)
219 return "Maximum of 9 colours";
221 /* ...and we must make sure we can generate at least 2 squares
222 * of each colour so it's theoretically soluble. */
223 if ((params
->w
* params
->h
) < (params
->ncols
* 2))
224 return "Too many colours makes given grid size impossible";
226 if ((params
->scoresub
< 1) || (params
->scoresub
> 2))
227 return "Scoring system not recognised";
232 /* Currently this is a very very dumb game-generation engine; it
233 * just picks randomly from the tile space. I had a look at a few
234 * other same game implementations, and none of them attempt to do
235 * anything to try and make sure the grid started off with a nice
236 * set of large blocks.
238 * It does at least make sure that there are >= 2 of each colour
239 * present at the start.
242 static char *new_game_desc(game_params
*params
, random_state
*rs
,
243 char **aux
, int interactive
)
246 int n
, i
, j
, c
, retlen
, *tiles
;
248 n
= params
->w
* params
->h
;
249 tiles
= snewn(n
, int);
250 memset(tiles
, 0, n
*sizeof(int));
252 /* randomly place two of each colour */
253 for (c
= 0; c
< params
->ncols
; c
++) {
254 for (j
= 0; j
< 2; j
++) {
256 i
= (int)random_upto(rs
, n
);
257 } while (tiles
[i
] != 0);
262 /* fill in the rest randomly */
263 for (i
= 0; i
< n
; i
++) {
265 tiles
[i
] = (int)random_upto(rs
, params
->ncols
)+1;
270 for (i
= 0; i
< n
; i
++) {
274 k
= sprintf(buf
, "%d,", tiles
[i
]);
275 ret
= sresize(ret
, retlen
+ k
+ 1, char);
276 strcpy(ret
+ retlen
, buf
);
279 ret
[retlen
-1] = '\0'; /* delete last comma */
285 static char *validate_desc(game_params
*params
, char *desc
)
287 int area
= params
->w
* params
->h
, i
;
290 for (i
= 0; i
< area
; i
++) {
294 if (!isdigit((unsigned char)*p
))
295 return "Not enough numbers in string";
296 while (isdigit((unsigned char)*p
)) p
++;
298 if (i
< area
-1 && *p
!= ',')
299 return "Expected comma after number";
300 else if (i
== area
-1 && *p
)
301 return "Excess junk at end of string";
304 if (n
< 0 || n
> params
->ncols
)
305 return "Colour out of range";
307 if (*p
) p
++; /* eat comma */
312 static game_state
*new_game(midend_data
*me
, game_params
*params
, char *desc
)
314 game_state
*state
= snew(game_state
);
318 state
->params
= *params
; /* struct copy */
319 state
->n
= state
->params
.w
* state
->params
.h
;
320 state
->tiles
= snewn(state
->n
, int);
322 for (i
= 0; i
< state
->n
; i
++) {
324 state
->tiles
[i
] = atoi(p
);
325 while (*p
&& *p
!= ',')
327 if (*p
) p
++; /* eat comma */
329 state
->complete
= state
->impossible
= 0;
335 static game_state
*dup_game(game_state
*state
)
337 game_state
*ret
= snew(game_state
);
339 *ret
= *state
; /* structure copy, except... */
341 ret
->tiles
= snewn(state
->n
, int);
342 memcpy(ret
->tiles
, state
->tiles
, state
->n
* sizeof(int));
347 static void free_game(game_state
*state
)
353 static char *solve_game(game_state
*state
, game_state
*currstate
,
354 char *aux
, char **error
)
359 static char *game_text_format(game_state
*state
)
364 maxlen
= state
->params
.h
* (state
->params
.w
+ 1);
365 ret
= snewn(maxlen
+1, char);
368 for (y
= 0; y
< state
->params
.h
; y
++) {
369 for (x
= 0; x
< state
->params
.w
; x
++) {
370 int t
= TILE(state
,x
,y
);
371 if (t
<= 0) *p
++ = ' ';
372 else if (t
< 10) *p
++ = '0'+t
;
373 else *p
++ = 'a'+(t
-10);
377 assert(p
- ret
== maxlen
);
383 struct game_params params
;
384 int *tiles
; /* selected-ness only */
386 int xsel
, ysel
, displaysel
;
389 static game_ui
*new_ui(game_state
*state
)
391 game_ui
*ui
= snew(game_ui
);
393 ui
->params
= state
->params
; /* structure copy */
394 ui
->tiles
= snewn(state
->n
, int);
395 memset(ui
->tiles
, 0, state
->n
*sizeof(int));
398 ui
->xsel
= ui
->ysel
= ui
->displaysel
= 0;
403 static void free_ui(game_ui
*ui
)
409 static char *encode_ui(game_ui
*ui
)
414 static void decode_ui(game_ui
*ui
, char *encoding
)
418 static void sel_clear(game_ui
*ui
, game_state
*state
)
422 for (i
= 0; i
< state
->n
; i
++)
423 ui
->tiles
[i
] &= ~TILE_SELECTED
;
428 static void game_changed_state(game_ui
*ui
, game_state
*oldstate
,
429 game_state
*newstate
)
431 sel_clear(ui
, newstate
);
434 * If the game state has just changed into an unplayable one
435 * (either completed or impossible), we vanish the keyboard-
438 if (newstate
->complete
|| newstate
->impossible
)
442 static char *sel_movedesc(game_ui
*ui
, game_state
*state
)
445 char *ret
, *sep
, buf
[80];
449 ret
= snewn(retsize
, char);
454 for (i
= 0; i
< state
->n
; i
++) {
455 if (ui
->tiles
[i
] & TILE_SELECTED
) {
456 sprintf(buf
, "%s%d", sep
, i
);
458 if (retlen
+ strlen(buf
) >= retsize
) {
459 retsize
= retlen
+ strlen(buf
) + 256;
460 ret
= sresize(ret
, retsize
, char);
462 strcpy(ret
+ retlen
, buf
);
463 retlen
+= strlen(buf
);
465 ui
->tiles
[i
] &= ~TILE_SELECTED
;
470 assert(retlen
< retsize
);
471 ret
[retlen
++] = '\0';
472 return sresize(ret
, retlen
, char);
475 static void sel_expand(game_ui
*ui
, game_state
*state
, int tx
, int ty
)
477 int ns
= 1, nadded
, x
, y
, c
;
479 TILE(ui
,tx
,ty
) |= TILE_SELECTED
;
483 for (x
= 0; x
< state
->params
.w
; x
++) {
484 for (y
= 0; y
< state
->params
.h
; y
++) {
485 if (x
== tx
&& y
== ty
) continue;
486 if (ISSEL(ui
,x
,y
)) continue;
490 ISSEL(ui
,x
-1,y
) && COL(state
,x
-1,y
) == c
) {
491 TILE(ui
,x
,y
) |= TILE_SELECTED
;
496 if ((x
+1 < state
->params
.w
) &&
497 ISSEL(ui
,x
+1,y
) && COL(state
,x
+1,y
) == c
) {
498 TILE(ui
,x
,y
) |= TILE_SELECTED
;
504 ISSEL(ui
,x
,y
-1) && COL(state
,x
,y
-1) == c
) {
505 TILE(ui
,x
,y
) |= TILE_SELECTED
;
510 if ((y
+1 < state
->params
.h
) &&
511 ISSEL(ui
,x
,y
+1) && COL(state
,x
,y
+1) == c
) {
512 TILE(ui
,x
,y
) |= TILE_SELECTED
;
519 } while (nadded
> 0);
524 sel_clear(ui
, state
);
528 static int sg_emptycol(game_state
*ret
, int x
)
531 for (y
= 0; y
< ret
->params
.h
; y
++) {
532 if (COL(ret
,x
,y
)) return 0;
538 static void sg_snuggle(game_state
*ret
)
542 /* make all unsupported tiles fall down. */
545 for (x
= 0; x
< ret
->params
.w
; x
++) {
546 for (y
= ret
->params
.h
-1; y
> 0; y
--) {
547 if (COL(ret
,x
,y
) != 0) continue;
548 if (COL(ret
,x
,y
-1) != 0) {
549 SWAPTILE(ret
,x
,y
,x
,y
-1);
556 /* shuffle all columns as far left as they can go. */
559 for (x
= 0; x
< ret
->params
.w
-1; x
++) {
560 if (sg_emptycol(ret
,x
) && !sg_emptycol(ret
,x
+1)) {
562 for (y
= 0; y
< ret
->params
.h
; y
++) {
563 SWAPTILE(ret
,x
,y
,x
+1,y
);
570 static void sg_check(game_state
*ret
)
572 int x
,y
, complete
= 1, impossible
= 1;
574 for (x
= 0; x
< ret
->params
.w
; x
++) {
575 for (y
= 0; y
< ret
->params
.h
; y
++) {
576 if (COL(ret
,x
,y
) == 0)
579 if (x
+1 < ret
->params
.w
) {
580 if (COL(ret
,x
,y
) == COL(ret
,x
+1,y
))
583 if (y
+1 < ret
->params
.h
) {
584 if (COL(ret
,x
,y
) == COL(ret
,x
,y
+1))
589 ret
->complete
= complete
;
590 ret
->impossible
= impossible
;
593 struct game_drawstate
{
594 int started
, bgcolour
;
595 int tileinner
, tilegap
;
596 int *tiles
; /* contains colour and SELECTED. */
599 static char *interpret_move(game_state
*state
, game_ui
*ui
, game_drawstate
*ds
,
600 int x
, int y
, int button
)
607 if (button
== RIGHT_BUTTON
|| button
== LEFT_BUTTON
) {
608 tx
= FROMCOORD(x
); ty
= FROMCOORD(y
);
609 } else if (button
== CURSOR_UP
|| button
== CURSOR_DOWN
||
610 button
== CURSOR_LEFT
|| button
== CURSOR_RIGHT
) {
613 dx
= (button
== CURSOR_LEFT
) ?
-1 : ((button
== CURSOR_RIGHT
) ?
+1 : 0);
614 dy
= (button
== CURSOR_DOWN
) ?
+1 : ((button
== CURSOR_UP
) ?
-1 : 0);
615 ui
->xsel
= (ui
->xsel
+ state
->params
.w
+ dx
) % state
->params
.w
;
616 ui
->ysel
= (ui
->ysel
+ state
->params
.h
+ dy
) % state
->params
.h
;
618 } else if (button
== CURSOR_SELECT
|| button
== ' ' || button
== '\r' ||
626 if (tx
< 0 || tx
>= state
->params
.w
|| ty
< 0 || ty
>= state
->params
.h
)
628 if (COL(state
, tx
, ty
) == 0) return NULL
;
630 if (ISSEL(ui
,tx
,ty
)) {
631 if (button
== RIGHT_BUTTON
)
632 sel_clear(ui
, state
);
634 ret
= sel_movedesc(ui
, state
);
636 sel_clear(ui
, state
); /* might be no-op */
637 sel_expand(ui
, state
, tx
, ty
);
643 static game_state
*execute_move(game_state
*from
, char *move
)
648 if (move
[0] == 'M') {
649 ret
= dup_game(from
);
656 if (i
< 0 || i
>= ret
->n
) {
663 while (*move
&& isdigit((unsigned char)*move
)) move
++;
664 if (*move
== ',') move
++;
667 ret
->score
+= npoints(&ret
->params
, n
);
669 sg_snuggle(ret
); /* shifts blanks down and to the left */
670 sg_check(ret
); /* checks for completeness or impossibility */
674 return NULL
; /* couldn't parse move string */
677 /* ----------------------------------------------------------------------
681 static void game_set_size(game_drawstate
*ds
, game_params
*params
,
685 ds
->tileinner
= tilesize
- ds
->tilegap
;
688 static void game_compute_size(game_params
*params
, int tilesize
,
691 /* Ick: fake up tile size variables for macro expansion purposes */
692 game_drawstate ads
, *ds
= &ads
;
693 game_set_size(ds
, params
, tilesize
);
695 *x
= TILE_SIZE
* params
->w
+ 2 * BORDER
- TILE_GAP
;
696 *y
= TILE_SIZE
* params
->h
+ 2 * BORDER
- TILE_GAP
;
699 static float *game_colours(frontend
*fe
, game_state
*state
, int *ncolours
)
701 float *ret
= snewn(3 * NCOLOURS
, float);
703 frontend_default_colour(fe
, &ret
[COL_BACKGROUND
* 3]);
705 ret
[COL_1
* 3 + 0] = 0.0F
;
706 ret
[COL_1
* 3 + 1] = 0.0F
;
707 ret
[COL_1
* 3 + 2] = 1.0F
;
709 ret
[COL_2
* 3 + 0] = 0.0F
;
710 ret
[COL_2
* 3 + 1] = 0.5F
;
711 ret
[COL_2
* 3 + 2] = 0.0F
;
713 ret
[COL_3
* 3 + 0] = 1.0F
;
714 ret
[COL_3
* 3 + 1] = 0.0F
;
715 ret
[COL_3
* 3 + 2] = 0.0F
;
717 ret
[COL_4
* 3 + 0] = 1.0F
;
718 ret
[COL_4
* 3 + 1] = 1.0F
;
719 ret
[COL_4
* 3 + 2] = 0.0F
;
721 ret
[COL_5
* 3 + 0] = 1.0F
;
722 ret
[COL_5
* 3 + 1] = 0.0F
;
723 ret
[COL_5
* 3 + 2] = 1.0F
;
725 ret
[COL_6
* 3 + 0] = 0.0F
;
726 ret
[COL_6
* 3 + 1] = 1.0F
;
727 ret
[COL_6
* 3 + 2] = 1.0F
;
729 ret
[COL_7
* 3 + 0] = 0.5F
;
730 ret
[COL_7
* 3 + 1] = 0.5F
;
731 ret
[COL_7
* 3 + 2] = 1.0F
;
733 ret
[COL_8
* 3 + 0] = 0.5F
;
734 ret
[COL_8
* 3 + 1] = 1.0F
;
735 ret
[COL_8
* 3 + 2] = 0.5F
;
737 ret
[COL_9
* 3 + 0] = 1.0F
;
738 ret
[COL_9
* 3 + 1] = 0.5F
;
739 ret
[COL_9
* 3 + 2] = 0.5F
;
741 ret
[COL_IMPOSSIBLE
* 3 + 0] = 0.0F
;
742 ret
[COL_IMPOSSIBLE
* 3 + 1] = 0.0F
;
743 ret
[COL_IMPOSSIBLE
* 3 + 2] = 0.0F
;
745 ret
[COL_SEL
* 3 + 0] = 1.0F
;
746 ret
[COL_SEL
* 3 + 1] = 1.0F
;
747 ret
[COL_SEL
* 3 + 2] = 1.0F
;
749 ret
[COL_HIGHLIGHT
* 3 + 0] = 1.0F
;
750 ret
[COL_HIGHLIGHT
* 3 + 1] = 1.0F
;
751 ret
[COL_HIGHLIGHT
* 3 + 2] = 1.0F
;
753 ret
[COL_LOWLIGHT
* 3 + 0] = ret
[COL_BACKGROUND
* 3 + 0] * 2.0 / 3.0;
754 ret
[COL_LOWLIGHT
* 3 + 1] = ret
[COL_BACKGROUND
* 3 + 1] * 2.0 / 3.0;
755 ret
[COL_LOWLIGHT
* 3 + 2] = ret
[COL_BACKGROUND
* 3 + 2] * 2.0 / 3.0;
757 *ncolours
= NCOLOURS
;
761 static game_drawstate
*game_new_drawstate(game_state
*state
)
763 struct game_drawstate
*ds
= snew(struct game_drawstate
);
767 ds
->tileinner
= ds
->tilegap
= 0; /* not decided yet */
768 ds
->tiles
= snewn(state
->n
, int);
769 for (i
= 0; i
< state
->n
; i
++)
775 static void game_free_drawstate(game_drawstate
*ds
)
781 /* Drawing routing for the tile at (x,y) is responsible for drawing
782 * itself and the gaps to its right and below. If we're the same colour
783 * as the tile to our right, then we fill in the gap; ditto below, and if
784 * both then we fill the teeny tiny square in the corner as well.
787 static void tile_redraw(frontend
*fe
, game_drawstate
*ds
,
788 int x
, int y
, int dright
, int dbelow
,
789 int tile
, int bgcolour
)
791 int outer
= bgcolour
, inner
= outer
, col
= tile
& TILE_COLMASK
;
794 if (tile
& TILE_IMPOSSIBLE
) {
796 inner
= COL_IMPOSSIBLE
;
797 } else if (tile
& TILE_SELECTED
) {
804 draw_rect(fe
, COORD(x
), COORD(y
), TILE_INNER
, TILE_INNER
, outer
);
805 draw_rect(fe
, COORD(x
)+TILE_INNER
/4, COORD(y
)+TILE_INNER
/4,
806 TILE_INNER
/2, TILE_INNER
/2, inner
);
809 draw_rect(fe
, COORD(x
)+TILE_INNER
, COORD(y
), TILE_GAP
, TILE_INNER
,
810 (tile
& TILE_JOINRIGHT
) ? outer
: bgcolour
);
812 draw_rect(fe
, COORD(x
), COORD(y
)+TILE_INNER
, TILE_INNER
, TILE_GAP
,
813 (tile
& TILE_JOINDOWN
) ? outer
: bgcolour
);
814 if (dright
&& dbelow
)
815 draw_rect(fe
, COORD(x
)+TILE_INNER
, COORD(y
)+TILE_INNER
, TILE_GAP
, TILE_GAP
,
816 (tile
& TILE_JOINDIAG
) ? outer
: bgcolour
);
818 if (tile
& TILE_HASSEL
) {
819 int sx
= COORD(x
)+2, sy
= COORD(y
)+2, ssz
= TILE_INNER
-5;
820 int scol
= (outer
== COL_SEL
) ? COL_LOWLIGHT
: COL_HIGHLIGHT
;
821 draw_line(fe
, sx
, sy
, sx
+ssz
, sy
, scol
);
822 draw_line(fe
, sx
+ssz
, sy
, sx
+ssz
, sy
+ssz
, scol
);
823 draw_line(fe
, sx
+ssz
, sy
+ssz
, sx
, sy
+ssz
, scol
);
824 draw_line(fe
, sx
, sy
+ssz
, sx
, sy
, scol
);
827 draw_update(fe
, COORD(x
), COORD(y
), TILE_SIZE
, TILE_SIZE
);
830 static void game_redraw(frontend
*fe
, game_drawstate
*ds
, game_state
*oldstate
,
831 game_state
*state
, int dir
, game_ui
*ui
,
832 float animtime
, float flashtime
)
836 /* This was entirely cloned from fifteen.c; it should probably be
837 * moved into some generic 'draw-recessed-rectangle' utility fn. */
842 TILE_SIZE
* state
->params
.w
+ 2 * BORDER
,
843 TILE_SIZE
* state
->params
.h
+ 2 * BORDER
, COL_BACKGROUND
);
844 draw_update(fe
, 0, 0,
845 TILE_SIZE
* state
->params
.w
+ 2 * BORDER
,
846 TILE_SIZE
* state
->params
.h
+ 2 * BORDER
);
849 * Recessed area containing the whole puzzle.
851 coords
[0] = COORD(state
->params
.w
) + HIGHLIGHT_WIDTH
- 1 - TILE_GAP
;
852 coords
[1] = COORD(state
->params
.h
) + HIGHLIGHT_WIDTH
- 1 - TILE_GAP
;
853 coords
[2] = COORD(state
->params
.w
) + HIGHLIGHT_WIDTH
- 1 - TILE_GAP
;
854 coords
[3] = COORD(0) - HIGHLIGHT_WIDTH
;
855 coords
[4] = coords
[2] - TILE_SIZE
;
856 coords
[5] = coords
[3] + TILE_SIZE
;
857 coords
[8] = COORD(0) - HIGHLIGHT_WIDTH
;
858 coords
[9] = COORD(state
->params
.h
) + HIGHLIGHT_WIDTH
- 1 - TILE_GAP
;
859 coords
[6] = coords
[8] + TILE_SIZE
;
860 coords
[7] = coords
[9] - TILE_SIZE
;
861 draw_polygon(fe
, coords
, 5, COL_HIGHLIGHT
, COL_HIGHLIGHT
);
863 coords
[1] = COORD(0) - HIGHLIGHT_WIDTH
;
864 coords
[0] = COORD(0) - HIGHLIGHT_WIDTH
;
865 draw_polygon(fe
, coords
, 5, COL_LOWLIGHT
, COL_LOWLIGHT
);
870 if (flashtime
> 0.0) {
871 int frame
= (int)(flashtime
/ FLASH_FRAME
);
872 bgcolour
= (frame
% 2 ? COL_LOWLIGHT
: COL_HIGHLIGHT
);
874 bgcolour
= COL_BACKGROUND
;
876 for (x
= 0; x
< state
->params
.w
; x
++) {
877 for (y
= 0; y
< state
->params
.h
; y
++) {
878 int i
= (state
->params
.w
* y
) + x
;
879 int col
= COL(state
,x
,y
), tile
= col
;
880 int dright
= (x
+1 < state
->params
.w
);
881 int dbelow
= (y
+1 < state
->params
.h
);
883 tile
|= ISSEL(ui
,x
,y
);
884 if (state
->impossible
)
885 tile
|= TILE_IMPOSSIBLE
;
886 if (dright
&& COL(state
,x
+1,y
) == col
)
887 tile
|= TILE_JOINRIGHT
;
888 if (dbelow
&& COL(state
,x
,y
+1) == col
)
889 tile
|= TILE_JOINDOWN
;
890 if ((tile
& TILE_JOINRIGHT
) && (tile
& TILE_JOINDOWN
) &&
891 COL(state
,x
+1,y
+1) == col
)
892 tile
|= TILE_JOINDIAG
;
894 if (ui
->displaysel
&& ui
->xsel
== x
&& ui
->ysel
== y
)
897 /* For now we're never expecting oldstate at all (because we have
898 * no animation); when we do we might well want to be looking
899 * at the tile colours from oldstate, not state. */
900 if ((oldstate
&& COL(oldstate
,x
,y
) != col
) ||
902 (ds
->bgcolour
!= bgcolour
) ||
903 (tile
!= ds
->tiles
[i
])) {
904 tile_redraw(fe
, ds
, x
, y
, dright
, dbelow
, tile
, bgcolour
);
909 ds
->bgcolour
= bgcolour
;
912 char status
[255], score
[80];
914 sprintf(score
, "Score: %d", state
->score
);
917 sprintf(status
, "COMPLETE! %s", score
);
918 else if (state
->impossible
)
919 sprintf(status
, "Cannot move! %s", score
);
920 else if (ui
->nselected
)
921 sprintf(status
, "%s Selected: %d (%d)",
922 score
, ui
->nselected
, npoints(&state
->params
, ui
->nselected
));
924 sprintf(status
, "%s", score
);
925 status_bar(fe
, status
);
929 static float game_anim_length(game_state
*oldstate
, game_state
*newstate
,
930 int dir
, game_ui
*ui
)
935 static float game_flash_length(game_state
*oldstate
, game_state
*newstate
,
936 int dir
, game_ui
*ui
)
938 if ((!oldstate
->complete
&& newstate
->complete
) ||
939 (!oldstate
->impossible
&& newstate
->impossible
))
940 return 2 * FLASH_FRAME
;
945 static int game_wants_statusbar(void)
950 static int game_timing_state(game_state
*state
, game_ui
*ui
)
956 #define thegame samegame
959 const struct game thegame
= {
960 "Same Game", "games.samegame",
967 TRUE
, game_configure
, custom_params
,
975 TRUE
, game_text_format
,
983 PREFERRED_TILE_SIZE
, game_compute_size
, game_set_size
,
990 game_wants_statusbar
,
991 FALSE
, game_timing_state
,
992 0, /* mouse_priorities */