Skip to content

Commit

Permalink
BitcoinMiner implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperRh committed Nov 4, 2015
1 parent 7c7957c commit d208574
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 6 deletions.
1 change: 1 addition & 0 deletions HackAttackFX/src/hackattackfx/BitcoinMiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void onTick(long elapsedtime) {

}
};
GameEngine.getInstance().setOnTickListener(tick);
}

public void setOnMineListener(OnMineComplete callback) throws DuplicateListenerException
Expand Down
2 changes: 0 additions & 2 deletions HackAttackFX/src/hackattackfx/CPUUpgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ public boolean upgrade(Iterator<Minion> minions) throws NoUpgradeAllowedExceptio
{
newCPU = Data.DEFAULT_MODULE_CPUUPGRADE_2;
this.level = newCPU.getLevel();
super.setLevel(newCPU.getLevel());
this.minionBonusMultiplier = newCPU.getMinionBonusMultiplier();
return true;
}
else if(this.level == 2)
{
newCPU = Data.DEFAULT_MODULE_CPUUPGRADE_3;
this.level = newCPU.getLevel();
super.setLevel(newCPU.getLevel());
this.minionBonusMultiplier = newCPU.getMinionBonusMultiplier();
return true;
}
Expand Down
12 changes: 10 additions & 2 deletions HackAttackFX/src/hackattackfx/FXMLDocument.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<Label id="lblCurrentWave" layoutX="785.0" layoutY="28.0" prefHeight="17.0" prefWidth="136.0" text="Wave:" />
<ImageView fx:id="btnPause" fitHeight="40.0" fitWidth="40.0" layoutX="1309.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="hackattackfx/resources/interface/Icons/PauseButton.png" backgroundLoading="true" />
<Image url="hackattackfx/resources/interface/Icons/PauseButton.png" backgroundLoading="false" />
</image>
</ImageView>
</children>
Expand Down Expand Up @@ -65,6 +65,14 @@
</AnchorPane>
</children>
</AnchorPane>
<AnchorPane id="window" layoutX="0.0" layoutY="70.0" prefHeight="527.0" prefWidth="1366.0" style="-fx-background-image: url(&quot;hackattackfx/resources/Background.png&quot;);" />
<AnchorPane id="window" layoutX="0.0" layoutY="70.0" prefHeight="527.0" prefWidth="1366.0" style="-fx-background-image: url(&quot;hackattackfx/resources/Background.png&quot;);">
<children>
<ImageView fx:id="buildBitcoinMiner" fitHeight="40.0" fitWidth="40.0" layoutX="49.0" layoutY="244.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="hackattackfx/resources/interface/Icons/Base/light/Bitcoin.png" backgroundLoading="true" />
</image>
</ImageView>
</children>
</AnchorPane>
</children>
</AnchorPane>
44 changes: 42 additions & 2 deletions HackAttackFX/src/hackattackfx/GameEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.Node;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;

/*
* To change this license header, choose License Headers in Project Properties.
Expand Down Expand Up @@ -113,7 +113,7 @@ private void initialize(){
}

/**
* Mostly used to draw the initial components like the bases and roads and event handlers
* Mostly used to draw the initial components like the bases, roads and event handlers
*/
private void preStart(){
graphicsEngine.drawRoad(map.getRoad());
Expand Down Expand Up @@ -456,6 +456,46 @@ public void handle(MouseEvent event) {
}
});

ImageView bitcoinminer = (ImageView)graphicsEngine.getNode("buildBitcoinMiner",null);
bitcoinminer.setOnMouseClicked(new EventHandler<MouseEvent>(){

@Override
public void handle(MouseEvent event) {
Image i = bitcoinminer.getImage();
Point p = new Point((int)bitcoinminer.getX(),(int)bitcoinminer.getY());
try {
BitcoinMiner miner = new BitcoinMiner(Data.DEFAULT_MODULE_BITCOINMINER_1,p,(int)i.getWidth(),(int)i.getHeight());
playerA.buildBitcoinMiner(miner);
graphicsEngine.drawBaseModule(ModuleName.BITCOIN_MINER, true);
miner.activate();
} catch (NotEnoughBitcoinsException ex) {
graphicsEngine.showError("Not enough bitcoins!");
} catch (InvalidModuleEnumException ex) {
Logger.getLogger(GameEngine.class.getName()).log(Level.SEVERE, null, ex);
}
}

});
bitcoinminer.setOnMouseEntered(new EventHandler<MouseEvent>(){

@Override
public void handle(MouseEvent event) {
try {
BitcoinMiner module = new BitcoinMiner(Data.DEFAULT_MODULE_BITCOINMINER_1,null,0,0);
graphicsEngine.drawModuleStats(module);
} catch (InvalidModuleEnumException ex) {
Logger.getLogger(GameEngine.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
bitcoinminer.setOnMouseExited(new EventHandler<MouseEvent>(){

@Override
public void handle(MouseEvent event) {
graphicsEngine.drawModuleStats(null);
}
});

ImageView pausebutton = (ImageView)graphicsEngine.getNode("btnPause",null);
pausebutton.setOnMouseClicked(new EventHandler<MouseEvent>(){

Expand Down
27 changes: 27 additions & 0 deletions HackAttackFX/src/hackattackfx/GraphicsEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,33 @@ public void drawSpellRange(Spell spell){

}

/**
* Draws the module of the given {@link ModuleName} and sets the corresponding enabled or disabled image.
* @param name
* @param enabled
*/
public void drawBaseModule(ModuleName name, boolean enabled){
switch(name){
case BITCOIN_MINER:
File file;
if(enabled){
file = new File("src/hackattackfx/resources/interface/Icons/Base/dark/Bitcoin.png");
}else{
file = new File("src/hackattackfx/resources/interface/Icons/Base/light/Bitcoin.png");
}
ImageView miner = (ImageView)parent.getNode("buildBitcoinMiner",null);
Image image = new Image(file.toURI().toString());
miner.setImage(image);
break;
case CPU_UPGRADE:

break;
case SOFTWARE_INJECTOR:

break;
}
}

public void drawLabels(int wavenr, String name, double health, double bitcoins){
Platform.runLater(new Runnable(){

Expand Down

0 comments on commit d208574

Please sign in to comment.