import java.io.*;
public class Simulation {
Prison prisonA;
Cell cellA;
public Guard guardA;
public Prisoner prisonerA;
¡@
public void init() {
int pWidth, pLength, exitX, exitY;
int maxContained, cellX, cellY;
int guardX, guardY, distanceGuarded;
boolean holdWeapon;
int intelligence, EQ, prisonerX, prisonerY;
String material, cagedMaterial;
// Creating prison. . .
pWidth = getInteger("Please enter width of prison: ");
pLength = getInteger("Please enter length of prison: ");
exitX = getInteger("Please enter X coordinate of the exit: ");
exitY = getInteger("Please enter Y coordinate of the exit: ");
Prison prisonA = new Prison(pWidth, pLength, exitX, exitY);
System.out.println("Prison created. . .");
¡@
// Creating cell. . .
maxContained = getInteger("Pleasse enter max number of prisoner in this cell: ");
material = getString("Please enter material of this cell: ");
cellX = getInteger("Please enter X coordinate of this cell: ");
cellY = getInteger("Please enter Y coordinate of this cell :");
Cell cellA = new Cell (maxContained, material, cellX, cellY);
System.out.println("Cell created. . .");
¡@
// Adding cell to the prison
prisonA.addCell(cellA);
System.out.println("CellA has been added to the prison.");
¡@
// Creating guard. . .
guardX = getInteger ("Please enter X coordinate of this guard: ");
guardY = getInteger ("Please enter Y coordinate of this guard: ");
switch (getInteger("Please specify if this guard held a weapon (0 or 1): ")) {
case 0: holdWeapon = false;
break;
case 1: holdWeapon = true;
break;
default: holdWeapon = true;
}
distanceGuarded = getInteger("Please enter the distance been guarded: ");
Guard guardA = new Guard(guardX, guardY, holdWeapon, distanceGuarded);
System.out.println("Guard created. . .");
¡@
// Adding guard to prison. . .
prisonA.addGuard(guardA);
¡@
// Creating prisoner. . .
intelligence = getInteger("Please enter intelligence of this prisoner (0 - 100): ");
EQ = getInteger("Please enter EQ of this prisoner (0 - 100): ");
cagedMaterial = material;
prisonerX = cellX;
¡@
prisonerY = cellY;
Prisoner prisonerA = new Prisoner(intelligence, EQ, cagedMaterial, prisonerX, prisonerY);
System.out.println("Prisoner created. . .");
¡@
// Adding prisoner to cell. . .
cellA.addPrisoner(prisonerA);
System.out.println("Prisoner has been added to the cell. . .");
¡@
System.out.println("Starting simulation. . .. . ");
int lappedPeriod=0;
while (lappedPeriod < 1) {
if (prisonerA.inCell)
prisonerA.tryEscapeCell();
else
prisonerA.tryEscapeAct();
¡@
if (guardA.detPrisonerOutsideCell()) {
if (!prisonerA.isDead) {
if (guardA.actionTaken())
prisonerA.isDead = true;
}
}
lappedPeriod++;
}
}
¡@
public void startSimulation(int period) {
¡@
int lappedPeriod=0;
¡@
//System.out.println(prisonerA.x);
//lappedPeriod=0; //System.out.println(abc);System.out.println(prisonerA.x);
while (lappedPeriod < period) {
System.out.println(prisonerA.x);
/*
if (prisonerA.inCell)
prisonerA.tryEscapeCell();
else
prisonerA.tryEscapeAct();
¡@
if (guardA.detPrisonerOutsideCell())
guardA.actionTaken();
*/
lappedPeriod++;
}
}
¡@
¡@
public String getString (String dispMsg) {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader keyb = new BufferedReader(isr);
¡@
System.out.println(dispMsg);
try {
return keyb.readLine();
} catch (IOException e) { }
return "";
}
¡@
private int getInteger (String dispMsg) {
return Integer.parseInt(getString(dispMsg));
/*int tempInt=0;
System.out.println(dispMsg);
try {
(int)System.in.read();
System.in.reset();
System.out.println(tempInt);
return tempInt;
} catch (IOException e) { }
return 0;*/
}