Commit ff9f1406 authored by hosein's avatar hosein

playground -> change | void added!

parent 8e79b040
...@@ -2,11 +2,12 @@ import java.util.Random; ...@@ -2,11 +2,12 @@ import java.util.Random;
public class PlayGround { public class PlayGround {
private int[][] ground; private int[][] ground;
int n, m; int n, m, policeNumbers;
PlayGround(int n, int m) { PlayGround(int n, int m, int policeNumbers) {
this.n = n; this.n = n;
this.m = m; this.m = m;
this.policeNumbers = policeNumbers;
ground = new int[n][m]; ground = new int[n][m];
int i, j; int i, j;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
...@@ -29,11 +30,11 @@ public class PlayGround { ...@@ -29,11 +30,11 @@ public class PlayGround {
} }
} }
public void putRandom(int policeNumber) { public void putRandom() {
int i, j, k; int i, j, k;
Random rand = new Random(); Random rand = new Random();
if (n * m > policeNumber) if (n * m > policeNumbers)
for (k = 0; k < policeNumber; k++) { for (k = 0; k < policeNumbers; k++) {
i = rand.nextInt(); i = rand.nextInt();
j = rand.nextInt(); j = rand.nextInt();
if (ground[i][j] == 0) if (ground[i][j] == 0)
...@@ -43,5 +44,16 @@ public class PlayGround { ...@@ -43,5 +44,16 @@ public class PlayGround {
else System.out.println("Error!! police numbers are higher than n*m"); else System.out.println("Error!! police numbers are higher than n*m");
} }
public void change(int[][] newPolicesSituation, int xThief, int yThief) {
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
ground[i][j] = 0;
for (i = 0; i < policeNumbers; i++)
ground[newPolicesSituation[i][0]][newPolicesSituation[i][1]] = 1;
ground[xThief][yThief] = -1;
}
} }
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