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.

73 lines
1.4 KiB

#include "labyrinth.h"
#include "global.h"
#include "stdio.h"
#include "stdlib.h"
void turn_direction_right(Direction *direction){
switch (*direction) {
case N:
*direction = E;
break;
case E:
*direction = S;
break;
case S:
*direction = W;
break;
case W:
*direction = N;
break;
}
}
void lab_move(unsigned short *x, unsigned short *y, Direction direction){
if (direction == N){
*x = *x - 1;
return;
}
if (direction == E){
*y = *y + 1;
return;
}
if (direction == S){
*x = *x + 1;
return;
}
if (direction == W){
*y = *y - 1;
return;
}
}
void set_wall(Field_State** field, unsigned short x, unsigned short y) {
field[x][y] = WALL;
}
void init_field(Field_State** field, unsigned short len_x, unsigned short len_y){
for (int c_x = 0; c_x < len_x; c_x++){
for (int c_y = 0; c_y < len_y; c_y++){
field[c_x][c_y] = WAY;
}
}
}
short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Direction direction, unsigned short len_x, unsigned short len_y){
lab_move(&x, &y, direction);
if (x >= len_x){
return 1;
}
if (y >= len_y){
return 1;
}
if (field[x][y] == WALL){
return 1;
}
return 0;
}