Commit a0959836 authored by 9731077's avatar 9731077

one method removed + add change field method

parent 71952f2f
...@@ -3,17 +3,19 @@ import java.util.Random; ...@@ -3,17 +3,19 @@ import java.util.Random;
//string to //string to
public class Field { public class Field {
private int m, n; private int m;
private String[][] fieldShape; private int n;
ArrayList<Police> polices; private ArrayList<Police> polices = new ArrayList<Police>();
ArrayList<Robber> robberPosotion; private Robber Robber;
public String[][] fieldShape;
public Field(int m, int n) { public Field(int m, int n) {
polices = new ArrayList<>();
robberPosotion = new ArrayList<>();
this.m = m; this.m = m;
this.n = n; this.n = n;
fieldShape = new String[m][n]; fieldShape = new String[m][n];
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
fieldShape[i][j] = "-";
} }
public int getM() { public int getM() {
...@@ -43,8 +45,7 @@ public class Field { ...@@ -43,8 +45,7 @@ public class Field {
fieldShape[tmpX][tmpY] = "P"; fieldShape[tmpX][tmpY] = "P";
polices.add(p); polices.add(p);
System.out.println("First police created"); System.out.println("First police created");
} } else {
else {
for (Police police : polices) { for (Police police : polices) {
if (police.getX() == tmpX && police.getY() == tmpY) { if (police.getX() == tmpX && police.getY() == tmpY) {
i--; i--;
...@@ -52,20 +53,19 @@ public class Field { ...@@ -52,20 +53,19 @@ public class Field {
break; break;
} }
} }
if (cnt == 0){ if (cnt == 0) {
Police p = new Police(tmpX, tmpY); Police p = new Police(tmpX, tmpY);
fieldShape[tmpX][tmpY] = "P"; fieldShape[tmpX][tmpY] = "P";
polices.add(p); polices.add(p);
System.out.println(i + "th police created");
} }
} }
} }
} }
public void setFirstPlaceOfRobber(){ public void setFirstPlaceOfRobber() {
int tmpX, tmpY, cnt = 0; int tmpX, tmpY, cnt = 0;
while (true){ while (true) {
Random randomGenerator = new Random(); Random randomGenerator = new Random();
tmpX = randomGenerator.nextInt(m); tmpX = randomGenerator.nextInt(m);
tmpY = randomGenerator.nextInt(n); tmpY = randomGenerator.nextInt(n);
...@@ -75,12 +75,41 @@ public class Field { ...@@ -75,12 +75,41 @@ public class Field {
break; break;
} }
} }
if (cnt == 0){ if (cnt == 0) {
Robber robber = new Robber(); Robber Robber = new Robber();
fieldShape[tmpX][tmpY] = "-"; fieldShape[tmpX][tmpY] = "-";
return; return;
} }
} }
} }
public void changeField() {
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
fieldShape[i][j] = "-";
fieldShape[Robber.getX()][Robber.getY()] = "D";
boolean b = false;
for (Police police : polices) {
if (fieldShape[police.getX()][police.getY()].equals("D")) {
b = true;
fieldShape[police.getX()][police.getY()] = "*";
}
if (fieldShape[police.getPreviosX()][police.getPreviosY()].equals("D")) {
b = true;
fieldShape[police.getX()][police.getY()] = "*";
}
if (!fieldShape[police.getX()][police.getY()].equals("*"))
fieldShape[police.getX()][police.getY()] = "P";
}
if (b == true) {
//show field
System.exit(0);
}
}
} }
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