Commit 71952f2f authored by 9731077's avatar 9731077

robber move randomly aded

parent 070a564a
package PACKAGE_NAME; import java.util.*;
public class Robber { public class Robber {
private int x, y, moveNum;
public void setY(int y) {
this.y = y;
}
public void setX(int x) {
this.x = x;
}
public void setMoveNum(int moveNum) {
this.moveNum = moveNum;
}
public int getY() {
return y;
}
public int getX() {
return x;
}
public int getMoveNum() {
return moveNum;
}
public void moveRandomly(int length, int width) {
Random randomGenerator = new Random();
moveNum++;
if (x != 0 && x != length - 1 && y != 0 && y != width - 1) {
int rx = randomGenerator.nextInt(3) - 1;
int ry = randomGenerator.nextInt(3) - 1;
x = x + rx;
y = y + ry;
}
if (x == 0 && y != 0 && y != width - 1) {
int rx = randomGenerator.nextInt(2);
int ry = randomGenerator.nextInt(3) - 1;
x = x + rx;
y = y + ry;
}
if (y == 0 && x != 0 && x != length - 1) {
int rx = randomGenerator.nextInt(3) - 1;
int ry = randomGenerator.nextInt(2);
x = x + rx;
y = y + ry;
}
if (x == length - 1 && y != 0 && y != width - 1) {
int rx = randomGenerator.nextInt(2) - 1;
int ry = randomGenerator.nextInt(3) - 1;
x = x + rx;
y = y + ry;
}
if (y == width - 1 && x != 0 && x != length - 1) {
int rx = randomGenerator.nextInt(3) - 1;
int ry = randomGenerator.nextInt(2) - 1;
x = x + rx;
y = y + ry;
}
if (x == 0 && y == 0) {
int rx = randomGenerator.nextInt(2);
int ry = randomGenerator.nextInt(2);
x = x + rx;
y = y + ry;
}
if (x == length - 1 && y == 0) {
int rx = randomGenerator.nextInt(2) - 1;
int ry = randomGenerator.nextInt(2);
x = x + rx;
y = y + ry;
}
if (x == 0 && y == width - 1) {
int rx = randomGenerator.nextInt(2);
int ry = randomGenerator.nextInt(2) - 1;
x = x + rx;
y = y + ry;
}
if (x == length - 1 && y == width - 1) {
int rx = randomGenerator.nextInt(2) - 1;
int ry = randomGenerator.nextInt(2) - 1;
x = x + rx;
y = y + ry;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment