Commit 684aca4e authored by hosein's avatar hosein

Police -> move | int[][] added!

parent 6ef69b22
public class Police {
private int x, y;
private static boolean see;
Police(int x , int y) {
this.x = x;
this.y = y;
see = false;
}
}
package mma;//package src;
import mma.PlayGround;
import mma.Police;
import mma.Thief;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("Enter n: ");
int n = input.nextInt();
System.out.print("Enter m: ");
int m = input.nextInt();
System.out.print("Enter police numbers: ");
int pn = input.nextInt();
PlayGround playGround = new PlayGround(n, m, pn);
int[][] positions = playGround.putRandom();
Thief thief = new Thief(positions[pn][0], positions[pn][1]);
Police[] polices = new Police[pn];
for (n = 0; n < pn; n++)
polices[n] = new Police(positions[n][0], positions[n][1]);
//--------------------------------------------------------------------------------
do {
playGround.policeSeeThief();
} while(!playGround.catchThief());
}
}
package mma;
import java.util.Random; import java.util.Random;
public class PlayGround { public class PlayGround {
private int[][] ground; private int[][] ground, thiefsituation;
int n, m, policeNumbers; int n, m, policeNumbers;
PlayGround(int n, int m, int policeNumbers) { PlayGround(int n, int m, int policeNumbers) {
...@@ -9,6 +11,7 @@ public class PlayGround { ...@@ -9,6 +11,7 @@ public class PlayGround {
this.m = m; this.m = m;
this.policeNumbers = policeNumbers; this.policeNumbers = policeNumbers;
ground = new int[n][m]; ground = new int[n][m];
thiefsituation = new int[1][1];
int i, j; int i, j;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
for (j = 0; j < m; j++) for (j = 0; j < m; j++)
...@@ -53,6 +56,8 @@ public class PlayGround { ...@@ -53,6 +56,8 @@ public class PlayGround {
ground[i][j] = 1; ground[i][j] = 1;
positions[policeNumbers][0] = i; // x positions[policeNumbers][0] = i; // x
positions[policeNumbers][1] = j; // y positions[policeNumbers][1] = j; // y
thiefsituation[0][0] = i; // x
thiefsituation[0][1] = j; // y
} }
} }
} }
...@@ -72,5 +77,40 @@ public class PlayGround { ...@@ -72,5 +77,40 @@ public class PlayGround {
ground[xThief][yThief] = -1; ground[xThief][yThief] = -1;
} }
public int[][] getGround() {
return ground;
}
public boolean policeSeeThief() {
int i, j, I, J;
if (thiefsituation[0][0] > 1) i = thiefsituation[0][0] - 2;
else i = 0;
if (thiefsituation[0][0] < n - 2) I = thiefsituation[0][0] + 3;
else I = n;
if (thiefsituation[0][1] > 1) j = thiefsituation[0][1] - 2;
else j = 0;
if (thiefsituation[0][1] < m - 2) J = thiefsituation[0][1] + 3;
else J = m;
for (; i < I; i++)
for (; j < J; j++)
if (ground[i][j] == -1)
return true;
return false;
}
public boolean catchThief() {
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (ground[i][j] == 100)
return true;
return false;
}
} }
package mma;
import java.util.Random;
public class Police {
private int x, y;
private static boolean see;
Police(int x, int y) {
this.x = x;
this.y = y;
see = false;
}
public int[][] move(int n, int m) {
boolean i, j, I, J;
i = j = I = J = false;
if (x != 0) i = true;
if (x != n - 1) I = true;
if (y != 0) j = true;
if (y != m - 1) J = true;
Random random = new Random();
int[][] Return = new int[1][1];
while (true) {
switch (random.nextInt() % 8) {
case 0:
if (i == true && j == true) {
Return[0][0] = x - 1; // x
Return[0][1] = y - 1; // y
return Return;
}
break;
case 1:
if (i == true) {
Return[0][0] = x - 1; // x
Return[0][1] = y; // y
return Return;
}
break;
case 2:
if (i == true && J == true) {
Return[0][0] = x + 1; // x
Return[0][1] = y - 1; // y
return Return;
}
break;
case 3:
if (i == true) {
Return[0][0] = x; // x
Return[0][1] = y - 1; // y
return Return;
}
break;
case 4:
if (J == true) {
Return[0][0] = x; // x
Return[0][1] = y + 1; // y
return Return;
}
break;
case 5:
if (i == true && J == true) {
Return[0][0] = x + 1; // x
Return[0][1] = y - 1; // y
return Return;
}
break;
case 6:
if (J == true) {
Return[0][0] = x + 1; // x
Return[0][1] = y; // y
return Return;
}
break;
case 7:
if (I == true && J == true) {
Return[0][0] = x + 1; // x
Return[0][1] = y + 1; // y
return Return;
}
}
}
}
public int[][] getSituation() {
int[][] Return = new int[1][1];
Return[0][0] = x;
Return[0][1] = y;
return Return;
}
}
\ No newline at end of file
public class Thief { public class Thief {
private int x, y; private int x, y;
private static boolean see; private boolean see;
Thief(int x, int y) { Thief(int x, int y) {
this.x = x; this.x = x;
......
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