int current_tile;
int diff_x, diff_y;
+ int click_x, click_y;
+ int release_x, release_y;
} game_t;
static void tile_init (tile_t *tile, color_t color, int number)
if (tile->color == RED)
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
if (tile->color == YELLOW)
- cairo_set_source_rgb (cr, 1.0, .843, 0.0);
- cairo_move_to (cr, 10, 25);
+ cairo_set_source_rgb (cr, 1.0, .843, 0.0);
+ if (tile->number + 1 > 9)
+ cairo_move_to (cr, 1, 25);
+ else
+ cairo_move_to (cr, 10, 25);
cairo_set_font_size(cr, 25);
cairo_show_text (cr, number_string);
{
int i;
qsort (&tile_group->tiles[0], tile_group->num_tiles,
- sizeof (tile_t), tile_compare);
-
+ sizeof (tile_t), tile_compare);
+
if (tile_group->num_tiles > 13 || tile_group->num_tiles < 3)
{
- return 0;
+ printf("fail run - invalid num tiles; ");
+ return 0;
}
for (i = 0; i < tile_group->num_tiles - 1; ++i)
- if(tile_group->tiles[i].color != tile_group->tiles[i + 1].color)
- {
- return 0;
- }
- if(tile_group->tiles[i].number != tile_group->tiles[i + 1].number -1)
- {
- return 0;
- }
+ {
+ if(tile_group->tiles[i].color != tile_group->tiles[i + 1].color)
+ {
+ printf("fail run - colors don't match; ");
+ return 0;
+ }
+ if( tile_group->tiles[i].number != tile_group->tiles[i + 1].number -1 &&
+ i+1 != tile_group->num_tiles)
+ {
+ printf("fail run - invalid number sequence; ");
+ return 0;
+ }
+ }
return 1;
}
static int tile_group_is_set(tile_group_t *tile_group)
{
int i;
- color_t seen_color[tile_group->num_tiles];
+ color_t seen_color[4];
+ for (i = 0; i < 4; i++)
+ seen_color[i] = 0;
if (tile_group->num_tiles > 4 || tile_group->num_tiles < 3)
{
- return 0;
+ printf("fail set - invalid num tiles; ");
+ return 0;
}
- for (i = 0; i < tile_group->num_tiles - 1; ++i)
+ for (i = 0; i <= tile_group->num_tiles - 1; ++i)
{
- if (tile_group->tiles[i].number != tile_group->tiles[i + 1].number)
- {
- return 0;
- }
+ if (tile_group->tiles[i].number != tile_group->tiles[i + 1].number &&
+ i+1 != tile_group->num_tiles)
+ {
+ printf("fail set - numbers don't match; ");
+ return 0;
+ }
+ seen_color[tile_group->tiles[i].color] += 1;
}
- seen_color[i] = tile_group->tiles[i].color;
- for (i = 0; i < tile_group->num_tiles; ++i)
+ for (i = 0; i < 4; i++)
{
- seen_color[tile_group->tiles[i].color]++;
- if (seen_color[tile_group->tiles[i].color] > 1)
- {
- return 0;
- }
+ if (seen_color[i] > 1)
+ {
+ printf("fail set - repeat color; ");
+ return 0;
+ }
}
return 1;
}
if (error)
FATAL_ERROR (error->message);
- game->current_tile = game->deck.num_tiles - 1;
+ /*This line appears to be useless, has been replaced by line below*/
+ //game->current_tile = game->deck.num_tiles - 1;
+ game->current_tile = -1;
+
game->diff_x = game->diff_y = 0;
}
for (i = 0; i < game->deck.num_tiles; i++)
{
- tile_x = game->deck.tiles[i].x;
- tile_y = game->deck.tiles[i].y;
- if (event->x >= tile_x && event->x <= (tile_x + TILE_WIDTH) &&
- event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) )
- {
- game->current_tile = i;
- game->diff_x = event->x - tile_x;
- game->diff_y = event->y - tile_y;
- }
+ tile_x = game->deck.tiles[i].x;
+ tile_y = game->deck.tiles[i].y;
+ if (event->x >= tile_x && event->x <= (tile_x + TILE_WIDTH) &&
+ event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) )
+ {
+ game->current_tile = i;
+ game->diff_x = event->x - tile_x;
+ game->diff_y = event->y - tile_y;
+ }
+ }
+ if (game->current_tile == -1)
+ {
+ game->click_x = event->x;
+ game->click_y = event->y;
}
-
return TRUE;
}
static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *event, game_t *game)
{
+ if (game->current_tile == -1)
+ {
+ tile_group_t group;
+ group.num_tiles = 0;
+
+ int i, tile_x, tile_y;
+ for (i = 0; i < game->deck.num_tiles; i++)
+ {
+ tile_x = game->deck.tiles[i].x;
+ tile_y = game->deck.tiles[i].y;
+ if ( (event->x >= tile_x && game->click_x <= tile_x &&
+ event->y >= tile_y && game->click_y <= tile_y) ||
+ (event->x >= tile_x && game->click_x <= tile_x &&
+ event->y <= (tile_y + TILE_HEIGHT) && game->click_y >= tile_y) )
+ {
+ group.tiles[group.num_tiles] = game->deck.tiles[i];
+ group.num_tiles++;
+ }
+ }
+ printf("is run %d\n", tile_group_is_run_one(&group) );
+ printf("is set %d\n", tile_group_is_set(&group) );
+ for (i = 0; i < group.num_tiles; i++)
+ tile_print(group.tiles[i]);
+ }
+
game->current_tile = -1;
- printf ("You released button %d\n", event->button);
return TRUE;
}