public Status clockWise() { // 如果走到了路的尽头 if (this.target == '!') { returnnull; }
// 顺时针寻找目标 inti= position; intstep=0; do { if (i == ring.length()) { i -= ring.length(); } if (ring.charAt(i) == this.target) { returnnewStatus(this.steps + step + 1, i, index + 1); } i++; step++; } while (i != position); thrownewRuntimeException("404 Not found"); }
public Status counterClockWise() { // 如果走到了路的尽头 if (this.target == '!') { returnnull; }
// 逆时针寻找目标 inti= position; intstep=0; do { if (i == -1) { i += ring.length(); } if (ring.charAt(i) == this.target) { returnnewStatus(this.steps + step + 1, i, index + 1); } i--; step++; } while (i != position); thrownewRuntimeException("404 Not found"); }