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;
//string to
public class Field {
private int m, n;
private String[][] fieldShape;
ArrayList<Police> polices;
ArrayList<Robber> robberPosotion;
private int m;
private int n;
private ArrayList<Police> polices = new ArrayList<Police>();
private Robber Robber;
public String[][] fieldShape;
public Field(int m, int n) {
polices = new ArrayList<>();
robberPosotion = new ArrayList<>();
this.m = m;
this.n = 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() {
......@@ -43,8 +45,7 @@ public class Field {
fieldShape[tmpX][tmpY] = "P";
polices.add(p);
System.out.println("First police created");
}
else {
} else {
for (Police police : polices) {
if (police.getX() == tmpX && police.getY() == tmpY) {
i--;
......@@ -52,20 +53,19 @@ public class Field {
break;
}
}
if (cnt == 0){
if (cnt == 0) {
Police p = new Police(tmpX, tmpY);
fieldShape[tmpX][tmpY] = "P";
polices.add(p);
System.out.println(i + "th police created");
}
}
}
}
public void setFirstPlaceOfRobber(){
public void setFirstPlaceOfRobber() {
int tmpX, tmpY, cnt = 0;
while (true){
while (true) {
Random randomGenerator = new Random();
tmpX = randomGenerator.nextInt(m);
tmpY = randomGenerator.nextInt(n);
......@@ -75,12 +75,41 @@ public class Field {
break;
}
}
if (cnt == 0){
Robber robber = new Robber();
if (cnt == 0) {
Robber Robber = new Robber();
fieldShape[tmpX][tmpY] = "-";
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