/* * Gnome Set game - cards.h * Copyright 2007 Kirill Gorelov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef CARDS_H #define CARDS_H #ifdef HAVE_CONFIG_H #include #endif #include #include #include "gettext.h" #include "img.h" #define ICARDS_X 3 #define ICARDS_Y 27 #define NCARDS_X 5 /* cards in a row */ #define NCARDS_Y 3 /* cards in a column */ #define NCARDS_IN_A_PACK (NCARDS_X*NCARDS_Y) #define NCARDS_ACTIVE 3 /* * A card in the Set game has a variation of the following four features: * color, symbol, number and shading. */ /* Colors are red, green and purple */ enum { COLOR_UNDEF=-1, COLOR_RED = 0, COLOR_GREEN, COLOR_PURPLE, COLOR_MAX }; /* Each card contains ovals, squiggles, or diamonds. */ enum { SYM_UNDEF=-1, SYM_DIAMOND=0, SYM_OVAL, SYM_SQUIGGLE, SYM_MAX }; /* Each card has one, two, or three symbols. */ enum { NUM_UNDEF=-1, NUM_ONE=0, NUM_TWO, NUM_THREE, NUM_MAX }; /* Each card is solid, open, or striped. */ enum { SHAD_UNDEF=-1, SHAD_SOLID=0, SHAD_OPEN, SHAD_STRIPED, SHAD_MAX }; /* Card structure definition */ typedef struct _Card { gint color; gint symbol; gint number; gint shading; /* game desk variables */ gboolean selected; } Card; /* The card_image struct */ typedef struct _CardsImage { /* The image as loaded from file */ Img *image; /* The image resized to the current window size */ GdkPixbuf *pixbuf; /* width, height and ratio of a single card */ gint width; gint height; gdouble ratio; } CardsImage; /* */ typedef struct _CardsPack { gint ncards_x; gint ncards_y; gint left_margin; /* cards margins */ gint right_margin; gint top_margin; gint bottom_margin; gint spacing; /* spacing between cards on the table */ gint x1,y1; /* top left corner */ gint x2,y2; /* bottom right corner */ gint hint_flag; /* set after the hint */ gint nactive; /* current number of active cards */ Card* active_cards[NCARDS_ACTIVE]; Card* cards[NCARDS_X][NCARDS_Y]; /* cards currently on the table */ } CardsPack; typedef struct _CardsDeck { Card* cards[81]; gint ncards; } CardsDeck; /* Cards image related functions */ CardsImage* cards_image_new(void); CardsImage* cards_image_from_file(const gchar *file); void cards_image_render_to_pixmap(CardsImage *cards, Card* card, GdkPixmap *target, GdkGC *target_gc, gint x, gint y); void cards_image_set_size(CardsImage *cards, gint width, gint height); void cards_image_free(CardsImage *cards); /* Crads deck functions */ void cards_deck_init(CardsDeck *deck); Card* cards_deck_draw(CardsDeck *deck); gboolean cards_deck_is_empty(CardsDeck *deck); void cards_deck_cleanup(CardsDeck *deck); /* Cards Pack functions */ void cards_pack_init(CardsPack *pack, gint lmar, gint rmar, gint tmar, gint bmar, gint sp); gboolean cards_pack_resize(CardsPack *pack, gint cards_x, gint cards_y); void cards_pack_resize_cards(CardsPack *pack, CardsImage *cards, gint width, gint height); gboolean cards_pack_fill(CardsPack *pack, CardsDeck *deck); gboolean cards_pack_check_active(CardsPack *pack, CardsImage *cards, gint x, gint y); gboolean cards_pack_check_set(CardsPack *pack); void cards_pack_reset(CardsPack *pack); void cards_pack_remove_selected(CardsPack *pack); gboolean cards_pack_hint(CardsPack *pack); gboolean are_there_sets_left(CardsPack *pack); void cards_pack_render_to_pixmap(CardsPack *pack, CardsImage *cards, GdkPixmap *target, GdkGC *target_gc); /* External definitions */ extern CardsDeck card_deck; extern CardsPack card_pack; #endif