Commit d4850a88 authored by 9611046's avatar 9611046

Main changes

parent 92929a35
...@@ -4,20 +4,164 @@ import java.util.Scanner; ...@@ -4,20 +4,164 @@ import java.util.Scanner;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) throws InterruptedException {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt(); int length = scanner.nextInt();
int width = scanner.nextInt(); int width = scanner.nextInt();
int arrestX =56;
int arrestY =56 ;
Land myLand = new Land(length, width); Land myLand = new Land(length, width);
Random rand = new Random();
// police.setLand(myLand);
int policeNumbers = scanner.nextInt(); int policeNumbers = scanner.nextInt();
ArrayList<Police> polices = new ArrayList<Police>(policeNumbers); ArrayList<Police> polices = new ArrayList<>(policeNumbers);
for (int i = 0; i < polices.size(); i++) { int[][] policePlace;
polices.get(i).setLand(myLand); policePlace = new int[2][policeNumbers];
int[][] thiefPlace = new int[2][1];
for (int i = 0; i < policeNumbers; i++) {
Police police = new Police();
polices.add(police);
}
for (Police value : polices) {
value.setLand(myLand);
} }
Thief thief = new Thief(); Thief thief = new Thief();
thief.setLand(myLand); thief.setLand(myLand);
thiefPlace[0][0] = rand.nextInt(myLand.getLength());
thiefPlace[1][0] = rand.nextInt(myLand.getWidth());
thief.setFirstxy(thiefPlace[0][0], thiefPlace[1][0]);
for (int i = 0; i < policeNumbers; i++) {
policePlace[0][i] = rand.nextInt(myLand.getLength());
policePlace[1][i] = rand.nextInt(myLand.getWidth());
if (policePlace[0][i] != thiefPlace[0][0] && policePlace[1][i] != thiefPlace[1][0]) {
polices.get(i).setFirstxy(policePlace[0][i], policePlace[1][i]);
} else {
policePlace[0][i] = rand.nextInt(myLand.getLength());
policePlace[1][i] = rand.nextInt(myLand.getWidth());
if (policePlace[0][i] != thiefPlace[0][0] && policePlace[1][i] != thiefPlace[1][0]) {
polices.get(i).setFirstxy(policePlace[0][i], policePlace[1][i]);
}
}
}
// while (!polices.get(0).getNotify()) {
do {
for (int i = 0; i < myLand.getLength(); i++) {
for (int j = 0; j < myLand.getWidth(); j++) {
myLand.setLandMatrix(i, j, '-');
}
}
for (Police police : polices) myLand.setLandMatrix(police.getX(), police.getY(), 'P');
myLand.setLandMatrix(thief.getX(), thief.getY(), 'D');
for (int i = 0; i < myLand.getLength(); i++) {
for (int j = 0; j < myLand.getWidth(); j++) {
System.out.print(myLand.getLandMatrix(i, j));
}
System.out.println();
}
Thread.sleep(1000);
System.out.println();
thief.move();
for (Police police : polices) {
police.move();
}
for (Police police : polices) {
if ((Math.abs(police.getX() - thief.getX()) <= 2) && (Math.abs(police.getY() - thief.getY()) <= 2)) {
for (Police value : polices) {
value.setNotify(true);
}
break;
}
}
} while (!polices.get(0).getNotify());
System.out.println(
"The thief is observed!!!!!!!!!!!!" +
"Here is my exiting chase!!!!!!!!!!!");
// Printing land after notifying
// Move smartMove = new
//moving polices after notifying
do {
for (int i = 0; i < myLand.getLength(); i++) {
for (int j = 0; j < myLand.getWidth(); j++) {
myLand.setLandMatrix(i, j, '-');
}
}
for (Police police : polices) myLand.setLandMatrix(police.getX(), police.getY(), 'P');
myLand.setLandMatrix(thief.getX(), thief.getY(), 'D');
for (int i = 0; i < myLand.getLength(); i++) {
for (int j = 0; j < myLand.getWidth(); j++) {
System.out.print(myLand.getLandMatrix(i, j));
}
System.out.println();
}
Thread.sleep(2000);
System.out.println();
thief.smartMove(polices.get(0).getX(), polices.get(0).getY());
for (Police police : polices) {
police.smartMove(thief.getX(), thief.getY());
}
for (Police police : polices) {
if (police.getX() == thief.getX() && police.getY() == thief.getY()) {
arrestX = thief.getX();
arrestY = thief.getY();
for (Police value : polices) {
value.SetThiefCatch(true);
}
break;
}
}
} while (!polices.get(0).getThiefCatch());
for (int i = 0; i < myLand.getLength(); i++) {
for (int j = 0; j < myLand.getWidth(); j++) {
myLand.setLandMatrix(i, j, '-');
}
}
myLand.setLandMatrix(arrestX,arrestY,'*');
for (int i = 0; i < myLand.getLength(); i++) {
for (int j = 0; j < myLand.getWidth(); j++) {
System.out.print(myLand.getLandMatrix(i, j));
}
System.out.println();
}
} }
} }
\ No newline at end of file
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