public boolean toForward(){ Cell cell = getRotateCell(0, 0); // ← 1 boolean pass = cell.getF()!=1; // ← 2 if(pass){ switch(direction){// ← 3 case NORTH: posY++; break; case EAST: posX++; break; case SOUTH: posY--; break; case WEST: posX--; break; } displayFieldMsg = true; // ← 4 } return pass;// ← 5 }
private final static int FIELD_MSG = 5;
private boolean displayFieldMsg = true;
public String message() {
if(msgArray==null)return null;
Cell cell = rotatePosCell(0, 0);
int type = cell.getBit4(4); // ← 1
if(type == 0)return null; // ← 2
String msg = null;
if(type == direction+1) { // ← 3
//doorMsg
int msgNo = cell.getBit4(5);
msg = msgArray[msgNo];
}else if(type == FIELD_MSG) { // ← 4
//FieldMsg
if(displayFieldMsg) { // ← 5
int msgNo = cell.getBit4(5); // ← 6
msg = msgArray[msgNo]; // ← 7
displayFieldMsg = false; // ← 8
}
}
return msg;
}
private final static int ACTION_UP = 6; private final static int ACTION_DOWN= 7; private boolean displayFieldMsg = true; public boolean action() { Cell cell = rotatePosCell(0, 0); int type = cell.getBit4(4); // ← 1 switch(type){ case 0: // ← 2 return false; case ACTION_DOWN: // ← 3 if(displayFieldMsg) { // ← 4 // ↓ 5 Boolean yn = Scan.getBoolean("上り階段があります。 昇りますか?(Y/N): "); if(yn) { down(); // ← 6 } displayFieldMsg = false; return true; } break; case ACTION_UP: // ← 7 if(displayFieldMsg) { // ← 8 // ↓ 9 Boolean yn = Scan.getBoolean("下り階段があります。 降りますか?(Y/N): "); if(yn) { up(); // ← 10 } displayFieldMsg = false; return true; } break; } return false; } private void up() { ++floor; } private void down() { --floor; }