5 #include <librsvg/rsvg.h>
6 #include <librsvg/rsvg-cairo.h>
9 * TILE_NUMBER_X_OFFSET = 3
11 * || TILE_NUMBER_WIDTH = 34
13 * || | TILE_WIDTH = 40
16 * +-----+ - TILE_NUMBER_Y_OFFSET = 3 -
19 * || || TILE_NUMBER_HEIGHT = 24 |
21 * | _ | _ |-TILE_HEIGHT = 50
23 * || || TILE_SUN_HEIGHT = 20 |
25 * | | TILE_SUN_Y_OFFSET = 3 |
27 * || | TILE_SUN_WIDTH = 20
29 * || TILE_SUN_X_OFFSET = 10
32 #define TILE_HEIGHT 50
34 #define TILE_NUMBER_X_OFFSET 3
35 #define TILE_NUMBER_Y_OFFSET 3
36 #define TILE_NUMBER_WIDTH 34
37 #define TILE_NUMBER_HEIGHT 24
39 #define TILE_SUN_X_OFFSET 10
40 #define TILE_SUN_Y_OFFSET 3
41 #define TILE_SUN_WIDTH 20
42 #define TILE_SUN_HEIGHT 20
44 #define FATAL_ERROR(msg) \
45 do { fprintf (stderr, "Error: %s\n", msg); exit (1); } while (0)
47 char *colors[] = {"Black", "Blue", "Red", "Yellow"};
49 typedef enum {BLACK, BLUE, RED, YELLOW} color_t;
60 #define DECK_MAX_TILES 104
63 tile_t tiles[DECK_MAX_TILES];
67 #define TILE_GROUP_MAX_TILES DECK_MAX_TILES
69 typedef struct tile_group {
70 tile_t tiles[TILE_GROUP_MAX_TILES];
74 #define BOARD_MAX_TILE_GROUPS (DECK_MAX_TILES / 3)
76 typedef struct board {
77 tile_group_t groups[BOARD_MAX_TILE_GROUPS];
81 typedef struct player {
85 typedef struct selection_box {
86 int x1, x2, y1, y2, visible;
89 #define GAME_MAX_PLAYERS 4
90 #define GAME_WINDOW_DEFAULT_WIDTH 800
91 #define GAME_WINDOW_DEFAULT_HEIGHT 600
93 typedef struct state {
94 player_t players[GAME_MAX_PLAYERS];
100 player_t players[GAME_MAX_PLAYERS];
104 selection_box_t selection_box;
106 RsvgHandle *blanktile;
107 RsvgHandle *selectedtile;
108 RsvgHandle *ownedtile;
111 tile_t *current_tile;
116 int click_x, click_y;
117 int release_x, release_y; /*Currently unused*/
120 static void selection_box_init(selection_box_t *box)
129 static void selection_box_draw(selection_box_t *box, cairo_t *cr)
131 cairo_rectangle (cr, box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1);
132 cairo_set_source_rgba(cr, 0.0, 0.1, 0.2, 0.5);
136 static void tile_init (tile_t *tile, color_t color, int number)
139 tile->number = number;
146 static void tile_set_x_y (tile_t *tile, int x, int y)
152 static void tile_print(tile_t tile)
154 printf("%6s %2d\n", colors[tile.color], tile.number + 1);
157 static void tile_draw(game_t *game, tile_t *tile, cairo_t *cr, GdkRegion *region)
159 char number_string[3];
161 GdkRectangle rectangle;
163 rectangle.x = tile->x - 1;
164 rectangle.y = tile->y - 1;
165 rectangle.width = TILE_WIDTH + 2;
166 rectangle.height = TILE_HEIGHT + 2;
167 if (gdk_region_rect_in (region, &rectangle) == GDK_OVERLAP_RECTANGLE_OUT)
170 len = snprintf (number_string, 3, "%d", tile->number + 1);
171 if (len < 0 || len >= 3)
172 FATAL_ERROR ("snprintf failed");
175 cairo_translate(cr, tile->x, tile->y);
178 rsvg_handle_render_cairo (game->selectedtile, cr);
180 rsvg_handle_render_cairo (game->ownedtile, cr);
182 rsvg_handle_render_cairo (game->blanktile, cr);
184 if (tile->color == BLACK)
185 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
186 if (tile->color == BLUE)
187 cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
188 if (tile->color == RED)
189 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
190 if (tile->color == YELLOW)
191 cairo_set_source_rgb (cr, 1.0, .843, 0.0);
192 if (tile->number + 1 > 9)
193 cairo_move_to (cr, 1, 25);
195 cairo_move_to (cr, 10, 25);
196 cairo_set_font_size(cr, 25);
197 cairo_show_text (cr, number_string);
202 static void tile_group_init(tile_group_t *tile_group)
204 tile_group->num_tiles = 0;
207 static void board_init(board_t *board)
210 board->num_groups = 0;
212 for (i = 0; i <= BOARD_MAX_TILE_GROUPS; ++i)
214 tile_group_init(&board->groups[i]);
218 static void player_init(player_t *player)
220 tile_group_init(&player->hand);
224 /* If tile_one < tile_two, then return value will be negative
225 if they are equal, 0 will be returned,
226 if tile_one > tile_two, then return value will be positive */
227 static int tile_compare(const void *one, const void *two)
229 const tile_t *tile_one = one;
230 const tile_t *tile_two = two;
231 return tile_one->number - tile_two->number;
234 static int tile_compare_1(tile_t *tile_one, tile_t *tile_two)
236 return tile_one->number - tile_two->number;
240 static int tile_in_box(game_t *game, tile_t *tile)
246 static int tile_group_is_run_one(tile_group_t *tile_group)
249 qsort (&tile_group->tiles[0], tile_group->num_tiles,
250 sizeof (tile_t), tile_compare);
252 if (tile_group->num_tiles > 13 || tile_group->num_tiles < 3)
254 printf("fail run - invalid num tiles; ");
257 for (i = 0; i < tile_group->num_tiles - 1; ++i)
259 if(tile_group->tiles[i].color != tile_group->tiles[i + 1].color)
261 printf("fail run - colors don't match; ");
264 if( tile_group->tiles[i].number != tile_group->tiles[i + 1].number -1 &&
265 i+1 != tile_group->num_tiles)
267 printf("fail run - invalid number sequence; ");
275 static int tile_group_is_run_two(tile_group_t *tile_group)
278 int lowest = 14, highest = 0;
281 /* By definition, a run must have at least 3 tiles. Also, it's
282 * impossible for any group of tiles with more than 13 tiles to be
283 * a run, (there are only 13 unique numbers so a group with more
284 * than 13 tiles must have some duplicates).
286 if (tile_group->num_tiles < 3 || tile_group->num_tiles > 13)
291 /* Loop through all tiles in the group, ensuring that they are all
292 * the same color and finding the highest and lowest number in the
294 run_color = tile_group->tiles[0].color;
296 for (i = 0; i < tile_group->num_tiles; i++)
298 if (tile_group->tiles[i].color != run_color)
300 if (tile_group->tiles[i].number > highest)
302 highest = tile_group->tiles[i].number;
304 if (tile_group->tiles[i].number < lowest)
306 lowest = tile_group->tiles[i].number;
310 /* For a run, the difference between the highest and lowest tiles
311 * will always be one less than the number of tiles in the
312 * group. If not then we know it's not a run.
314 if (highest - lowest != tile_group->num_tiles - 1)
319 /* XXX: There's a bug here. We're guessing that at this point
320 * anything we're looking at must be a run. This would be correct
321 * if there were no duplicate tiles, but since there are
322 * duplicates this us quite broken. For example consider two
323 * sequences of entirely red tiles:
325 * This is a run: 1, 2, 3, 4
326 * But this is not: 1, 3, 4, 4
328 * As currently written, this function will consider both of these
329 * groups to be a run. One possible fix is to throw away the
330 * highest - lowest heuristic and instead simply sort the tiles up
331 * front and ensure the difference between each adjacent pair is
337 static int tile_group_is_set(tile_group_t *tile_group)
340 color_t seen_color[4];
341 for (i = 0; i < 4; i++)
344 if (tile_group->num_tiles > 4 || tile_group->num_tiles < 3)
346 printf("fail set - invalid num tiles; ");
349 for (i = 0; i <= tile_group->num_tiles - 1; ++i)
351 if (tile_group->tiles[i].number != tile_group->tiles[i + 1].number &&
352 i+1 != tile_group->num_tiles)
354 printf("fail set - numbers don't match; ");
357 seen_color[tile_group->tiles[i].color] += 1;
359 for (i = 0; i < 4; i++)
361 if (seen_color[i] > 1)
363 printf("fail set - repeat color; ");
370 static void deck_deal(game_t *game, deck_t *deck)
376 printf ("How many players(1-4) should I deal in? ");
377 game->num_players = getchar();
378 if (game->num_players == EOF)
380 printf ("\nGoodbye.\n");
384 game->num_players -= '0';
386 for (i = 0; i < game->num_players; ++i)
388 for (j = 0; j < 14; ++j)
390 rand_tile = ((deck->num_tiles + 1.0) * rand()) / (RAND_MAX + 1.0);
391 temp = deck->tiles[rand_tile];
392 deck->tiles[rand_tile] = deck->tiles[deck->num_tiles - 1];
393 game->players[i].hand.tiles[j] = temp;
394 game->players[i].hand.tiles[j].owned = 1;
395 deck->num_tiles -= 1;
396 game->players[i].hand.num_tiles += 1;
399 printf ("Game dealt for %d player(s)\n", game->num_players);
402 static void deck_init(deck_t *deck)
406 for (h = 0; h <= 1; ++h)
408 for (i = 0; i <= 3; ++i)
410 for (j = 0; j <= 12; ++j)
412 tile_init (&deck->tiles[deck->num_tiles++], i, j);
413 printf ("There are %d tiles in the deck\n", deck->num_tiles);
419 static void deck_shuffle(deck_t *deck)
424 for (last = deck->num_tiles; last > 0; --last)
426 rand_tile = ((last + 1.0) * rand()) / (RAND_MAX + 1.0);
427 temp = deck->tiles[rand_tile];
428 deck->tiles[rand_tile] = deck->tiles[last - 1];
429 deck->tiles[last - 1] = temp;
433 static void deck_print(deck_t *deck)
436 for (h = 0; h < 2; ++h)
438 for (i = 0; i < 4; ++i)
440 for (j = 0; j < 13; ++j)
442 tile_print(deck->tiles[j + (i * 13) + (h * 52)]);
446 printf ("There are %d tiles in the deck\n" , deck->num_tiles);
449 static void deck_spread(deck_t *deck)
452 for (i = 0; i < 8; i++)
454 for (j = 0; j < 13; j++)
456 deck->tiles[j + (i * 13)].x = j * 50;
457 deck->tiles[j + (i * 13)].y = i * 60;
462 static void deck_draw(game_t *game, cairo_t *cr, GdkRegion *region)
465 for (i = 0; i < game->deck.num_tiles; i++)
467 tile_draw(game, &game->deck.tiles[i], cr, region);
471 static void hand_print(game_t *game, int player)
474 for (i = 0; i < game->players[player].hand.num_tiles; i++)
476 tile_print(game->players[player].hand.tiles[i]);
480 static void hand_draw(game_t *game, int player, cairo_t *cr, GdkRegion *region, GtkWidget *widget)
483 int window_width = widget->allocation.width;
484 // int window_width = GAME_WINDOW_DEFAULT_WIDTH;
485 int window_height = widget->allocation.height;
486 // int window_height = GAME_WINDOW_DEFAULT_HEIGHT;
487 for (i = 0; i < game->players[player].hand.num_tiles; i++)
489 tile_set_x_y(&game->players[player].hand.tiles[i],
490 ((window_width / game->players[player].hand.num_tiles)) * i,
491 (window_height - TILE_HEIGHT - 6) );
493 for (i = 0; i < game->players[player].hand.num_tiles; i++)
495 tile_draw(game, &game->players[player].hand.tiles[i], cr, region);
499 static void save_state(game_t *game)
502 game->state.board = game->board;
503 game->state.deck = game->deck;
504 //game->state.players = game->players;
507 static void restore_state(game_t *game)
509 game->board = game->state.board;
510 game->deck = game->state.deck;
511 //game->players = game->state.players;
514 static void game_init(game_t *game)
517 GError *error = NULL;
519 game->num_players = 0;
521 for (i = 0; i < GAME_MAX_PLAYERS; ++i)
523 player_init(&game->players[i]);
524 game->num_players += 1;
526 game->current_player = 0;
528 selection_box_init(&game->selection_box);
529 board_init(&game->board);
530 deck_init(&game->deck);
531 deck_shuffle(&game->deck);
533 game->selectedtile = rsvg_handle_new_from_file ("tiles/selected_tile.svg", &error);
535 FATAL_ERROR (error->message);
537 game->ownedtile = rsvg_handle_new_from_file ("tiles/owned_tile.svg", &error);
539 FATAL_ERROR (error->message);
541 game->blanktile = rsvg_handle_new_from_file ("tiles/blank_tile.svg", &error);
543 FATAL_ERROR (error->message);
545 // game->current_tile = game->deck.num_tiles - 1;
546 game->current_tile = &game->deck.tiles[0];
547 game->select_mode = 1;
548 game->drag_group_mode = 0;
550 game->diff_x = game->diff_y = 0;
553 static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, game_t *game)
557 cr = gdk_cairo_create (widget->window);
559 deck_draw(game, cr, event->region);
561 if (game->selection_box.visible)
562 selection_box_draw(&game->selection_box, cr);
564 hand_draw(game, game->current_player, cr, event->region, widget);
565 // hand_draw(game, 0, cr, event->region);
572 static gboolean on_key_press_event (GtkWidget *widget, GdkEventKey *event, game_t *game)
576 cr = gdk_cairo_create (widget->window);
578 printf ("You pressed key %d\n", event->keyval);
580 if (event->keyval == 65293) //HIT ENTER
583 printf ("\tEnd of player %d's turn\n", game->current_player + 1);
584 if (game->current_player == game->num_players - 1)
585 game->current_player = 0;
587 game->current_player += 1;
588 gtk_widget_queue_draw(widget);
591 if (event->keyval == 65307) //HIT ESCAPE
594 printf ("\tChanges Reverted\n");
595 gtk_widget_queue_draw(widget);
598 if (event->keyval == 112) //HIT "P"
600 deck_print(&game->deck);
601 //hand_draw(game, game->current_player, cr, event->region, widget);
602 //on_expose_event(widget, event, game);
606 if (event->keyval == 65505 || event->keyval == 65506)
607 game->drag_group_mode = 1;
612 static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event, game_t *game)
614 int i, tile_x, tile_y;
616 player_t *curr_player = &game->players[0];
618 /*Handle tiles in player's hand */
619 for (i = 0; i < curr_player->hand.num_tiles; i++)
621 curr_tile = &curr_player->hand.tiles[i];
622 if (curr_tile->selected)
624 curr_tile->selected = 0;
625 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
627 tile_x = curr_player->hand.tiles[i].x;
628 tile_y = curr_player->hand.tiles[i].y;
629 if (event->x >= tile_x && event->x <= (tile_x + TILE_WIDTH) &&
630 event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) )
632 game->select_mode = 0;
634 game->current_tile = curr_tile;
636 if (!curr_tile->selected)
637 curr_tile->selected = 1;
639 curr_tile->selected = 0;
640 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
642 game->diff_x = event->x - tile_x;
643 game->diff_y = event->y - tile_y;
647 /*Handle tiles in deck */
648 for (i = 0; i < game->deck.num_tiles; i++)
650 curr_tile = &game->deck.tiles[i];
651 if (curr_tile->selected)
653 curr_tile->selected = 0;
654 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
657 tile_x = game->deck.tiles[i].x;
658 tile_y = game->deck.tiles[i].y;
659 if (event->x >= tile_x && event->x <= (tile_x + TILE_WIDTH) &&
660 event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) )
662 game->select_mode = 0;
664 // game->current_tile = i;
665 game->current_tile = curr_tile;
667 //delete_this? curr_tile = &game->deck.tiles[game->current_tile];
668 if (!curr_tile->selected)
669 curr_tile->selected = 1;
671 curr_tile->selected = 0;
672 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
674 game->diff_x = event->x - tile_x;
675 game->diff_y = event->y - tile_y;
678 if (game->select_mode)
680 // game->deck.tiles[game->current_tile].selected = 0;
681 game->current_tile->selected = 0;
682 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
684 game->selection_box.visible = 1;
685 /*These next two lines appear to be dead
686 game->click_x = event->x;
687 game->click_y = event->y;*/
689 game->selection_box.x1 = event->x;
690 game->selection_box.x2 = event->x;
691 game->selection_box.y1 = event->y;
692 game->selection_box.y2 = event->y;
697 static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *event, game_t *game)
699 if (game->select_mode)
701 game->select_mode = 0;
702 selection_box_t *box;
703 box = &game->selection_box;
705 int x_min = MIN(box->x1, box->x2);
706 int x_max = MAX(box->x1, box->x2);
707 int y_min = MIN(box->y1, box->y2);
708 int y_max = MAX(box->y1, box->y2);
709 int width = abs(box->x2 - box->x1);
710 int height = abs(box->y2 - box->y1);
713 gtk_widget_queue_draw_area (widget, x_min, y_min, width, height);
715 // tile_group_t group;
716 // group.num_tiles = 0;
718 tile_t* group[TILE_GROUP_MAX_TILES];
721 int i, tile_x, tile_y, tile_x2, tile_y2;
722 for (i = 0; i < game->deck.num_tiles; i++)
724 tile_x = game->deck.tiles[i].x;
725 tile_y = game->deck.tiles[i].y;
726 tile_x2 = tile_x + TILE_WIDTH;
727 tile_y2 = tile_y + TILE_HEIGHT;
728 if (/*If top-left corner*/
729 (tile_x >= x_min && tile_x <= x_max &&
730 tile_y >= y_min && tile_y <= y_max) ||
731 /*or bottom-right corner*/
732 (tile_x2 >= x_min && tile_x2 <= x_max &&
733 tile_y2 >= y_min && tile_y2 <= y_max) ||
734 /*or bottom-left corner*/
735 (tile_x >= x_min && tile_x <= x_max &&
736 tile_y2 >= y_min && tile_y2 <= y_max) ||
737 /*or top-right corner*/
738 (tile_x2 >= x_min && tile_x2 <= x_max &&
739 tile_y >= y_min && tile_y <= y_max) ||
741 (y_min >= tile_y && y_min <= tile_y2 &&
742 x_min <= tile_x && x_max >= tile_x) ||
744 (x_min >= tile_x && x_min <= tile_x2 &&
745 y_min <= tile_y && y_max >= tile_y) ||
747 (y_min >= tile_y && y_min <= tile_y2 &&
748 x_min >= tile_x && x_min <= tile_x2) ||
749 /*or bottom edge of tile selected*/
750 (x_min >= tile_x && x_min <= tile_x2 &&
751 y_min >= tile_y && y_min <= tile_y) )
753 // group.tiles[group.num_tiles] = game->deck.tiles[i];
754 // group.num_tiles++;
756 group[num_tiles] = &game->deck.tiles[i];
760 //printf("is run %d\n", tile_group_is_run_one(&group) );
761 //printf("is set %d\n", tile_group_is_set(&group) );
763 // int matching_y = y_min;
765 // for (i = 0; i < group.num_tiles; i++)
767 for (i = 0; i < num_tiles; i++)
769 // tile_print(group.tiles[i]);
770 gtk_widget_queue_draw_area (widget, group[i]->x - 1 , group[i]->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
771 group[i]->x = x_min + (i * (TILE_WIDTH));
773 gtk_widget_queue_draw_area (widget, group[i]->x - 1 , group[i]->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
777 for (i = 0; i < group.num_tiles; i++)
779 for (j = 0; j < game->deck.num_tiles; j++)
781 if (group.tiles[i].x == game->deck.tiles[j].x &&
782 group.tiles[i].y == game->deck.tiles[j].y)
784 new_x = x_min + (i * (TILE_WIDTH));
785 gtk_widget_queue_draw_area (widget, game->deck.tiles[j].x - 1 , game->deck.tiles[j].y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
786 game->deck.tiles[j].x = new_x;
787 game->deck.tiles[j].y = matching_y;
788 gtk_widget_queue_draw_area (widget, new_x - 1 , matching_y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
793 game->select_mode = 1;
798 static gboolean on_button_motion_event (GtkWidget *widget, GdkEventMotion *event,
799 game_t *game, cairo_t *cr)
801 if (game->select_mode)
803 selection_box_t *box;
804 box = &game->selection_box;
807 int x_min = MIN(box->x1, box->x2);
808 int x_max = MAX(box->x1, box->x2);
809 int y_min = MIN(box->y1, box->y2);
810 int y_max = MAX(box->y1, box->y2);
811 int width = abs(box->x2 - box->x1);
812 int height = abs(box->y2 - box->y1);
814 gtk_widget_queue_draw_area ( widget, x_min, y_min, width, height );
819 gtk_widget_queue_draw_area ( widget, MIN(box->x1, box->x2), MIN(box->y1, box->y2), abs(box->x2 - box->x1), abs(box->y2 - box->y1) );
821 int i, tile_x, tile_y, tile_x2, tile_y2;
823 for (i = 0; i < game->deck.num_tiles; i++)
825 curr_tile = &game->deck.tiles[i];
827 tile_x = game->deck.tiles[i].x;
828 tile_y = game->deck.tiles[i].y;
829 tile_x2 = tile_x + TILE_WIDTH;
830 tile_y2 = tile_y + TILE_HEIGHT;
831 if (/*If top-left corner*/
832 (tile_x >= x_min && tile_x <= x_max &&
833 tile_y >= y_min && tile_y <= y_max) ||
834 /*or bottom-right corner*/
835 (tile_x2 >= x_min && tile_x2 <= x_max &&
836 tile_y2 >= y_min && tile_y2 <= y_max) ||
837 /*or bottom-left corner*/
838 (tile_x >= x_min && tile_x <= x_max &&
839 tile_y2 >= y_min && tile_y2 <= y_max) ||
840 /*or top-right corner*/
841 (tile_x2 >= x_min && tile_x2 <= x_max &&
842 tile_y >= y_min && tile_y <= y_max) ||
844 (y_min >= tile_y && y_min <= tile_y2 &&
845 x_min <= tile_x && x_max >= tile_x) ||
847 (x_min >= tile_x && x_min <= tile_x2 &&
848 y_min <= tile_y && y_max >= tile_y) ||
850 (y_min >= tile_y && y_min <= tile_y2 &&
851 x_min >= tile_x && x_min <= tile_x2) ||
852 /*or bottom edge of tile selected*/
853 (x_min >= tile_x && x_min <= tile_x2 &&
854 y_min >= tile_y && y_min <= tile_y) )
856 curr_tile->selected = 1;
857 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
862 if (curr_tile->selected)
864 curr_tile->selected = 0;
865 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
872 if (game->drag_group_mode)
878 // tile = &game->deck.tiles[game->current_tile];
879 tile = game->current_tile;
881 /* First, invalidate the region where the tile currently is. */
882 gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
884 /* Then, move the tile */
885 tile->x = event->x - game->diff_x;
886 tile->y = event->y - game->diff_y;
888 /* Finally, invalidate the region where the tile is now. */
889 gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
894 int main(int argc, char *argv[])
901 gtk_init (&argc, &argv);
904 deck_print(&game.deck);
905 deck_spread(&game.deck);
906 deck_deal(&game, &game.deck);
907 //hand_print(&game, 0); //With Zero being passed, will print hand for player 1(players[0])
908 //deck_print(&game.deck);
910 /* Create a new window */
911 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
912 gtk_window_set_default_size (GTK_WINDOW (window),
913 GAME_WINDOW_DEFAULT_WIDTH,
914 GAME_WINDOW_DEFAULT_HEIGHT);
916 gtk_widget_set_events (window,
919 GDK_BUTTON_MOTION_MASK |
920 GDK_BUTTON_PRESS_MASK |
921 GDK_BUTTON_RELEASE_MASK);
923 g_signal_connect (G_OBJECT (window), "delete_event",
924 G_CALLBACK (gtk_main_quit), NULL);
925 g_signal_connect (G_OBJECT (window), "expose_event",
926 G_CALLBACK (on_expose_event), &game);
927 g_signal_connect (G_OBJECT (window), "key_press_event",
928 G_CALLBACK (on_key_press_event), &game);
929 g_signal_connect (G_OBJECT (window), "button_press_event",
930 G_CALLBACK (on_button_press_event), &game);
931 g_signal_connect (G_OBJECT (window), "button_release_event",
932 G_CALLBACK (on_button_release_event), &game);
933 g_signal_connect (G_OBJECT (window), "motion_notify_event",
934 G_CALLBACK (on_button_motion_event), &game);
937 gtk_widget_show_all (window);