mahjongg.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. enum {
  17. /* level-specific enums */
  18. Tiles = 144,
  19. Depth = 5,
  20. TileDxy = 6, /* tile displacement when on a higher level */
  21. Lx = 32,
  22. Ly = 16,
  23. Bord = Depth*TileDxy,
  24. };
  25. enum {
  26. /* the size of a complete tile */
  27. Tilex = 60,
  28. Tiley = 74,
  29. /* only the face part */
  30. Facex = 54,
  31. Facey = 68,
  32. /* and the entire window, giving room for 5*6 = 30 pixels
  33. * that are needed for the higher tiles
  34. */
  35. Sizex = Lx*Facex/2 + 2*Bord,
  36. Sizey = Ly*Facey/2 + 2*Bord,
  37. };
  38. /* which part of a tile */
  39. typedef enum {
  40. None,
  41. TL, /* main brick */
  42. TR,
  43. BR,
  44. BL,
  45. } Which;
  46. typedef struct {
  47. Point start; /* where is this brick in the tileset */
  48. int clicked;
  49. Which which;
  50. int type;
  51. int redraw;
  52. } Brick;
  53. typedef struct {
  54. int d;
  55. int x;
  56. int y;
  57. } Click;
  58. typedef struct {
  59. Brick board[Depth][Lx][Ly]; /* grid of quarter tiles */
  60. Click c; /* player has a brick selected */
  61. Click l; /* mouse-over-brick indicator */
  62. int done;
  63. Click hist[Tiles];
  64. int remaining;
  65. } Level;
  66. Level level; /* the level played */
  67. Level orig; /* same, sans modifications */
  68. Image *img; /* buffer */
  69. Image *background;
  70. Image *brdr;
  71. Image *gameover;
  72. Image *litbrdr;
  73. Image *mask;
  74. Image *selected;
  75. Image *textcol;
  76. Image *tileset;
  77. /* logic.c */
  78. Click Cl(int d, int x, int y);
  79. Click NC;
  80. Brick *bmatch(Click c);
  81. int canmove(void);
  82. Click cmatch(Click c, int dtop);
  83. int eqcl(Click c1, Click c2);
  84. int isfree(Click c);
  85. /* graphics.c */
  86. void clearlevel(void);
  87. void clicked(Point);
  88. void deselect(void);
  89. void done(void);
  90. void drawlevel(void);
  91. void hint(void);
  92. void light(Point);
  93. void resize(Point);
  94. void undo(void);
  95. /* mahjongg.c */
  96. Image *eallocimage(Rectangle, int, uint, uint);
  97. char *genlevels(int);
  98. /* level.c */
  99. void generate(uint seed);
  100. int parse(char *);