You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.5 KiB

  1. #include "labyrinth.h"
  2. #include "global.h"
  3. #include "stdio.h"
  4. #include "stdlib.h"
  5. void turn_direction_right(Direction *direction){
  6. switch (*direction) {
  7. case N:
  8. *direction = E;
  9. break;
  10. case E:
  11. *direction = S;
  12. break;
  13. case S:
  14. *direction = W;
  15. break;
  16. case W:
  17. *direction = N;
  18. break;
  19. }
  20. }
  21. void lab_move(unsigned short *x, unsigned short *y, Direction direction){
  22. if (direction == N){
  23. *x = *x - 1;
  24. return;
  25. }
  26. if (direction == E){
  27. *y = *y + 1;
  28. return;
  29. }
  30. if (direction == S){
  31. *x = *x + 1;
  32. return;
  33. }
  34. if (direction == W){
  35. *y = *y - 1;
  36. return;
  37. }
  38. }
  39. void set_wall(Field_State** field, unsigned short x, unsigned short y) {
  40. field[x][y] = WALL;
  41. }
  42. void init_field(Field_State** field, unsigned short len_x, unsigned short len_y){
  43. for (int c_x = 0; c_x < len_x; c_x++){
  44. for (int c_y = 0; c_y < len_y; c_y++){
  45. field[c_x][c_y] = WAY;
  46. }
  47. }
  48. }
  49. short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Direction direction, unsigned short len_x, unsigned short len_y){
  50. lab_move(&x, &y, direction);
  51. if (x >= len_x){
  52. return 1;
  53. }
  54. if (y >= len_y){
  55. return 1;
  56. }
  57. if (direction == N && field[x][y] == WALL){
  58. return 1;
  59. }
  60. if (direction == E && field[x][y] == WALL){
  61. return 1;
  62. }
  63. return 0;
  64. }