Commit 8dd280cc authored by 9611046's avatar 9611046

makes move function

parent 234fc831
...@@ -4,26 +4,96 @@ public class Police { ...@@ -4,26 +4,96 @@ public class Police {
Random rand = new Random(); Random rand = new Random();
Land policeLand; Land policeLand;
private int x;
private int y;
int firstx = rand.nextInt(policeLand.getLength()); public void setFirstxy() {
int firsty = rand.nextInt(policeLand.getLength()); x = rand.nextInt(policeLand.getLength());
y = rand.nextInt(policeLand.getLength());
}
public void move() {
int a = rand.nextInt(8);
switch (a) {
case 0:
//Right
if (x + 1 <= policeLand.getLength()) {
x += 1;
break;
}
case 1:
//Left
if (x > 0) {
x -= 1;
break;
}
case 2:
//Up
if (y > 0) {
y -= 1;
break;
}
case 3:
//Down
if (y + 1 < policeLand.getWidth()) {
y += 1;
}
case 4:
//North East
if (y > 0) {
if (x + 1 <= policeLand.getLength()) {
y += 1;
x += 1;
}
}
case 5:
//North west
if (y > 0) {
if (x > 0) {
y += 1;
x -= 1;
}
}
case 6:
//Southeast
if (y + 1 < policeLand.getWidth()) {
if (x + 1 <= policeLand.getLength()) {
y += 1;
x += 1;
break;
}
}
case 7:
//Southwest
private int x = firstx; if (y + 1 < policeLand.getWidth()) {
private int y = firsty; if (x > 0) {
y += 1;
x -= 1;
break;
public void move(){ }
}
}
int[][] availgitableRout =
} }
public void setLand(Land myLand) { public void setLand(Land myLand) {
policeLand = myLand; policeLand = myLand;
} }
public int getX(){
public int getX() {
return x; return x;
} }
public int getY(){
public int getY() {
return y; return y;
} }
......
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