Skip to content

Commit

Permalink
Client - server -> only launchers work
Browse files Browse the repository at this point in the history
  • Loading branch information
GalKarp committed Oct 9, 2014
1 parent 470dc19 commit d7ac525
Show file tree
Hide file tree
Showing 31 changed files with 727 additions and 422 deletions.
6 changes: 5 additions & 1 deletion Java-Missle/src/launcher/Destructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import missile.DestructedLanucher;
import missile.DestructedMissile;

public class Destructor extends Thread{
public class Destructor extends Thread {

/**
*
*/

private static Logger logger;

Expand Down
36 changes: 27 additions & 9 deletions Java-Missle/src/launcher/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package launcher;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.Vector;
import java.util.logging.FileHandler;
import java.util.logging.Logger;

import war.controller.WarEventListener;
import logger.LogFormatter;
import logger.ObjectFilter;
import missile.Missile;
import war.controller.WarEventListener;

public class Launcher extends Thread {
public class Launcher extends Thread implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
public static final int MIN_REVEAL = 1;
public static final int MAX_REVEAL = 5;

Expand All @@ -21,8 +26,9 @@ public class Launcher extends Thread {
private boolean isHidden;
private boolean isRunning;
private Vector<Missile> missiles;
private FileHandler fileHandler;
private List<WarEventListener> allListeners;
private transient FileHandler fileHandler;
private transient List<WarEventListener> allListeners;
//why listeners in launcher?

/**
* Constructor
Expand Down Expand Up @@ -62,7 +68,7 @@ public Launcher(String id, boolean isHidden ,List<WarEventListener> allListeners
this.isHidden = isHidden;
this.missiles = new Vector<Missile>();
this.isRunning = true;
this.allListeners = allListeners;
this.allListeners = allListeners; //you never use this shit. delete it
fileHandler = new FileHandler("Launcher_" + this.id + ".txt", false);
fileHandler.setFilter(new ObjectFilter(this));
fileHandler.setFormatter(new LogFormatter());
Expand Down Expand Up @@ -135,15 +141,16 @@ public void addMissile(String id, String destination, int launchtime,
}
}
public Missile CreatWithoutAddMissile(String id, String destination, int launchtime,
String flytime, String damage) {
String flytime, String damage, Vector<WarEventListener> listeners) {
int flyTime = Integer.parseInt(flytime);
int daMage = Integer.parseInt(damage);
Missile missile = new Missile(id, destination, launchtime,
flyTime, daMage, this.fileHandler, this ,allListeners);
synchronized (this) {
this.notify();
}
return missile;
// synchronized (this) {
// this.notify();
// }

}

/**
Expand Down Expand Up @@ -184,4 +191,15 @@ public void run() {
catch (InterruptedException e) {
}
}

public void addMissile(Missile missile) {
this.missiles.add(missile);
for (WarEventListener l : allListeners) {
// l.addedLauncherToDestroy(destructor_id,target_id,destruct_time);
}
// synchronized (this) {
// this.notify();
// }

}
}
6 changes: 5 additions & 1 deletion Java-Missle/src/logger/LogFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import java.util.logging.LogRecord;


public class LogFormatter extends Formatter {
public class LogFormatter extends Formatter {

/**
*
*/

@Override
public String format(LogRecord record) {
Expand Down
3 changes: 3 additions & 0 deletions Java-Missle/src/logger/ObjectFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

public class ObjectFilter implements Filter {

/**
*
*/
private Vector<Object> objects = new Vector<Object>();

public ObjectFilter(Object toFilter) {
Expand Down
10 changes: 7 additions & 3 deletions Java-Missle/src/main/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import war.War;
import war.controller.AbstractWarView;
import war.controller.WarController;
import war.db.WarDBConnection;

public class Program {
/**
*
*/
public static final String LAUNCHER = "launcher";
public static final String MISSILE = "missile";
public static final int TAKES_TIME_MIN = 1;
Expand All @@ -29,11 +31,11 @@ public static void main(String[] args) {

try {
// War warModel = xml.readXML();
new WarDBConnection();
// new WarDBConnection();
// WarDBConnection.clearWarDataBase();
War warModel = new War();
AbstractWarView viewGui = new WarGui();
// new Server();
WarController controller = new WarController(warModel,viewGui);
XMLparser xml = new XMLparser(controller);

Expand Down Expand Up @@ -70,6 +72,8 @@ private static void checkEndOfWar(War war) {
}
}
}
//ok thats better
//you should really consider modifying the source. its fucking you up bigtime.
if (counter == size) {
/*String stats = displayStatistics(war);
logger.log(Level.INFO, "All launchers destroyed - end of war");
Expand Down
54 changes: 0 additions & 54 deletions Java-Missle/src/main/Server.java

This file was deleted.

12 changes: 10 additions & 2 deletions Java-Missle/src/missile/AbstractMissile.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package missile;
import java.io.Serializable;
import java.util.logging.FileHandler;

import logger.LogFormatter;
import logger.ObjectFilter;

public abstract class AbstractMissile extends Thread{
public abstract class AbstractMissile extends Thread implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private int delayBeforeLaunch;
private FileHandler fileHandler;
private transient FileHandler fileHandler;

public AbstractMissile(int delayBeforeLaunch,
FileHandler fileHandler) {
Expand Down
6 changes: 5 additions & 1 deletion Java-Missle/src/missile/DestructedLanucher.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import war.controller.WarEventListener;
import war.db.WarDBConnection;

public class DestructedLanucher extends AbstractMissile {
public class DestructedLanucher extends AbstractMissile {

/**
*
*/

private static Logger logger;

Expand Down
7 changes: 6 additions & 1 deletion Java-Missle/src/missile/DestructedMissile.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package missile;
import java.io.Serializable;
import java.util.List;
import java.util.logging.FileHandler;
import java.util.logging.Level;
Expand All @@ -10,7 +11,11 @@
import war.controller.WarEventListener;
import war.db.WarDBConnection;

public class DestructedMissile extends AbstractMissile {
public class DestructedMissile extends AbstractMissile implements Serializable {
/**
*
*/

private static Logger logger;

private Missile target;
Expand Down
23 changes: 19 additions & 4 deletions Java-Missle/src/missile/Missile.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package missile;
import java.io.Serializable;
import java.util.List;
import java.util.logging.FileHandler;
import java.util.logging.Level;
Expand All @@ -9,12 +10,18 @@
import war.controller.WarEventListener;
import war.db.WarDBConnection;

public class Missile extends AbstractMissile {
public class Missile extends AbstractMissile implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;


public enum Status {Waiting, Launched, Destroyed, Hit};
private static Logger logger;

private List<WarEventListener> allListeners;
private transient List<WarEventListener> allListeners;
private String missileId;
private String destination;
private int flyTime;
Expand Down Expand Up @@ -43,7 +50,11 @@ public Missile(String id, String destination, int launchTime, int flyTime,
this.launcher = launcher;
this.setStatus(Status.Waiting);
this.allListeners = allListeners;

// this is dumb implementation. // not mine , those things ha been taken from avishay and dvir
//still this is very problematic. try to add transient to every error. it tells the outputstream not to write that specific object
//Ok, ill try to eork on it, Thans Bro
//ill talk to you if there be anything else
//ok lets just launch last time
logger = Logger.getLogger("warLogger");
}

Expand Down Expand Up @@ -125,7 +136,11 @@ public void run() {
}
// notify();
logger.log(Level.INFO, print_log, this);

//each launcher had missile so every missile must have launcher
//why listener though?
//to add things to gui and backward -- mvc
//your implementation is wrong. when you add a launcher or a missile you should call the function in the controller with the parameters
//for example l.addedMissileToModelEvent(missileId,destination,damage,flyTime);
try {
for(int time = 0 ; time <= flyTime ; time++){
Thread.sleep(War.TIME_INTERVAL);
Expand Down
23 changes: 20 additions & 3 deletions Java-Missle/src/view/ConsoleApp.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
package view;

import java.util.List;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;
import war.controller.WarUIEventsListener;

public class ConsoleApp extends Application {
public class ConsoleApp extends Application {
private Stage primaryStage;
private Missiletab missiletab;
private Launchertab launcherTab;
private List<WarUIEventsListener> allListeners;
private String launcherId;


public ConsoleApp(
) {
this.allListeners = LaunchersPanel.getAllListeners();
this.launcherId = LaunchersPanel.getLauncherID();
// main(null);

}

public void start(Stage primaryStage) throws Exception {

final Tab tabMissile = new Tab();
Expand All @@ -19,8 +34,8 @@ public void start(Stage primaryStage) throws Exception {
TabPane tabPane = new TabPane();
tabPane.setId("mainPane");

missiletab = new Missiletab(this);
launcherTab = new Launchertab(this);
missiletab = new Missiletab(this , launcherId , allListeners);
launcherTab = new Launchertab(this , allListeners);

tabMissile.setContent(missiletab);
tabLauncher.setContent(launcherTab);
Expand All @@ -39,5 +54,7 @@ public static void main(String[] args) {
public Stage getPrimaryStage() {
return primaryStage;
}



}
Loading

0 comments on commit d7ac525

Please sign in to comment.