Skip to content

Commit

Permalink
Remerged
Browse files Browse the repository at this point in the history
  • Loading branch information
juleskreutzer committed Jan 27, 2016
1 parent 3f14eb1 commit 6b9c225
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Hack Attack Client/src/hack/attack/client/GraphicsEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1096,14 +1096,16 @@ public void removeModule(Module mod){

public void drawAttackLine(Defense defense, Minion minion){
Line attackLine = new Line(defense.getPosition().x, defense.getPosition().y, minion.getPosition().x, minion.getPosition().y);
int currentID = ClientAdapter.getInstance().getCurrentUserID();
Window window = minion.getOwnerID() == currentID? FXMLDocumentController.Window.TOP : FXMLDocumentController.Window.DOWN;

if (defense.getModuleName() == ModuleName.BOTTLECAP_ANTIVIRUS)
{
attackLine.setStroke(Color.GREEN);
attackLine.setStrokeLineCap(StrokeLineCap.ROUND);
attackLine.setOpacity(0.75);
attackLine.setStrokeWidth(3);
parent.addNode(attackLine, Window.DOWN);
parent.addNode(attackLine, window);
}

switch(defense.getModuleName())
Expand All @@ -1113,28 +1115,28 @@ public void drawAttackLine(Defense defense, Minion minion){
attackLine.setStrokeLineCap(StrokeLineCap.ROUND);
attackLine.setOpacity(0.75);
attackLine.setStrokeWidth(3);
parent.addNode(attackLine, Window.DOWN);
parent.addNode(attackLine, window);
break;
case MUSCLE_ANTIVIRUS:
attackLine.setStroke(Color.BLUE);
attackLine.setStrokeLineCap(StrokeLineCap.ROUND);
attackLine.setOpacity(0.75);
attackLine.setStrokeWidth(3);
parent.addNode(attackLine, Window.DOWN);
parent.addNode(attackLine, window);
break;
case SCALE_ANTIVIRUS:
attackLine.setStroke(Color.PURPLE);
attackLine.setStrokeLineCap(StrokeLineCap.ROUND);
attackLine.setOpacity(0.75);
attackLine.setStrokeWidth(3);
parent.addNode(attackLine, Window.DOWN);
parent.addNode(attackLine, window);
break;
case SNIPER_ANTIVIRUS:
attackLine.setStroke(Color.RED);
attackLine.setStrokeLineCap(StrokeLineCap.ROUND);
attackLine.setOpacity(0.75);
attackLine.setStrokeWidth(3);
parent.addNode(attackLine, Window.DOWN);
parent.addNode(attackLine, window);
break;
}
//Initialize timer outisde of method and add tasks?
Expand All @@ -1144,7 +1146,7 @@ public void drawAttackLine(Defense defense, Minion minion){
timer.schedule(new TimerTask() {
@Override
public void run() {
parent.removeNode(attackLine, Window.DOWN);
parent.removeNode(attackLine, window);
}
},200);
}
Expand Down
32 changes: 32 additions & 0 deletions Hack Attack Client/src/hack/attack/rmi/ClientAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import hack.attack.client.FXMLDocumentController.Window;
import hack.attack.client.GraphicsEngine;
import hack.attack.client.MinionImage;
import hack.attack.client.ModuleImage;
import hack.attack.client.SoftwareInjector;
import hack.attack.client.SpawnTargetImage;
import hack.attack.client.exceptions.DuplicateSpawnException;
Expand Down Expand Up @@ -873,5 +874,36 @@ public void handle(MouseEvent event) {

});

}
@Override
public void fire(int moduleid, long minionid){
Defense source = null;
Minion target = null;

ArrayList<Node> nodes = engine.getAllNodes();
for(Node n : nodes)
{
if(n instanceof ModuleImage)
{
ModuleImage moi = (ModuleImage)n;
Module m = (Module)moi.getReference();
if(m.getModuleID() == moduleid){
source = (Defense)m;
}

}
if(n instanceof MinionImage){
MinionImage mii = (MinionImage)n;
Minion m = (Minion)mii.getReference();
if(m.getMinionID() == minionid){
target = m;
}
}
}
if(source != null && target != null){
engine.drawAttackLine(source, target);
}


}
}
2 changes: 2 additions & 0 deletions Hack Attack Client/src/hack/attack/rmi/IClientUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public interface IClientUpdate extends IClient {
* @param waveNumber Number indicating the current wave
*/
public void updateLabels(int waveNumber, String playernamea, double healthplayera, double bitcoinsplayera, String playernameb, double healthplayerb) throws RemoteException;

public void fire(int moduleid, long minionid) throws RemoteException;
}
2 changes: 2 additions & 0 deletions Hack Attack Client/src/hack/attack/rmi/Minion.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface MinionHeartbeat{
private static final long serialVersionUID = 000002L;
private long minionID = 0;


//Fields
private MinionType minionType; //The MinionType of the minion
private double health; //The ammunt of health the minion currently has.
Expand Down Expand Up @@ -57,6 +58,7 @@ public Minion(MinionType type)
*/
public Minion(MinionTemplate minion, double multiplier, int ownerID)
{
minionID = nextMinionID++;
health = (minion.getHealth() * multiplier);
initialHealth = health;
speed = (minion.getSpeed());
Expand Down
9 changes: 9 additions & 0 deletions Hack Attack Client/src/hack/attack/rmi/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ abstract public class Module implements Serializable {

private static final long serialVersionUID = 000003L;

private static int nextID;

protected int moduleID;

protected Point position;
protected int width;
protected int height;
Expand All @@ -28,6 +32,7 @@ abstract public class Module implements Serializable {

public Module(double cost, Point position, int width, int height, ModuleName name, int level, String desc)
{
moduleID = nextID++;
this.width = width;
this.height = height;
this.cost = cost;
Expand Down Expand Up @@ -174,4 +179,8 @@ public String getDescription()
{
return this.desc;
}

int getModuleID() {
return moduleID;
}
}
20 changes: 19 additions & 1 deletion Hack Attack Server/src/hack/attack/rmi/Defense.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import hack.attack.server.Wave;
import java.awt.Point;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
Expand All @@ -34,6 +35,10 @@ public class Defense extends Module implements ITargetable, Serializable {
ArrayList<Minion> minions;
Random random;

private IClientUpdate updateA;
private IClientUpdate updateB;


private int ownerID;

private double damage;
Expand Down Expand Up @@ -95,6 +100,10 @@ public Defense(DefenseTemplate template, Point position, int width, int height,
public void activate(GameEngine engine){
this.engine = engine;
target = null;

updateA = (IClientUpdate)engine.getInterfacesA().get("update");
updateB = (IClientUpdate)engine.getInterfacesB().get("update");

tickListener = new OnExecuteTick() {

@Override
Expand Down Expand Up @@ -446,7 +455,16 @@ public boolean hasTarget(){
* @param minion The enemy minion target.
*/
public void fire(Minion minion){
if(canDoDamage) { minion.receiveDamage(damage); }
if(canDoDamage) {
try {
minion.receiveDamage(damage);
updateA.fire(getModuleID(), minion.getMinionID());
updateB.fire(getModuleID(), minion.getMinionID());
} catch (RemoteException ex) {
Logger.getLogger(Defense.class.getName()).log(Level.SEVERE, null, ex);
}

}
if(!targetInRange(minion)||minion.getHealth() <= 0){
target = null;
}
Expand Down
2 changes: 2 additions & 0 deletions Hack Attack Server/src/hack/attack/rmi/IClientUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public interface IClientUpdate extends IClient {
* @param waveNumber Number indicating the current wave
*/
public void updateLabels(int waveNumber, String playernamea, double healthplayera, double bitcoinsplayera, String playernameb, double healthplayerb) throws RemoteException;

public void fire(int moduleid, long minionid) throws RemoteException;
}
9 changes: 9 additions & 0 deletions Hack Attack Server/src/hack/attack/rmi/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ abstract public class Module implements Serializable {

private static final long serialVersionUID = 000003L;

private static int nextID;

protected int moduleID;

protected Point position;
protected int width;
protected int height;
Expand All @@ -28,6 +32,7 @@ abstract public class Module implements Serializable {

public Module(double cost, Point position, int width, int height, ModuleName name, int level, String desc)
{
moduleID = nextID++;
this.width = width;
this.height = height;
this.cost = cost;
Expand All @@ -37,6 +42,10 @@ public Module(double cost, Point position, int width, int height, ModuleName nam

}

public int getModuleID(){
return moduleID;
}

/**
*
* @return the display name of the object
Expand Down

0 comments on commit 6b9c225

Please sign in to comment.