1 enum { 2 /* 3 * D[1-4], the seasons, appear only once 4 * F[1-4], the flowers, appear only once 5 * everything else appears 4 times 6 * for a total of 144 7 */ 8 A1 = 0, A2, A3, A4, A5, A6, A7, A8, A9, 9 B1, B2, B3, B4, B5, B6, B7, B8, B9, 10 C1, C2, C3, C4, C5, C6, C7, C8, C9, 11 D1, D2, D3, D4, E1, E2, E3, E4, 12 F1, F2, F3, F4, G1, G2, G3, 13 Seasons, 14 Flowers, 15 }; 16 17 enum { 18 /* level-specific enums */ 19 Tiles = 144, 20 Depth = 5, 21 TileDxy = 6, /* tile displacement when on a higher level */ 22 Lx = 32, 23 Ly = 16, 24 Bord = Depth*TileDxy, 25 }; 26 enum { 27 /* the size of a complete tile */ 28 Tilex = 60, 29 Tiley = 74, 30 31 /* only the face part */ 32 Facex = 54, 33 Facey = 68, 34 35 /* and the entire window, giving room for 5*6 = 30 pixels 36 * that are needed for the higher tiles 37 */ 38 Sizex = Lx*Facex/2 + 2*Bord, 39 Sizey = Ly*Facey/2 + 2*Bord, 40 }; 41 42 /* which part of a tile */ 43 typedef enum { 44 None, 45 TL, /* main brick */ 46 TR, 47 BR, 48 BL, 49 } Which; 50 51 typedef struct { 52 Point start; /* where is this brick in the tileset */ 53 int clicked; 54 Which which; 55 int type; 56 int redraw; 57 } Brick; 58 59 typedef struct { 60 int d; 61 int x; 62 int y; 63 } Click; 64 65 typedef struct { 66 Brick board[Depth][Lx][Ly]; /* grid of quarter tiles */ 67 Click c; /* player has a brick selected */ 68 Click l; /* mouse-over-brick indicator */ 69 int done; 70 Click hist[Tiles]; 71 int remaining; 72 } Level; 73 74 Level level; /* the level played */ 75 Level orig; /* same, sans modifications */ 76 77 Image *img; /* buffer */ 78 79 Image *background; 80 Image *brdr; 81 Image *gameover; 82 Image *litbrdr; 83 Image *mask; 84 Image *selected; 85 Image *textcol; 86 Image *tileset; 87 88 /* logic.c */ 89 Click Cl(int d, int x, int y); 90 Click NC; 91 Brick *bmatch(Click c); 92 int canmove(void); 93 Click cmatch(Click c, int dtop); 94 int eqcl(Click c1, Click c2); 95 int isfree(Click c); 96 97 /* graphics.c */ 98 void clearlevel(void); 99 void clicked(Point); 100 void deselect(void); 101 void done(void); 102 void drawlevel(void); 103 void hint(void); 104 void light(Point); 105 void resize(Point); 106 void undo(void); 107 108 /* mahjongg.c */ 109 Image *eallocimage(Rectangle, int, uint, uint); 110 char *genlevels(int); 111 112 /* level.c */ 113 void generate(uint seed); 114 int parse(char *); 115