Skip to content

Commit

Permalink
loggerfree check
Browse files Browse the repository at this point in the history
  • Loading branch information
siqq committed Sep 6, 2014
1 parent 4c8706e commit 5bc1a38
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 206 deletions.
20 changes: 10 additions & 10 deletions Java-Missle/src/launcher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

public class Launcher extends Thread {

public static final int MIN_REVEAL = 1;
public static final int MAX_REVEAL = 5;
public static final int MIN_REVEAL = 1;
public static final int MAX_REVEAL = 5;

private static Logger logger;

private String id;
private boolean isHidden;
private boolean isRunning;
private Vector<Missile> missiles;
private FileHandler fileHandler;
private List<WarEventListener> allListeners;
private static Logger logger;

private String id;
private boolean isHidden;
private boolean isRunning;
private Vector<Missile> missiles;
private FileHandler fileHandler;
private List<WarEventListener> allListeners;

/**
* Constructor
* @param id
Expand Down
157 changes: 7 additions & 150 deletions Java-Missle/src/main/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
import war.controller.WarController;

public class Program {
public static final String LAUNCHER = "launcher";
public static final String MISSILE = "missile";
public static final int TAKES_TIME_MIN = 1;
public static final int TAKES_TIME_MAX = 10;
public static final String LAUNCHER = "launcher";
public static final String MISSILE = "missile";
public static final int TAKES_TIME_MIN = 1;
public static final int TAKES_TIME_MAX = 10;


private static Logger logger = Logger.getLogger("warLogger");
private static Scanner input = new Scanner(System.in);
private static Logger logger = Logger.getLogger("warLogger");
private static Scanner input = new Scanner(System.in);

public static void main(String[] args) {

Expand Down Expand Up @@ -88,19 +87,7 @@ public void run() {
option = input.nextInt();
input.nextLine();
System.out.println();
switch (option) {
case 1:
addNewDestructor(war);
break;
case 2:
addNewLauncher(war);
break;
case 3:
launchMissile(war);
break;
case 4:
destructLauncher(war);
break;
switch (option) {
case 5:
destructMissile(war);
break;
Expand Down Expand Up @@ -153,136 +140,6 @@ private static void checkEndOfWar(War war) {
}
}

/**
* Add new Destructor (Iron Dome/Plane/Ship)
*
* @param war
* @throws InputMismatchException
* @throws SecurityException
* @throws IOException
*/
private static void addNewDestructor(War war) throws InputMismatchException,
SecurityException, IOException, Exception {
System.out.print("Please Insert Id: ");
String id = input.nextLine();
if (id.isEmpty()) {
throw new Exception("Id cant be empty");
}
System.out.print("Please Insert Type(Plane/Ship/Iron Dome) : ");
String type = input.nextLine();
if (WarUtility.getDestructorById(id, war, type) != null) {
throw new Exception("Id already exist!");
}
if (type.equals("Plane") || type.equals("Ship")) {
Destructor desctructor = new Destructor(
id, type, new Vector<AbstractMissile>());
war.addLauncherDestructor(desctructor);
} else if (type.equals("Iron Dome")) {
Destructor desctructor = new Destructor(
id, type, new Vector<AbstractMissile>());
war.addMissileDestructor(desctructor);
} else {
throw new Exception("Type must be Plane/Ship/Iron Dome\n");
}
}

/**
* add new launcher to war
*
* @param war
* @throws Exception
*/
private static void addNewLauncher(War war) throws Exception {
System.out.print("Please Insert Id: ");
String id = input.nextLine();
if ((id.isEmpty()) || (WarUtility.getLauncherById(id, war) != null)) {
throw new Exception("This Id is empty or already exist");
}
boolean is_hidden = (Math.round(Math.random()) == 1) ? true : false;
war.addLauncher(new Launcher(id, is_hidden , war.getListeners()));
}

/**
* search for launcher and add missile to it from user's input
*
* @param war
* @throws Exception
*/
private static void launchMissile(War war) throws Exception {
// choose a launcher from launcher list
System.out.println("Choose launcher "
+ "from the following Launchers list:");
Vector<Launcher> launchers = war.getMissileLaunchers();
if (launchers.size() == 0) {
throw new Exception("no launchers...first insert launcher");
}
printLaunchers(launchers);

System.out.print("\nEnter your Choise: ");
String launcher_id = input.nextLine();
// find selected launcher so we can add missile to it
Launcher selected_launcher = WarUtility.getLauncherById(launcher_id,
war);
if (selected_launcher == null) {
throw new Exception("Launcher does not exist");
}
// now create new missile from user input
System.out.print("Please insert Missile id: ");
String missile_id = input.nextLine();
if ((missile_id.isEmpty()) || (WarUtility.getMissileById(missile_id, war) != null)) {
throw new Exception("This Id is empty or already exist");
}
System.out.print("Please insert your destination: ");
String destination = input.nextLine();
System.out.print("Please insert potential damage: ");
int damage = input.nextInt();
int fly_time = (int) (TAKES_TIME_MIN + (Math.random() *
(TAKES_TIME_MAX - TAKES_TIME_MIN + 1))) * 10;
selected_launcher.addMissile(missile_id, destination, 0, fly_time, damage);
}

/**
* choose a destructor and select a launcher to destruct
*
* @param war
* @throws Exception
*/
private static void destructLauncher(War war) throws Exception {
// first pick a destructor
System.out.println("Choose destructor "
+ "from the following Destructors list:");

Vector<Destructor> destructors = war.getMissileLauncherDestructors();
printDestructors(destructors);

System.out.print("\nEnter your Choise: ");
String destructor_id = input.nextLine();
Destructor selected_destructor =
WarUtility.getDestructorById(destructor_id, war, LAUNCHER);
if (selected_destructor == null) {
throw new Exception("Destructor does not exist");
}
// now choose it's target
System.out.println("Choose a launcher to destruct "
+ "from the following launchers list:");
Vector<Launcher> launchers = war.getMissileLaunchers();
printLaunchers(launchers);

System.out.print("\nEnter your Choise: ");
String target_id = input.nextLine();
Launcher target = WarUtility.getLauncherById(target_id, war);
if (target == null) {
throw new Exception("Target does not exist");
}
int destruct_time = (int) (TAKES_TIME_MIN + (Math.random() *
(TAKES_TIME_MAX - TAKES_TIME_MIN + 1)));
// assign destructor to destruct the launcher
DestructedLanucher assigned_destructor = new DestructedLanucher(target, destruct_time,
selected_destructor, selected_destructor.getFileHandler() , war.getListeners());

selected_destructor.addDestructMissile(assigned_destructor);
}

/**
* choose a destructor and select a missile to destruct
* @param war
Expand Down
2 changes: 1 addition & 1 deletion Java-Missle/src/main/XMLparser.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class XMLparser {
private Vector<Launcher> missileLaunchers = new Vector<>();
private Vector<Destructor> missileDestructors = new Vector<>();
private Vector<Destructor> missileLauncherDestructors = new Vector<>();
WarController controller;
private WarController controller;

public XMLparser(WarController controller) throws ParserConfigurationException, SAXException,
IOException {
Expand Down
8 changes: 4 additions & 4 deletions Java-Missle/src/missile/DestructedLanucher.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

public class DestructedLanucher extends AbstractMissile {

private static Logger logger;
private static Logger logger;

private Launcher target;
private Destructor destructor;
private List<WarEventListener> allListeners;
private Launcher target;
private Destructor destructor;
private List<WarEventListener> allListeners;

/**
* Constructor
Expand Down
9 changes: 3 additions & 6 deletions Java-Missle/src/missile/DestructedMissile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import war.controller.WarEventListener;

public class DestructedMissile extends AbstractMissile {
private static Logger logger;
private static Logger logger;

private Missile target;
private Destructor destructor;
private List<WarEventListener> allListeners;

private Missile target;
private Destructor destructor;

/**
* Constructor
Expand All @@ -27,7 +25,6 @@ public DestructedMissile(Missile target, int destructAfterLaunch,
this.target = target;
this.destructor = destructor;
logger = Logger.getLogger("warLogger");
this.allListeners = allListeners;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions Java-Missle/src/missile/Missile.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

public class Missile extends AbstractMissile {

public enum Status {Waiting, Launched, Destroyed, Hit};
private List<WarEventListener> allListeners;
private static Logger logger;

private String missileId;
private String destination;
private int flyTime;
private int damage;
private Launcher launcher;
private Status status;
public enum Status {Waiting, Launched, Destroyed, Hit};
private static Logger logger;

private List<WarEventListener> allListeners;
private String missileId;
private String destination;
private int flyTime;
private int damage;
private Launcher launcher;
private Status status;


/**
Expand Down
2 changes: 1 addition & 1 deletion Java-Missle/src/view/ProgressPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ else if (type == "destructor"){
progressBar.setValue(time);
System.out.println(time);
JLabel temp = (JLabel)progressBar.getComponent(0);
temp.setText(destination +" Will Hit Launcher #"+ missileId + " in " + (flyTime - time) +"s");
temp.setText(destination +" Will Hit Launcher #"+ missileId + " in " + (flyTime - time) +"s");

}

Expand Down
25 changes: 12 additions & 13 deletions Java-Missle/src/war/War.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@
*/

public class War extends Thread {

public static final int TIME_INTERVAL = 1000; //sleep time for threads
public static final double SUCCESS_RATE = 0.2; //success rate for destructors
public static final String LAUNCHER = "launcher";
public static final String MISSILE = "missile";
public static final int TAKES_TIME_MIN = 1;
public static final int TAKES_TIME_MAX = 10;

private static Logger logger;

private Vector<Launcher> missileLaunchers = new Vector<>();
private Vector<Destructor> missileDestructors = new Vector<>();
private Vector<Destructor> missileLauncherDestructors = new Vector<>();
public static final int TIME_INTERVAL = 1000; //sleep time for threads
public static final double SUCCESS_RATE = 0.2; //success rate for destructors
public static final String LAUNCHER = "launcher";
public static final String MISSILE = "missile";
public static final int TAKES_TIME_MIN = 1;
public static final int TAKES_TIME_MAX = 10;

private static Logger logger;

private Vector<Launcher> missileLaunchers = new Vector<>();
private Vector<Destructor> missileDestructors = new Vector<>();
private Vector<Destructor> missileLauncherDestructors = new Vector<>();
private Vector<WarEventListener> listeners;

/**
Expand Down
13 changes: 11 additions & 2 deletions Java-Missle/src/war/controller/AbstractWarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@

public interface AbstractWarView {
void registerListener(WarUIEventsListener listener);

void addLauncherToUI(String id);

void addDestructorToUI(Destructor destructor);

void addLauncherDestructorToUI(String destructorId, String type);

void addMissileDestructorToModelEvenet(String destructorId, String type);

void addMissileToUI(String missileId, String destination, int damage,
int flyTime);

void destroyMissileProgress(String missileId, String type);

void addDestroyerProgress(String destructor_id, String target_id,
int destruct_time);
int destruct_time);

void removeLauncherFromView(String launcherId);

void updateMissileProgress(int time, String missileId, String type,
String destination, int damage, int flyTime);

}
2 changes: 1 addition & 1 deletion Java-Missle/src/war/controller/WarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import war.War;

public class WarController implements WarUIEventsListener,WarEventListener {
private War warModel;
private War warModel;
private AbstractWarView warView;

public WarController(War model, AbstractWarView view) {
Expand Down
14 changes: 12 additions & 2 deletions Java-Missle/src/war/controller/WarEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
public interface WarEventListener {

void addDestructorToModel(String id, String type);

void addLauncherToModel(String id);

void addedLauncherToModelEvent(String launcherId);

void addedLuncherDestructorToModelEvent(String destructorId, String type);

void addedMissileDestructorToModelEvent(String destructorId, String type);

void addedMissileToModelEvent(String missileId, String destination,
int damage, int flyTime);
void addedLauncherToDestroy(String destructor_id, String target_id, int destruct_time);
int damage, int flyTime);

void addedLauncherToDestroy(String destructor_id, String target_id,
int destruct_time);

void DestroyMissileProgressBar(String missileId, String string);

void RemovedLauncherFromUI(String launcherId);

void UpdatedMissileProgressToModelEvent(int time, String missileId,
String string, String destination, int damage, int flyTime);

Expand Down
Loading

0 comments on commit 5bc1a38

Please sign in to comment.