Commit f23ef9a7 authored by 9611046's avatar 9611046

Completes the project

parent d4850a88
public class Land {
private int length;
private int width;
private int[][] landMatrix = new int[length][width];
private char[][] landMatrix;
public Land(int length, int width) {
this.length = length;
this.width = width;
landMatrix = new char[length][width];
}
public int getLength() {
......@@ -16,8 +18,14 @@ public class Land {
return width;
}
public int[][] getLandMatrix() {
return landMatrix;
public void setLandMatrix(int x, int y, char c){
if(x>=0 && x<width && y>=0 && y<length) {
landMatrix[x][y] = c;
}
}
public char getLandMatrix(int x,int y) {
return landMatrix[x][y];
}
}
......@@ -8,8 +8,10 @@ public class Main {
Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt();
int width = scanner.nextInt();
int arrestX =56;
int arrestY =56 ;
int arrestX =0;
int arrestY =0;
int policeMovment = 0;
int thiefMovement = 0;
Land myLand = new Land(length, width);
Random rand = new Random();
int policeNumbers = scanner.nextInt();
......@@ -78,8 +80,10 @@ public class Main {
thief.move();
thiefMovement++;
for (Police police : polices) {
police.move();
policeMovment++;
}
......@@ -127,8 +131,10 @@ System.out.println(
thief.smartMove(polices.get(0).getX(), polices.get(0).getY());
thiefMovement++;
for (Police police : polices) {
police.smartMove(thief.getX(), thief.getY());
policeMovment++;
}
......@@ -162,6 +168,10 @@ System.out.println(
System.out.println();
}
System.out.println("The number of police movements: "+policeMovment+"\n"+
"The number of thieves' moves: "+thiefMovement);
}
}
import java.util.Random;
public class Police {
Random rand = new Random();
Land policeLand;
private Land policeLand;
private int x;
private int y;
public void setFirstxy() {
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;
}
}
private boolean notify = false;
private boolean thiefCatch = false;
case 5:
//North west
if (y > 0) {
if (x > 0) {
y += 1;
x -= 1;
}
}
public void setFirstxy(int x, int y) {
case 6:
//Southeast
if (y + 1 < policeLand.getWidth()) {
if (x + 1 <= policeLand.getLength()) {
y += 1;
x += 1;
break;
}
this.x = x;
this.y = y;
}
case 7:
//Southwest
if (y + 1 < policeLand.getWidth()) {
if (x > 0) {
y += 1;
x -= 1;
break;
}
public void move() {
Move move1 = new Move(x,y,policeLand);
move1.moveXY();
this.x = move1.getX();
this.y = move1.getY();
}
public void smartMove(int w,int z) {
// this.w = x;
// this.z = z;
Move move1 = new Move(x,y,w,z,policeLand);
move1.smartMove();
this.x = move1.getX();
this.y = move1.getY();
}
}
public void setLand(Land myLand) {
policeLand = myLand;
}
......@@ -97,4 +45,19 @@ public class Police {
return y;
}
public boolean getNotify() {
return notify;
}
public void setNotify(boolean notify) {
this.notify = notify;
}
public void SetThiefCatch(boolean thiefCatch){
this.thiefCatch = thiefCatch;
}
public boolean getThiefCatch(){
return thiefCatch;
}
}
import java.util.Random;
public class Thief {
Land thiefLand;
Random rand = new Random();
private int firstx = rand.nextInt(thiefLand.getLength());
private int firsty = rand.nextInt(thiefLand.getLength());
private int x = firstx;
private int y = firsty;
private Land thiefLand;
private int x ;
private int y ;
public int getX(){
......@@ -19,4 +17,29 @@ public class Thief {
public void setLand(Land myLand) {
thiefLand = myLand;
}
public void setFirstxy(int x,int y) {
this.x = x;
this.y = y;
// this.x = rand.nextInt(thiefLand.getLength());
// y = rand.nextInt(thiefLand.getLength());
}
public void move() {
Move move1 = new Move(x,y,thiefLand);
move1.moveXY();
this.x = move1.getX();
this.y = move1.getY();
}
public void smartMove(int w,int z) {
// this.w = x;
// this.z = z;
Move move1 = new Move(w,z,x,y,thiefLand);
move1.smartMove();
this.x = move1.getW();
this.y = move1.getZ();
}
}
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