Commit 22d731ec authored by 9731077's avatar 9731077

finished

parent 95728c84
import java.util.ArrayList;
import java.util.Random;
import java.util.*;
import java.sql.SQLOutput;
//string to
public class Field {
private int m;
private int n;
private ArrayList<Police> polices = new ArrayList<Police>();
private Robber Robber;
private final int m;
private final int n;
public String[][] fieldShape;
private Robber robber;
private ArrayList<Police> polices = new ArrayList<Police>();
public Field(int m, int n) {
this.m = m;
......@@ -18,98 +18,107 @@ public class Field {
fieldShape[i][j] = "-";
}
public int getM() {
return m;
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) {
showFieldShape();
System.exit(0);
}
public void setM(int m) {
this.m = m;
}
public int getN() {
return n;
public void setRobber(Robber robber) {
this.robber = robber;
}
public void setN(int n) {
this.n = n;
public Robber getRobber() {
return robber;
}
public String[][] getCourt() {
return fieldShape;
}
public ArrayList<Police> getPolices() {
return polices;
}
public void setFirstPlaceOfPolice(int policeNum) {
int tmpX, tmpY, cnt = 0;
Random randomGenerator = new Random();
public void randomPolicePlace(int policeNum) {
Random random = 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 {
int x = random.nextInt(m);
int y = random.nextInt(n);
boolean bl = true;
if (polices.size() != 0) {
for (Police police : polices) {
if (police.getX() == tmpX && police.getY() == tmpY) {
if (police.getX() == x && police.getY() == y) {
i--;
cnt++;
bl = false;
break;
}
}
if (cnt == 0) {
Police p = new Police(tmpX, tmpY);
fieldShape[tmpX][tmpY] = "P";
polices.add(p);
}
}
if (bl == true) {
fieldShape[x][y] = "P";
Police p = new Police(x, y);
polices.add(p);
}
}
public void setFirstPlaceOfRobber() {
int tmpX, tmpY, cnt = 0;
}
public void randomRobberPlce() {
Random random = new Random();
while (true) {
Random randomGenerator = new Random();
tmpX = randomGenerator.nextInt(m);
tmpY = randomGenerator.nextInt(n);
int x = random.nextInt(m);
int y = random.nextInt(n);
boolean b = true;
for (Police police : polices) {
if (police.getX() == tmpX && police.getY() == tmpY) {
cnt++;
break;
if (police.getX() == x && police.getY() == y)
b = false;
}
}
if (cnt == 0) {
Robber Robber = new Robber();
fieldShape[tmpX][tmpY] = "-";
return;
if (b == true) {
robber = new Robber(x, y);
fieldShape[x][y] = "D";
break;
}
}
}
public void changeField() {
for (int i = 0; i < m; i++)
public void showFieldShape() {
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()] = "*";
System.out.print(fieldShape[i][j] + " | ");
System.out.println();
}
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