Commit df12700b authored by 9731077's avatar 9731077

First police of java fifnished

parent 7b284a5f
package PACKAGE_NAME; import java.util.ArrayList;
import java.util.Random;
//string to
public class Field { public class Field {
private int m, n;
private String[][] fieldShape;
ArrayList<Police> polices;
ArrayList<Robber> robberPosotion;
public Field(int m, int n) {
polices = new ArrayList<>();
robberPosotion = new ArrayList<>();
this.m = m;
this.n = n;
fieldShape = new String[m][n];
}
public int getM() {
return m;
}
public void setM(int m) {
this.m = m;
}
public int getN() {
return n;
}
public void setN(int n) {
this.n = n;
}
public void setFirstPlaceOfPolice(int policeNum) {
int tmpX, tmpY, cnt = 0;
Random randomGenerator = new Random();
for (int i = 0; i < policeNum; i++) {
tmpX = randomGenerator.nextInt(m);
tmpY = randomGenerator.nextInt(n);
if (polices.size() == 0) {
Police p = new Police(tmpX, tmpY);
fieldShape[tmpX][tmpY] = "P";
polices.add(p);
System.out.println("First police created");
}
else {
for (Police police : polices) {
if (police.getX() == tmpX && police.getY() == tmpY) {
i--;
cnt++;
break;
}
}
if (cnt == 0){
Police p = new Police(tmpX, tmpY);
fieldShape[tmpX][tmpY] = "P";
polices.add(p);
System.out.println(i + "th police created");
}
}
}
}
} }
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