Commit 94ee5d71 authored by 9611046's avatar 9611046

Documentation

parent f23ef9a7
/**
* A 2D land where the thief and the police are located in
*/
public class Land {
private int length;
private int width;
private char[][] landMatrix;
/**
* Constructor
* @param length specifies length of this land
* @param width specifies width of this land
*/
public Land(int length, int width) {
this.length = length;
this.width = width;
landMatrix = new char[length][width];
}
/**
* @return length of length
*/
public int getLength() {
return length;
}
/**
* @return width of length
*/
public int getWidth() {
return width;
}
/**
* Sets an element of this 2D array land
* @param x is the x coordinate of element
* @param y is the y coordinate of element
* @param c is the substitute value of the element
*/
public void setLandMatrix(int x, int y, char c){
if(x>=0 && x<width && y>=0 && y<length) {
landMatrix[x][y] = c;
}
}
/**
* @return value of 2D array land in x , y coordinate
*/
public char getLandMatrix(int x,int y) {
return landMatrix[x][y];
}
......
......@@ -2,6 +2,11 @@ import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
/**
* A simple simulation game of the pursuit of the thief and the police
* @auter Newsha Shahbodaghkhan
* @version 1.0
*/
public class Main {
public static void main(String[] args) throws InterruptedException {
......
import java.util.Random;
/**
* A class for identifying both police and thief moves
*/
public class Move {
private int x;
private int y;
......@@ -7,11 +10,26 @@ public class Move {
private int z;
private Land moveLand;
/**
* A constructor for random move of police and thief move
* @param x is x coordinate of police or thief
* @param y is the y coordinate of police or thief
* @param land is the current land of game
*/
public Move(int x,int y,Land land){
this.x = x;
this.y = y;
moveLand = land;
}
/**
* A constructor for smart move of police and thief move
*@param x is x coordinate of police
* @param y is the y coordinate of police
* @param w is the x coordinate of thief
* @param z is the y coordinate of thief
* @param land is the current land of game
*/
public Move(int x,int y,int w,int z,Land land){
this.x = x;
this.y = y;
......@@ -19,7 +37,10 @@ public class Move {
this.z = z;
moveLand = land;
}
//Random Move
/**
* Simulates random move of police and thief
*/
public void moveXY(){
Random rand = new Random();
int a = rand.nextInt(8);
......@@ -100,8 +121,12 @@ public class Move {
}
}
/**
* Simulates smart move
*/
public void smartMove(){
// Random random = new Random();
//This is the smart move of police and thief x,y are PoliceX, PoliceY and w, z are thiefX, thiefY
if(x>w ){
if(y>z){
......
/**
* Simulates police coordinate an move
*/
public class Police {
private Land policeLand;
......@@ -8,21 +11,36 @@ public class Police {
private boolean notify = false;
private boolean thiefCatch = false;
/**
* Sets first place of police
* @param x is x coordinate
* @param y is y coordinate
*/
public void setFirstxy(int x, int y) {
this.x = x;
this.y = y;
}
/**
* random move and then again setting new coordinate
*/
public void move() {
Move move1 = new Move(x,y,policeLand);
move1.moveXY();
this.x = move1.getX();
this.y = move1.getY();
}
/**
* Smart move of thief
* @param w is the thief x coordinate
* @param z is the thief y coordinate
*/
public void smartMove(int w,int z) {
// this.w = x;
// this.z = z;
Move move1 = new Move(x,y,w,z,policeLand);
move1.smartMove();
this.x = move1.getX();
......@@ -31,32 +49,58 @@ public class Police {
}
/**
* @param myLand current land
*/
public void setLand(Land myLand) {
policeLand = myLand;
}
/**
* @return x coordinate of police
*/
public int getX() {
return x;
}
/**
*
* @return y coordinate of police
*/
public int getY() {
return y;
}
/**
* @return true if police notified thief place
*/
public boolean getNotify() {
return notify;
}
/**
* @param notify sets field notify true if boolean notify is true
*/
public void setNotify(boolean notify) {
this.notify = notify;
}
/**
*
* @param thiefCatch sets field thiefCatch true if boolean thiefCatch is true
*/
public void SetThiefCatch(boolean thiefCatch){
this.thiefCatch = thiefCatch;
}
/**
*
* @return current situation of thiefCatch returns true if police took the thief
*/
public boolean getThiefCatch(){
return thiefCatch;
}
......
import java.util.Random;
/**
* Simulates thief coordinate an move
*/
public class Thief {
private Land thiefLand;
......@@ -7,23 +9,45 @@ public class Thief {
private int y ;
/**
* @return x coordinate of thief
*/
public int getX(){
return x;
}
/**
*
* @return y coordinate of thief
*/
public int getY(){
return y;
}
/**
*
* @param myLand current land
*/
public void setLand(Land myLand) {
thiefLand = myLand;
}
/**
* Sets first place of thief
* @param x is x coordinate
* @param y is y coordinate
*/
public void setFirstxy(int x,int y) {
this.x = x;
this.y = y;
// this.x = rand.nextInt(thiefLand.getLength());
// y = rand.nextInt(thiefLand.getLength());
}
/**
* random move and then again setting new coordinate
*/
public void move() {
Move move1 = new Move(x,y,thiefLand);
move1.moveXY();
......@@ -31,9 +55,14 @@ public class Thief {
this.y = move1.getY();
}
/**
* Smart move of thief
* @param w is the police x coordinate
* @param z is the police y coordinate
*/
public void smartMove(int w,int z) {
// this.w = x;
// this.z = z;
Move move1 = new Move(w,z,x,y,thiefLand);
move1.smartMove();
this.x = move1.getW();
......
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