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