40 lines
1,013 B
C
40 lines
1,013 B
C
|
int attempt_move(int x, int y, int units, int direction) {
|
||
|
int xfuture = x;
|
||
|
int yfuture = y;
|
||
|
switch (direction) {
|
||
|
case 0: // right
|
||
|
xfuture = xfuture + units;
|
||
|
if (readmap(xfuture, y) == '&') {
|
||
|
return 0;
|
||
|
}
|
||
|
else {
|
||
|
return 1;
|
||
|
}
|
||
|
case 1: // up
|
||
|
yfuture = yfuture - units; // we subtract because moving up
|
||
|
if (readmap(x, yfuture) == '&') {
|
||
|
return 0;
|
||
|
}
|
||
|
else {
|
||
|
return 1;
|
||
|
}
|
||
|
case 2: // left
|
||
|
xfuture = xfuture - units;
|
||
|
if (readmap(xfuture, y) == '&') {
|
||
|
return 0;
|
||
|
}
|
||
|
else {
|
||
|
return 1;
|
||
|
}
|
||
|
case 3: // down
|
||
|
yfuture = yfuture + units;
|
||
|
if (readmap(x, yfuture) == '&') {
|
||
|
return 0;
|
||
|
}
|
||
|
else {
|
||
|
return 1;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|