sokoban.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. enum {
  2. /* levels */
  3. Empty = 0,
  4. Background,
  5. Wall,
  6. Cargo,
  7. Goal,
  8. GoalCargo,
  9. Glenda,
  10. /* movements */
  11. Up,
  12. Down,
  13. Left,
  14. Right,
  15. };
  16. enum {
  17. /* glenda faces the horizontal direction she's moving in */
  18. GLeft = 0,
  19. GRight = 1,
  20. };
  21. enum {
  22. MazeX = 20,
  23. MazeY = 18,
  24. BoardX = 49,
  25. BoardY = 49,
  26. SizeX = MazeX*BoardX+10,
  27. SizeY = MazeY*BoardY+10,
  28. Maxlevels = 200,
  29. };
  30. typedef struct {
  31. uint dir; /* direction */
  32. uint count; /* number of single-step moves */
  33. } Step;
  34. typedef struct {
  35. uint nstep; /* number of valid steps */
  36. Step *step;
  37. uint beyond; /* number of allocated Step */
  38. } Route;
  39. typedef struct {
  40. uint board[MazeX][MazeY];
  41. } Visited;
  42. typedef struct {
  43. Point glenda;
  44. Point max; /* that's how much the board spans */
  45. uint index;
  46. uint done;
  47. uint board[MazeX][MazeY];
  48. } Level;
  49. Level level; /* the current level */
  50. Level levels[Maxlevels]; /* all levels from this file */
  51. int numlevels; /* how many levels do we have */
  52. int animate; /* boolean: animate during multi-step move? */
  53. Image *img; /* buffer */
  54. Image *text; /* for text messages */
  55. Image *win;
  56. Image *goal;
  57. Image *cargo;
  58. Image *goalcargo;
  59. Image *wall;
  60. Image *empty;
  61. Image *gleft;
  62. Image *gright;
  63. Image *glenda;
  64. Image *bg;
  65. /* graphics.c */
  66. void drawscreen(void);
  67. void drawlevel(void);
  68. void drawwin(void);
  69. void drawglenda(void);
  70. void drawboard(Point);
  71. void resize(Point);
  72. Point boardsize(Point);
  73. /* level.c */
  74. int loadlevels(char *);
  75. /* move.c */
  76. void move(int);
  77. /* route.c */
  78. Route* newroute(void);
  79. void freeroute(Route*);
  80. void reverseroute(Route*);
  81. void pushstep(Route*, int, int);
  82. void popstep(Route*);
  83. int validwalk(Point, Step, Point*);
  84. int validpush(Point, Step, Point*);
  85. int isvalid(Point, Route*, int (*)(Point, Step, Point*));
  86. int findwalk(Point, Point, Route*);
  87. void applyroute(Route*);
  88. /* sokoban.c */
  89. char *genlevels(int);
  90. Image *eallocimage(Rectangle, int, uint);