diff --git a/src/main/java/fi/utu/tech/gui/javafx/Check.java b/src/main/java/fi/utu/tech/gui/javafx/Check.java index 5e5b2c4b7b9625c67ce7c71e3c7debc2d472d8c8..0437884b2fe3291b21a51b7585cf91e8ac42fc92 100644 --- a/src/main/java/fi/utu/tech/gui/javafx/Check.java +++ b/src/main/java/fi/utu/tech/gui/javafx/Check.java @@ -4,61 +4,44 @@ import javafx.scene.control.Alert; import javafx.stage.Stage; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; public class Check { - public static void check(String p1, String p2, Object grid, int lentotuki, int taistelu, int risteily, int sukellus, int kevyt) throws IOException { - int l = lentotuki * 5; - int t = taistelu * 4; - int r = risteily * 3; - int s = sukellus * 3; - int k = kevyt * 2; - int total = l+t+r+s+k; - String g = (String) grid; - - int max = 25; + public Check() { - if (g.equals("5 x 5")){ - max = 12; - } - if (g.equals("6 x 6")){ - max = 18; - } - if (g.equals("7 x 7")){ - max = 29; - } - if (g.equals("8 x 8")){ - max = 32; - } - if (g.equals("9 x 9")){ - max = 40; - } - if (g.equals("10 x 10")){ - max = 50; - } + } + public static void check(String p1, String p2, Object grid, ArrayList<Integer> ships) throws IOException { + String g = (String) grid; - if (g.equals("5 x 5") && (total) <= 12){ - GameWindow.start(5,l,t,r,s,k, new Stage()); - } - if (g.equals("6 x 6") && (total)<= 18){ - GameWindow.start(6,l,t,r,s,k, new Stage()); - } - if (g.equals("7 x 7") && (total)<= 29){ - GameWindow.start(7,l,t,r,s,k, new Stage()); - } - if (g.equals("8 x 8") && (total)<= 32){ - GameWindow.start(8,l,t,r,s,k, new Stage()); - } - if (g.equals("9 x 9") && (total)<= 40){ - GameWindow.start(9,l,t,r,s,k, new Stage()); - } - if (g.equals("10 x 10") && (total)<= 50){ - GameWindow.start(10,l,t,r,s,k, new Stage()); - } - else{ + int max = 0; + int shipSpace = (ships.get(0) * 2) + (ships.get(1) * 3) + (ships.get(2) * 3) + (ships.get(3) * 4) + (ships.get(4) * 5); + + switch (g) { + case "5 x 5": + max = 12; + break; + case "6 x 6": + max = 18; + break; + case "7 x 7": + max = 24; + break; + case "8 x 8": + max = 32; + break; + case "9 x 9": + max = 40; + break; + case "10 x 10": + max = 50; + break; + } + if (shipSpace > max) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Information Dialog"); - alert.setHeaderText("Liikaa posankoita!!! " + (total) + "/" + max); + alert.setHeaderText("Liikaa posankoita!!! " + (shipSpace) + "/" + max); alert.setContentText("Vähennä posankoiden määrää"); alert.showAndWait(); diff --git a/src/main/java/fi/utu/tech/gui/javafx/Controller.java b/src/main/java/fi/utu/tech/gui/javafx/Controller.java index 08400347b7c3e7db4164633d03cd3b2b68e681f5..b8bf57dd5b83913e9aeb32ca3e77099224b949d7 100644 --- a/src/main/java/fi/utu/tech/gui/javafx/Controller.java +++ b/src/main/java/fi/utu/tech/gui/javafx/Controller.java @@ -9,6 +9,8 @@ import javafx.stage.Stage; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; public class Controller { @@ -42,20 +44,36 @@ public class Controller { @FXML private Button start; + private ArrayList<Integer> ships; + //Bindaa laivojen määrän laskuriin KESKEN Pls help. Voi kans poistaa @FXML public void initialize(){ - int l = lentotuki.getValue(); - int t = taistelija.getValue(); - int r = risteily.getValue(); - int s = lentotuki.getValue(); - int k = lentotuki.getValue(); + count.textProperty().bind(new SimpleIntegerProperty().asString()); + + ships = new ArrayList<Integer>(); + + for(int i = 0; i < 5; i++ ) { + ships.add(0); + } + + lentotuki.valueProperty().addListener((obs, oldValue, newValue) -> + ships.set(4, newValue)); + + taistelija.valueProperty().addListener((obs1, oldValue1, newValue1) -> + ships.set(3, newValue1)); + + risteily.valueProperty().addListener((obs2, oldValue2, newValue2) -> + ships.set(2, newValue2)); + sukellus.valueProperty().addListener((obs3, oldValue3, newValue3) -> + ships.set(1, newValue3)); - count.textProperty().bind(new SimpleIntegerProperty(l).asString()); + kevyt.valueProperty().addListener((obs4, oldValue4, newValue4) -> + ships.set(0, newValue4)); } @@ -64,6 +82,7 @@ public class Controller { void startGamePressed(ActionEvent e) throws IOException { Check.check(player1.getId(), player2.getId(), +<<<<<<< HEAD grid.getValue(), lentotuki.getValue(), taistelija.getValue(), @@ -73,6 +92,9 @@ public class Controller { Stage mainGame = new Stage(); +======= + grid.getValue(), ships); +>>>>>>> 223376c3d7907cb9280f32d7f878d7f3591e5476 }