sokoban.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. enum {
  10. /* levels */
  11. Empty = 0,
  12. Background,
  13. Wall,
  14. Cargo,
  15. Goal,
  16. GoalCargo,
  17. Glenda,
  18. /* movements */
  19. Up,
  20. Down,
  21. Left,
  22. Right,
  23. };
  24. enum {
  25. /* glenda faces the horizontal direction she's moving in */
  26. GLeft = 0,
  27. GRight = 1,
  28. };
  29. enum {
  30. MazeX = 20,
  31. MazeY = 18,
  32. BoardX = 49,
  33. BoardY = 49,
  34. SizeX = MazeX*BoardX+10,
  35. SizeY = MazeY*BoardY+10,
  36. Maxlevels = 200,
  37. };
  38. typedef struct Step {
  39. uint dir; /* direction */
  40. uint count; /* number of single-step moves */
  41. } Step;
  42. typedef struct Route {
  43. uint nstep; /* number of valid Step */
  44. Step *step;
  45. Point dest; /* result of step */
  46. } Route;
  47. typedef struct Walk {
  48. uint nroute; /* number of valid Route* */
  49. Route **route;
  50. uint beyond; /* number of allocated Route* */
  51. } Walk;
  52. typedef struct Visited {
  53. uint board[MazeX][MazeY];
  54. } Visited;
  55. typedef struct Animation {
  56. Route* route;
  57. Step *step;
  58. int count;
  59. } Animation;
  60. typedef struct {
  61. Point glenda;
  62. Point max; /* that's how much the board spans */
  63. uint index;
  64. uint done;
  65. uint board[MazeX][MazeY];
  66. } Level;
  67. Level level; /* the current level */
  68. Level levels[Maxlevels]; /* all levels from this file */
  69. int numlevels; /* how many levels do we have */
  70. Image *img; /* buffer */
  71. Image *text; /* for text messages */
  72. Image *win;
  73. Image *goal;
  74. Image *cargo;
  75. Image *goalcargo;
  76. Image *wall;
  77. Image *empty;
  78. Image *gleft;
  79. Image *gright;
  80. Image *glenda;
  81. Image *bg;
  82. /* graphics.c */
  83. void drawscreen(void);
  84. void drawlevel(void);
  85. void drawwin(void);
  86. void drawglenda(void);
  87. void drawboard(Point);
  88. void resize(Point);
  89. Point boardsize(Point);
  90. /* level.c */
  91. int loadlevels(char *);
  92. /* move.c */
  93. void move(int);
  94. /* route.c */
  95. int validpush(Point, Step*, Point*);
  96. int isvalid(Point, Route*, int (*)(Point, Step*, Point*));
  97. void freeroute(Route*);
  98. Route* extend(Route*, int, int, Point);
  99. Route* findroute(Point, Point);
  100. /* animation.c */
  101. void initanimation(Animation*);
  102. void setupanimation(Animation*, Route*);
  103. int onestep(Animation*);
  104. void stopanimation(Animation*);
  105. /* sokoban.c */
  106. char *genlevels(int);
  107. Image *eallocimage(Rectangle, int, uint);