int boats[9] = {1, 1, 1, 1, 2, 2, 3, 4, 0};
char *help =
- "<d> Rotate shirp\n"
- "<i> Move up element\n"
- "<j> Move left element\n"
- "<k> Move down element\n"
- "<l> Move right element\n"
- "<p> Put ship or bomb\n"
+ "<d> Rotate ship\n"
+ "<i> Move up\n"
+ "<j> Move left\n"
+ "<k> Move down\n"
+ "<l> Move right\n"
+ "<p> Put ship/bomb\n"
"<q> Quit\n"
- "<t> Toggle case legend\n"
+ "<t> Toggle legend\n"
;
/* help message */
case KEY_UP:
case 'i':
if (length > 0) {
- if (testlocation (boardhuman, length, x, y - 1, orient, " ")) {
- y--;
+ int t;
+ for (t = y - 1; t >= 0; t--) {
+ if (testlocation (boardhuman, length, x, t, orient, " ")) {
+ y = t;
+ break;
+ }
}
} else {
- if (testlocation (boardcomputer, 1, x, y - 1, orient, " S")) {
- y--;
+ int t;
+ for (t = y - 1; t >= 0; t--) {
+ if (testlocation (boardcomputer, 1, x, t, orient, " S")) {
+ y = t;
+ break;
+ }
}
}
break;
case KEY_LEFT:
case 'j':
if (length > 0) {
- if (testlocation (boardhuman, length, x - 1, y, orient, " ")) {
- x--;
+ int t;
+ for (t = x - 1; t >= 0; t--) {
+ if (testlocation (boardhuman, length, t, y, orient, " ")) {
+ x = t;
+ break;
+ }
}
} else {
- if (testlocation (boardcomputer, 1, x - 1, y, orient, " S")) {
- x--;
+ int t;
+ for (t = y - 1; t >= 0; t--) {
+ if (testlocation (boardcomputer, 1, t, y, orient, " S")) {
+ x = t;
+ break;
+ }
}
}
break;
case KEY_DOWN:
case 'k':
if (length > 0) {
- if (testlocation (boardhuman, length, x, y + 1, orient, " ")) {
- y++;
+ int t;
+ for (t = y + 1; t < ysize; t++) {
+ if (testlocation (boardhuman, length, x, t, orient, " ")) {
+ y = t;
+ break;
+ }
}
} else {
- if (testlocation (boardcomputer, 1, x, y + 1, orient, " S")) {
- y++;
+ int t;
+ for (t = y + 1; t < ysize; t++) {
+ if (testlocation (boardcomputer, 1, x, t, orient, " S")) {
+ y = t;
+ break;
+ }
}
}
break;
case KEY_RIGHT:
case 'l':
if (length > 0) {
- if (testlocation (boardhuman, length, x + 1, y, orient, " ")) {
- x++;
+ int t;
+ for (t = x + 1; t < xsize; t++) {
+ if (testlocation (boardhuman, length, t, y, orient, " ")) {
+ x = t;
+ break;
+ }
}
} else {
- if (testlocation (boardcomputer, 1, x + 1, y, orient, " S")) {
- x++;
+ int t;
+ for (t = x + 1; t < xsize; t++) {
+ if (testlocation (boardcomputer, 1, t, y, orient, " S")) {
+ x = t;
+ break;
+ }
}
}
break;