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
94 player_t players[GAME_MAX_PLAYERS];
98 selection_box_t selection_box;
99 RsvgHandle *blanktile;
100 RsvgHandle *selectedtile;
101 RsvgHandle *ownedtile;
103 tile_t *current_tile;
108 int click_x, click_y;
109 int release_x, release_y; /*Currently unused*/
112 static void selection_box_init(selection_box_t *box)
121 static void selection_box_draw(selection_box_t *box, cairo_t *cr)
123 cairo_rectangle (cr, box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1);
124 cairo_set_source_rgba(cr, 0.0, 0.1, 0.2, 0.5);
128 static void tile_init (tile_t *tile, color_t color, int number)
131 tile->number = number;
138 static void tile_set_x_y (tile_t *tile, int x, int y)
144 static void tile_print(tile_t tile)
146 printf("%6s %2d\n", colors[tile.color], tile.number + 1);
149 static void tile_draw(game_t *game, tile_t *tile, cairo_t *cr, GdkRegion *region)
151 char number_string[3];
153 GdkRectangle rectangle;
155 rectangle.x = tile->x - 1;
156 rectangle.y = tile->y - 1;
157 rectangle.width = TILE_WIDTH + 2;
158 rectangle.height = TILE_HEIGHT + 2;
159 if (gdk_region_rect_in (region, &rectangle) == GDK_OVERLAP_RECTANGLE_OUT)
162 len = snprintf (number_string, 3, "%d", tile->number + 1);
163 if (len < 0 || len >= 3)
164 FATAL_ERROR ("snprintf failed");
167 cairo_translate(cr, tile->x, tile->y);
170 rsvg_handle_render_cairo (game->selectedtile, cr);
172 rsvg_handle_render_cairo (game->ownedtile, cr);
174 rsvg_handle_render_cairo (game->blanktile, cr);
176 if (tile->color == BLACK)
177 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
178 if (tile->color == BLUE)
179 cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
180 if (tile->color == RED)
181 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
182 if (tile->color == YELLOW)
183 cairo_set_source_rgb (cr, 1.0, .843, 0.0);
184 if (tile->number + 1 > 9)
185 cairo_move_to (cr, 1, 25);
187 cairo_move_to (cr, 10, 25);
188 cairo_set_font_size(cr, 25);
189 cairo_show_text (cr, number_string);
194 static void tile_group_init(tile_group_t *tile_group)
196 tile_group->num_tiles = 0;
199 static void board_init(board_t *board)
202 board->num_groups = 0;
204 for (i = 0; i <= BOARD_MAX_TILE_GROUPS; ++i)
206 tile_group_init(&board->groups[i]);
210 static void player_init(player_t *player)
212 tile_group_init(&player->hand);
216 /* If tile_one < tile_two, then return value will be negative
217 if they are equal, 0 will be returned,
218 if tile_one > tile_two, then return value will be positive */
219 static int tile_compare(const void *one, const void *two)
221 const tile_t *tile_one = one;
222 const tile_t *tile_two = two;
223 return tile_one->number - tile_two->number;
226 static int tile_group_is_run_one(tile_group_t *tile_group)
229 qsort (&tile_group->tiles[0], tile_group->num_tiles,
230 sizeof (tile_t), tile_compare);
232 if (tile_group->num_tiles > 13 || tile_group->num_tiles < 3)
234 printf("fail run - invalid num tiles; ");
237 for (i = 0; i < tile_group->num_tiles - 1; ++i)
239 if(tile_group->tiles[i].color != tile_group->tiles[i + 1].color)
241 printf("fail run - colors don't match; ");
244 if( tile_group->tiles[i].number != tile_group->tiles[i + 1].number -1 &&
245 i+1 != tile_group->num_tiles)
247 printf("fail run - invalid number sequence; ");
255 static int tile_group_is_run_two(tile_group_t *tile_group)
258 int lowest = 14, highest = 0;
261 /* By definition, a run must have at least 3 tiles. Also, it's
262 * impossible for any group of tiles with more than 13 tiles to be
263 * a run, (there are only 13 unique numbers so a group with more
264 * than 13 tiles must have some duplicates).
266 if (tile_group->num_tiles < 3 || tile_group->num_tiles > 13)
271 /* Loop through all tiles in the group, ensuring that they are all
272 * the same color and finding the highest and lowest number in the
274 run_color = tile_group->tiles[0].color;
276 for (i = 0; i < tile_group->num_tiles; i++)
278 if (tile_group->tiles[i].color != run_color)
280 if (tile_group->tiles[i].number > highest)
282 highest = tile_group->tiles[i].number;
284 if (tile_group->tiles[i].number < lowest)
286 lowest = tile_group->tiles[i].number;
290 /* For a run, the difference between the highest and lowest tiles
291 * will always be one less than the number of tiles in the
292 * group. If not then we know it's not a run.
294 if (highest - lowest != tile_group->num_tiles - 1)
299 /* XXX: There's a bug here. We're guessing that at this point
300 * anything we're looking at must be a run. This would be correct
301 * if there were no duplicate tiles, but since there are
302 * duplicates this us quite broken. For example consider two
303 * sequences of entirely red tiles:
305 * This is a run: 1, 2, 3, 4
306 * But this is not: 1, 3, 4, 4
308 * As currently written, this function will consider both of these
309 * groups to be a run. One possible fix is to throw away the
310 * highest - lowest heuristic and instead simply sort the tiles up
311 * front and ensure the difference between each adjacent pair is
317 static int tile_group_is_set(tile_group_t *tile_group)
320 color_t seen_color[4];
321 for (i = 0; i < 4; i++)
324 if (tile_group->num_tiles > 4 || tile_group->num_tiles < 3)
326 printf("fail set - invalid num tiles; ");
329 for (i = 0; i <= tile_group->num_tiles - 1; ++i)
331 if (tile_group->tiles[i].number != tile_group->tiles[i + 1].number &&
332 i+1 != tile_group->num_tiles)
334 printf("fail set - numbers don't match; ");
337 seen_color[tile_group->tiles[i].color] += 1;
339 for (i = 0; i < 4; i++)
341 if (seen_color[i] > 1)
343 printf("fail set - repeat color; ");
350 static void deck_deal(game_t *game, deck_t *deck)
356 printf ("How many players(1-4) should I deal in? ");
357 game->num_players = getchar();
358 if (game->num_players == EOF)
360 printf ("\nGoodbye.\n");
364 game->num_players -= '0';
366 for (i = 0; i < game->num_players; ++i)
368 for (j = 0; j < 14; ++j)
370 rand_tile = ((deck->num_tiles + 1.0) * rand()) / (RAND_MAX + 1.0);
371 temp = deck->tiles[rand_tile];
372 deck->tiles[rand_tile] = deck->tiles[deck->num_tiles - 1];
373 game->players[i].hand.tiles[j] = temp;
374 game->players[i].hand.tiles[j].owned = 1;
375 deck->num_tiles -= 1;
376 game->players[i].hand.num_tiles += 1;
379 printf ("Game dealt for %d player(s)\n", game->num_players);
382 static void deck_init(deck_t *deck)
386 for (h = 0; h <= 1; ++h)
388 for (i = 0; i <= 3; ++i)
390 for (j = 0; j <= 12; ++j)
392 tile_init (&deck->tiles[deck->num_tiles++], i, j);
393 printf ("There are %d tiles in the deck\n", deck->num_tiles);
399 static void deck_shuffle(deck_t *deck)
404 for (last = deck->num_tiles; last > 0; --last)
406 rand_tile = ((last + 1.0) * rand()) / (RAND_MAX + 1.0);
407 temp = deck->tiles[rand_tile];
408 deck->tiles[rand_tile] = deck->tiles[last - 1];
409 deck->tiles[last - 1] = temp;
413 static void deck_print(deck_t *deck)
416 for (h = 0; h < 2; ++h)
418 for (i = 0; i < 4; ++i)
420 for (j = 0; j < 13; ++j)
422 tile_print(deck->tiles[j + (i * 13) + (h * 52)]);
426 printf ("There are %d tiles in the deck\n" , deck->num_tiles);
429 static void deck_spread(deck_t *deck)
432 for (i = 0; i < 8; i++)
434 for (j = 0; j < 13; j++)
436 deck->tiles[j + (i * 13)].x = j * 50;
437 deck->tiles[j + (i * 13)].y = i * 60;
442 static void deck_draw(game_t *game, cairo_t *cr, GdkRegion *region)
445 for (i = 0; i < game->deck.num_tiles; i++)
447 tile_draw(game, &game->deck.tiles[i], cr, region);
451 static void hand_print(game_t *game, int player)
454 for (i = 0; i < game->players[player].hand.num_tiles; i++)
456 tile_print(game->players[player].hand.tiles[i]);
460 static void hand_draw(game_t *game, int player, cairo_t *cr, GdkRegion *region)
463 int gwdw = GAME_WINDOW_DEFAULT_WIDTH;
464 int gwdh = GAME_WINDOW_DEFAULT_HEIGHT;
465 for (i = 0; i < game->players[player].hand.num_tiles; i++)
467 tile_set_x_y(&game->players[player].hand.tiles[i],
468 ((gwdw / game->players[player].hand.num_tiles)) * i,
469 (gwdh - TILE_HEIGHT - 6) );
471 for (i = 0; i < game->players[player].hand.num_tiles; i++)
473 tile_draw(game, &game->players[player].hand.tiles[i], cr, region);
477 static void game_init(game_t *game)
480 GError *error = NULL;
482 game->num_players = 0;
484 for (i = 0; i < GAME_MAX_PLAYERS; ++i)
486 player_init(&game->players[i]);
487 game->num_players += 1;
490 selection_box_init(&game->selection_box);
491 board_init(&game->board);
492 deck_init(&game->deck);
493 deck_shuffle(&game->deck);
495 game->selectedtile = rsvg_handle_new_from_file ("tiles/selected_tile.svg", &error);
497 FATAL_ERROR (error->message);
499 game->ownedtile = rsvg_handle_new_from_file ("tiles/owned_tile.svg", &error);
501 FATAL_ERROR (error->message);
503 game->blanktile = rsvg_handle_new_from_file ("tiles/blank_tile.svg", &error);
505 FATAL_ERROR (error->message);
507 // game->current_tile = game->deck.num_tiles - 1;
508 game->current_tile = &game->deck.tiles[0];
509 game->select_mode = 1;
510 game->drag_group_mode = 0;
512 game->diff_x = game->diff_y = 0;
515 static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, game_t *game)
519 cr = gdk_cairo_create (widget->window);
521 deck_draw(game, cr, event->region);
523 if (game->selection_box.visible)
524 selection_box_draw(&game->selection_box, cr);
526 hand_draw(game, 0, cr, event->region);
533 static gboolean on_key_press_event (GtkWidget *widget, GdkEventKey *event, game_t *game)
535 printf ("You pressed key %d\n", event->keyval);
536 if (event->keyval == 65505 || event->keyval == 65506)
537 game->drag_group_mode = 1;
542 static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event, game_t *game)
544 int i, tile_x, tile_y;
546 player_t *curr_player = &game->players[0];
548 /*Handle tiles in player's hand */
549 for (i = 0; i < curr_player->hand.num_tiles; i++)
551 curr_tile = &curr_player->hand.tiles[i];
552 if (curr_tile->selected)
554 curr_tile->selected = 0;
555 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
557 tile_x = curr_player->hand.tiles[i].x;
558 tile_y = curr_player->hand.tiles[i].y;
559 if (event->x >= tile_x && event->x <= (tile_x + TILE_WIDTH) &&
560 event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) )
562 game->select_mode = 0;
564 game->current_tile = curr_tile;
566 if (!curr_tile->selected)
567 curr_tile->selected = 1;
569 curr_tile->selected = 0;
570 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
572 game->diff_x = event->x - tile_x;
573 game->diff_y = event->y - tile_y;
577 /*Handle tiles in deck */
578 for (i = 0; i < game->deck.num_tiles; i++)
580 curr_tile = &game->deck.tiles[i];
581 if (curr_tile->selected)
583 curr_tile->selected = 0;
584 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
587 tile_x = game->deck.tiles[i].x;
588 tile_y = game->deck.tiles[i].y;
589 if (event->x >= tile_x && event->x <= (tile_x + TILE_WIDTH) &&
590 event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) )
592 game->select_mode = 0;
594 // game->current_tile = i;
595 game->current_tile = curr_tile;
597 //delete_this? curr_tile = &game->deck.tiles[game->current_tile];
598 if (!curr_tile->selected)
599 curr_tile->selected = 1;
601 curr_tile->selected = 0;
602 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
604 game->diff_x = event->x - tile_x;
605 game->diff_y = event->y - tile_y;
608 if (game->select_mode)
610 // game->deck.tiles[game->current_tile].selected = 0;
611 game->current_tile->selected = 0;
612 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
614 game->selection_box.visible = 1;
615 /*These next two lines appear to be dead
616 game->click_x = event->x;
617 game->click_y = event->y;*/
619 game->selection_box.x1 = event->x;
620 game->selection_box.x2 = event->x;
621 game->selection_box.y1 = event->y;
622 game->selection_box.y2 = event->y;
627 static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *event, game_t *game)
629 if (game->select_mode)
631 game->select_mode = 0;
632 selection_box_t *box;
633 box = &game->selection_box;
635 int x_min = MIN(box->x1, box->x2);
636 int x_max = MAX(box->x1, box->x2);
637 int y_min = MIN(box->y1, box->y2);
638 int y_max = MAX(box->y1, box->y2);
639 int width = abs(box->x2 - box->x1);
640 int height = abs(box->y2 - box->y1);
643 gtk_widget_queue_draw_area (widget, x_min, y_min, width, height);
645 // tile_group_t group;
646 // group.num_tiles = 0;
648 tile_t* group[TILE_GROUP_MAX_TILES];
651 int i, tile_x, tile_y, tile_x2, tile_y2;
652 for (i = 0; i < game->deck.num_tiles; i++)
654 tile_x = game->deck.tiles[i].x;
655 tile_y = game->deck.tiles[i].y;
656 tile_x2 = tile_x + TILE_WIDTH;
657 tile_y2 = tile_y + TILE_HEIGHT;
658 if (/*If top-left corner*/
659 (tile_x >= x_min && tile_x <= x_max &&
660 tile_y >= y_min && tile_y <= y_max) ||
661 /*or bottom-right corner*/
662 (tile_x2 >= x_min && tile_x2 <= x_max &&
663 tile_y2 >= y_min && tile_y2 <= y_max) ||
664 /*or bottom-left corner*/
665 (tile_x >= x_min && tile_x <= x_max &&
666 tile_y2 >= y_min && tile_y2 <= y_max) ||
667 /*or top-right corner of tile selected*/
668 (tile_x2 >= x_min && tile_x2 <= x_max &&
669 tile_y >= y_min && tile_y <= y_max) ||
671 (y_min >= tile_y && y_min <= tile_y2 &&
672 x_min <= tile_x && x_max >= tile_x) ||
674 (x_min >= tile_x && x_min <= tile_x2 &&
675 y_min <= tile_y && y_max >= tile_y) ||
677 (y_min >= tile_y && y_min <= tile_y2 &&
678 x_min >= tile_x && x_min <= tile_x2) ||
680 (x_min >= tile_x && x_min <= tile_x2 &&
681 y_min >= tile_y && y_min <= tile_y) )
683 // group.tiles[group.num_tiles] = game->deck.tiles[i];
684 // group.num_tiles++;
686 group[num_tiles] = &game->deck.tiles[i];;
690 //printf("is run %d\n", tile_group_is_run_one(&group) );
691 //printf("is set %d\n", tile_group_is_set(&group) );
693 // int matching_y = y_min;
695 // for (i = 0; i < group.num_tiles; i++)
696 for (i = 0; i < num_tiles; i++)
698 // tile_print(group.tiles[i]);
699 gtk_widget_queue_draw_area (widget, group[i]->x - 1 , group[i]->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
700 group[i]->x = x_min + (i * (TILE_WIDTH));
702 gtk_widget_queue_draw_area (widget, group[i]->x - 1 , group[i]->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
706 for (i = 0; i < group.num_tiles; i++)
708 for (j = 0; j < game->deck.num_tiles; j++)
710 if (group.tiles[i].x == game->deck.tiles[j].x &&
711 group.tiles[i].y == game->deck.tiles[j].y)
713 new_x = x_min + (i * (TILE_WIDTH));
714 gtk_widget_queue_draw_area (widget, game->deck.tiles[j].x - 1 , game->deck.tiles[j].y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
715 game->deck.tiles[j].x = new_x;
716 game->deck.tiles[j].y = matching_y;
717 gtk_widget_queue_draw_area (widget, new_x - 1 , matching_y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
722 game->select_mode = 1;
727 static gboolean on_button_motion_event (GtkWidget *widget, GdkEventMotion *event,
728 game_t *game, cairo_t *cr)
730 if (game->select_mode)
732 selection_box_t *box;
733 box = &game->selection_box;
736 int x_min = MIN(box->x1, box->x2);
737 int x_max = MAX(box->x1, box->x2);
738 int y_min = MIN(box->y1, box->y2);
739 int y_max = MAX(box->y1, box->y2);
740 int width = abs(box->x2 - box->x1);
741 int height = abs(box->y2 - box->y1);
743 gtk_widget_queue_draw_area ( widget, x_min, y_min, width, height );
748 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) );
750 int i, tile_x, tile_y, tile_x2, tile_y2;
752 for (i = 0; i < game->deck.num_tiles; i++)
754 curr_tile = &game->deck.tiles[i];
755 if (curr_tile->selected)
757 curr_tile->selected = 0;
758 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
761 tile_x = game->deck.tiles[i].x;
762 tile_y = game->deck.tiles[i].y;
763 tile_x2 = tile_x + TILE_WIDTH;
764 tile_y2 = tile_y + TILE_HEIGHT;
765 if (/*If top-left corner*/
766 (tile_x >= x_min && tile_x <= x_max &&
767 tile_y >= y_min && tile_y <= y_max) ||
768 /*or bottom-right corner*/
769 (tile_x2 >= x_min && tile_x2 <= x_max &&
770 tile_y2 >= y_min && tile_y2 <= y_max) ||
771 /*or bottom-left corner*/
772 (tile_x >= x_min && tile_x <= x_max &&
773 tile_y2 >= y_min && tile_y2 <= y_max) ||
774 /*or top-right corner of tile selected*/
775 (tile_x2 >= x_min && tile_x2 <= x_max &&
776 tile_y >= y_min && tile_y <= y_max) ||
778 (y_min >= tile_y && y_min <= tile_y2 &&
779 x_min <= tile_x && x_max >= tile_x) ||
781 (x_min >= tile_x && x_min <= tile_x2 &&
782 y_min <= tile_y && y_max >= tile_y) ||
784 (y_min >= tile_y && y_min <= tile_y2 &&
785 x_min >= tile_x && x_min <= tile_x2) ||
787 (x_min >= tile_x && x_min <= tile_x2 &&
788 y_min >= tile_y && y_min <= tile_y) )
790 curr_tile->selected = 1;
791 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
796 curr_tile->selected = 0;
797 gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
803 if (game->drag_group_mode)
809 // tile = &game->deck.tiles[game->current_tile];
810 tile = game->current_tile;
812 /* First, invalidate the region where the tile currently is. */
813 gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
815 /* Then, move the tile */
816 tile->x = event->x - game->diff_x;
817 tile->y = event->y - game->diff_y;
819 /* Finally, invalidate the region where the tile is now. */
820 gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
825 int main(int argc, char *argv[])
832 gtk_init (&argc, &argv);
835 deck_print(&game.deck);
836 deck_spread(&game.deck);
837 deck_deal(&game, &game.deck);
838 //hand_print(&game, 0); //With Zero being passed, will print hand for player 1(players[0])
839 //deck_print(&game.deck);
841 /* Create a new window */
842 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
843 gtk_window_set_default_size (GTK_WINDOW (window),
844 GAME_WINDOW_DEFAULT_WIDTH,
845 GAME_WINDOW_DEFAULT_HEIGHT);
847 gtk_widget_set_events (window,
850 GDK_BUTTON_MOTION_MASK |
851 GDK_BUTTON_PRESS_MASK |
852 GDK_BUTTON_RELEASE_MASK);
854 g_signal_connect (G_OBJECT (window), "delete_event",
855 G_CALLBACK (gtk_main_quit), NULL);
856 g_signal_connect (G_OBJECT (window), "expose_event",
857 G_CALLBACK (on_expose_event), &game);
858 g_signal_connect (G_OBJECT (window), "key_press_event",
859 G_CALLBACK (on_key_press_event), &game);
860 g_signal_connect (G_OBJECT (window), "button_press_event",
861 G_CALLBACK (on_button_press_event), &game);
862 g_signal_connect (G_OBJECT (window), "button_release_event",
863 G_CALLBACK (on_button_release_event), &game);
864 g_signal_connect (G_OBJECT (window), "motion_notify_event",
865 G_CALLBACK (on_button_motion_event), &game);
868 gtk_widget_show_all (window);