Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GalKarp committed Sep 6, 2014
1 parent 5bc1a38 commit f27d0f3
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 25 deletions.
7 changes: 5 additions & 2 deletions Java-Missle/src/missile/DestructedLanucher.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ public void run() {
for(int time = 0 ; time <= super.getDelayBeforeLaunch() ; time++){
Thread.sleep(War.TIME_INTERVAL);
for (WarEventListener l : allListeners) {
l.UpdatedMissileProgressToModelEvent(time, target.getLauncherId() , "destructor",(destructor.getType()+" #" + destructor.getDestructorId()),0,super.getDelayBeforeLaunch());
l.UpdatedMissileProgressToModelEvent(time, target.getLauncherId() , "launcherDestroyer",(destructor.getType()+" #" + destructor.getDestructorId()),0,super.getDelayBeforeLaunch());
}
}
for (WarEventListener l : allListeners) {
l.RemoveCurrentElement(target.getLauncherId());
}
for (WarEventListener l : allListeners) {
l.DestroyMissileProgressBar(target.getLauncherId() , "destructor");
l.RemovedLauncherFromUI(target.getLauncherId());
}

} catch (InterruptedException e) {
Expand Down
19 changes: 18 additions & 1 deletion Java-Missle/src/missile/DestructedMissile.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class DestructedMissile extends AbstractMissile {

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

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

Expand All @@ -34,7 +36,22 @@ public void run() {
Object arr[] = { this, target };
try {
// wait untill destroy after war launch
sleep(super.getDelayBeforeLaunch() * War.TIME_INTERVAL);
// sleep(super.getDelayBeforeLaunch() * War.TIME_INTERVAL);

for(int time = 0 ; time <= super.getDelayBeforeLaunch() ; time++){
Thread.sleep(War.TIME_INTERVAL);
for (WarEventListener l : allListeners) {
l.UpdatedMissileProgressToModelEvent(time, target.getMissileId() , "IronDome",(destructor.getType()+" #" + destructor.getDestructorId()),0,super.getDelayBeforeLaunch());
}
}
for (WarEventListener l : allListeners) {
l.RemoveCurrentElement(target.getMissileId());
}
for (WarEventListener l : allListeners) {
l.DestroyMissileProgressBar(target.getMissileId() , "missile");
}



synchronized (destructor) {
logger.log(Level.INFO, "Trying to destroy missile :"
Expand Down
44 changes: 42 additions & 2 deletions Java-Missle/src/view/IronDomesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import javax.swing.ImageIcon;
Expand All @@ -11,28 +14,65 @@
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import war.controller.WarEventListener;
import war.controller.WarUIEventsListener;

public class IronDomesPanel extends JPanel {
public static final String LAUNCHER_IMAGE_PATH = "/drawable/dome60x89.png";
private ImageIcon domeIcon = new ImageIcon(LAUNCHER_IMAGE_PATH);
private Queue<JButton> domeQueue = new LinkedList<JButton>();
public IronDomesPanel() {
private List<WarUIEventsListener> allListeners;
private WarGui warGui;
private String missileId;
private boolean fireMissileButtonPressed;
public IronDomesPanel(List<WarUIEventsListener> allListeners, WarGui warGui) {
this.setBorder(new LineBorder(new Color(0, 0, 0)));
setLayout(new GridLayout(2, 3,3,3));
this.fireMissileButtonPressed = false;
this.allListeners=allListeners;
this.warGui=warGui;

}
public void addIronDomeToPanel(String id){
public void addIronDomeToPanel(final String id){

JButton dome = new JButton(id,new ImageIcon(LaunchersPanel.class.getResource(LAUNCHER_IMAGE_PATH)));
dome.setVerticalTextPosition(SwingConstants.BOTTOM);
dome.setHorizontalTextPosition(SwingConstants.CENTER);
this.add(dome);
domeQueue.add(dome);
dome.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(fireMissileButtonPressed){
String IronDomeId = ((JButton) e.getSource()).getText(); // id of the launcher to destroy
setBorder(new LineBorder(new Color(0, 0, 0)));
validate();
//getIronDome(IronDomeId);
for (WarUIEventsListener l : allListeners) {
l.addInterceptionToUI(missileId, id);
}

}
}

});
repaint();
validate();

}
protected void getIronDome(String ironDomeId) {
warGui.getIronDome(ironDomeId);

}
public void addMissileDestructorToUI(String destructorId, String type) {
// type could be used for future functions if there are other Missile Destructors
addIronDomeToPanel(destructorId);
}
public void selectLauncherTofireFrom(String missileId) {
this.setBorder(new LineBorder(new Color(255, 0, 0), 2));
fireMissileButtonPressed = true;
this.missileId = missileId;

}
}
28 changes: 19 additions & 9 deletions Java-Missle/src/view/LaunchersPanel.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;

import war.controller.WarUIEventsListener;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class LaunchersPanel extends JPanel {
public static final String LAUNCHER_IMAGE_PATH = "/drawable/launcher87x70.png";

Expand All @@ -29,15 +28,26 @@ public class LaunchersPanel extends JPanel {
private boolean fireMissileButtonPressed;
private boolean destroyLauncherButtonPressed;
private WarGui warGui;
private JPanel panel;

public LaunchersPanel(List<WarUIEventsListener> allListeners, WarGui warGui) {
this.warGui = warGui;
// setLayout(new GridLayout(2, 3, 3, 3));
setLayout(new FlowLayout(FlowLayout.LEFT));
setBorder(new LineBorder(new Color(0, 0, 0)));
this.allListeners = allListeners;
this.fireMissileButtonPressed = false;
this.destroyLauncherButtonPressed = false;
setLayout(new BorderLayout(0, 0));


panel = new JPanel();
panel.setLayout(new FlowLayout());
add(panel, BorderLayout.CENTER);

JScrollPane scrollPane = new JScrollPane(panel);

scrollPane.setPreferredSize(new Dimension(305, 100));

add(scrollPane, BorderLayout.EAST);
}

public boolean isFireMissileButtonPressed() {
Expand All @@ -54,7 +64,7 @@ public void addLauncherToPanel(final String id) {
LaunchersPanel.class.getResource(LAUNCHER_IMAGE_PATH)));
launcher.setVerticalTextPosition(SwingConstants.BOTTOM);
launcher.setHorizontalTextPosition(SwingConstants.CENTER);
this.add(launcher);
panel.add(launcher);
launchersQueue.add(launcher);
repaint();
validate();
Expand Down
7 changes: 1 addition & 6 deletions Java-Missle/src/view/MissilePopUpFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;

import com.sun.glass.events.WindowEvent;

import war.War;
import war.controller.WarEventListener;
import war.controller.WarUIEventsListener;
import javax.swing.JLabel;

public class MissilePopUpFrame extends JFrame {
private JTextField txtId, txtDamage, txtDest, txtFlyTime;
Expand Down
Loading

0 comments on commit f27d0f3

Please sign in to comment.