Added basic functionality with KahootChampion
This commit is contained in:
@@ -11,16 +11,16 @@ import javafx.scene.layout.GridPane;
|
|||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import static javafx.application.Application.launch;
|
import static javafx.application.Application.launch;
|
||||||
|
|
||||||
public class ShipWarfareGUI extends Application {
|
public class ShipWarfareGUI extends Application {
|
||||||
|
|
||||||
|
|
||||||
private Player player;
|
private Player player = new Player();
|
||||||
public static void main(String args[]){
|
public static void main(String args[]){
|
||||||
launch(args);
|
launch(args);
|
||||||
ShipWarfare ship = new ShipWarfare(new Player());
|
|
||||||
ship.peasantFleetAttack();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Label label1;
|
private Label label1;
|
||||||
@@ -28,6 +28,28 @@ public class ShipWarfareGUI extends Application {
|
|||||||
private Button button1;
|
private Button button1;
|
||||||
private Button button2;
|
private Button button2;
|
||||||
|
|
||||||
|
public int numOfShips() {
|
||||||
|
|
||||||
|
int numOfShipsAttacking = 0;
|
||||||
|
Random randomValue = new Random();
|
||||||
|
if (player.getMoney() <= 100000) {
|
||||||
|
//Minimum one ship will attack, maximum 20
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(20) + 1;
|
||||||
|
} else if (player.getMoney() <= 200000) {
|
||||||
|
//Minimum 30 Ships will attack, maximum 70
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(40) + 30;
|
||||||
|
} else if (player.getMoney() <= 500000) {
|
||||||
|
//Minimum 50 ships will attack, maximum 140
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(90) + 50;
|
||||||
|
} else if (player.getMoney() > 1000000) {
|
||||||
|
//Minimum 100 ships will attack, maximum 300 ships
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(3) + 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
return numOfShipsAttacking;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void setPlayer(Player player) {
|
public void setPlayer(Player player) {
|
||||||
this.player = new Player(player);
|
this.player = new Player(player);
|
||||||
}
|
}
|
||||||
@@ -89,11 +111,18 @@ public class ShipWarfareGUI extends Application {
|
|||||||
hBox1.getChildren().add(button1);
|
hBox1.getChildren().add(button1);
|
||||||
hBox1.getChildren().add(button2);
|
hBox1.getChildren().add(button2);
|
||||||
|
|
||||||
|
ShipWarfareGUI ship = new ShipWarfareGUI();
|
||||||
|
label1.setText(ship.numOfShips() + " Merchant Ships are attacking you.");
|
||||||
|
|
||||||
button1.setOnAction(new EventHandler<ActionEvent>(){
|
button1.setOnAction(new EventHandler<ActionEvent>(){
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event){
|
public void handle(ActionEvent event){
|
||||||
label1.setText("Balance: ");
|
label1.setText("Balance: ");
|
||||||
System.out.println("You pressed the button.");
|
System.out.println("You pressed the button.");
|
||||||
|
button1.setVisible(false);
|
||||||
|
button2.setVisible(false);
|
||||||
|
button1.setDisable(true);
|
||||||
|
button2.setDisable(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user