diff --git a/class/application/Controller$1.class b/class/application/Controller$1.class index 1e159b04bcc10e758a54a6ad35ca4ba9fa4b5df2..f285cfaad04c444835452f2b4fd554adb419b14c 100644 Binary files a/class/application/Controller$1.class and b/class/application/Controller$1.class differ diff --git a/class/application/Controller$2.class b/class/application/Controller$2.class index 8772805082f719d2f4069e28ab38c667cdc86f64..770c6bd7b41d397a1fe2139e3cea67f767dce807 100644 Binary files a/class/application/Controller$2.class and b/class/application/Controller$2.class differ diff --git a/class/application/Controller$3.class b/class/application/Controller$3.class index 2128f395e0c1285f380c5a39a35da7d4cc20120f..e69c0cf350cd9b9657139a7163639d98b94612c7 100644 Binary files a/class/application/Controller$3.class and b/class/application/Controller$3.class differ diff --git a/class/application/Controller$4.class b/class/application/Controller$4.class index 4f60b496f10af4cf9f947231cbafa5df3c3fee53..999d61509c117294c1f1c8168aed35ba49c67a9d 100644 Binary files a/class/application/Controller$4.class and b/class/application/Controller$4.class differ diff --git a/class/application/Controller$5.class b/class/application/Controller$5.class index ff65ae4e0c93ec903179d2e54404bff4359b5f6a..7a730d62a3e4d03f10bba0fafb77f76c054381da 100644 Binary files a/class/application/Controller$5.class and b/class/application/Controller$5.class differ diff --git a/class/application/Controller$6.class b/class/application/Controller$6.class index 027974dcc6466893efeb7b749ce78cc985b6df6c..ec87ab5584606e73ee3fc437c18f1fb8a6d0391b 100644 Binary files a/class/application/Controller$6.class and b/class/application/Controller$6.class differ diff --git a/class/application/Controller$7.class b/class/application/Controller$7.class index 7f51833b4c466c9acccd2a116b74b66b50fc1632..c67eaa2734c58f9732d1b4031da5cc9e36d61bd2 100644 Binary files a/class/application/Controller$7.class and b/class/application/Controller$7.class differ diff --git a/class/application/Controller$8.class b/class/application/Controller$8.class index 8711b3bf8f6442640e8de6cdfbe744dd442a1164..fda9f9734cf7d5026d164da40117b70622086f13 100644 Binary files a/class/application/Controller$8.class and b/class/application/Controller$8.class differ diff --git a/class/application/Controller.class b/class/application/Controller.class index a393e20a12c8a0779aba81a2046f8e2121bbf637..1d08088c6bd0c22f96fc9657f82d0bb2080f3355 100644 Binary files a/class/application/Controller.class and b/class/application/Controller.class differ diff --git a/class/application/Main.class b/class/application/Main.class index 9052a30434ad5936f733b59d1de4fb72348f0b71..dabd9a0e1d264556eddbc6eaa71c216e4edd1674 100644 Binary files a/class/application/Main.class and b/class/application/Main.class differ diff --git a/class/application/MainGUI.fxml b/class/application/MainGUI.fxml index e4034b73ab3be3bd61c0fba252faf4d57a56802b..979f8741621f2615fdb45dc649d1ca023bc80112 100644 --- a/class/application/MainGUI.fxml +++ b/class/application/MainGUI.fxml @@ -3,6 +3,9 @@ <?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> +<?import javafx.scene.control.Menu?> +<?import javafx.scene.control.MenuBar?> +<?import javafx.scene.control.MenuItem?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.HBox?> @@ -50,17 +53,17 @@ <Font name="System Bold" size="12.0" /> </font> </Label> - <Label fx:id="labelAI2Name" alignment="CENTER" contentDisplay="CENTER" layoutX="661.0" layoutY="95.0" prefHeight="19.0" prefWidth="106.0" text="Computer 2" textAlignment="CENTER"> + <Label fx:id="labelAI2Name" alignment="CENTER" contentDisplay="CENTER" layoutX="661.0" layoutY="107.0" prefHeight="19.0" prefWidth="106.0" text="Computer 2" textAlignment="CENTER"> <font> <Font name="System Bold" size="13.0" /> </font> </Label> - <Label fx:id="labelAI3Name" alignment="CENTER" contentDisplay="CENTER" layoutX="36.0" layoutY="95.0" prefHeight="19.0" prefWidth="106.0" text="Computer 3" textAlignment="CENTER"> + <Label fx:id="labelAI3Name" alignment="CENTER" contentDisplay="CENTER" layoutX="36.0" layoutY="107.0" prefHeight="19.0" prefWidth="106.0" text="Computer 3" textAlignment="CENTER"> <font> <Font name="System Bold" size="13.0" /> </font> </Label> - <Label fx:id="labelAI1Name" alignment="CENTER" contentDisplay="CENTER" layoutX="340.0" layoutY="16.0" prefHeight="19.0" prefWidth="106.0" text="Computer 1" textAlignment="CENTER"> + <Label fx:id="labelAI1Name" alignment="CENTER" contentDisplay="CENTER" layoutX="340.0" layoutY="38.0" prefHeight="19.0" prefWidth="106.0" text="Computer 1" textAlignment="CENTER"> <font> <Font name="System Bold" size="13.0" /> </font> @@ -70,5 +73,16 @@ <Font name="System Bold" size="14.0" /> </font> </Button> + <MenuBar fx:id="menuBar" prefHeight="25.0" prefWidth="304.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"> + <menus> + <Menu fx:id="menu1" mnemonicParsing="false" text="Menü"> + <items> + <MenuItem fx:id="menuItem1" mnemonicParsing="false" onAction="#startGame" text="Neues Spiel" /> + <MenuItem fx:id="menuItem2" mnemonicParsing="false" onAction="#openSettings" text="Einstellungen" /> + <MenuItem fx:id="menuItem3" mnemonicParsing="false" onAction="#about" text="Über" /> + </items> + </Menu> + </menus> + </MenuBar> </children> </AnchorPane> diff --git a/class/application/PathSettings.class b/class/application/PathSettings.class new file mode 100644 index 0000000000000000000000000000000000000000..3325c7acc9f96544b9d89e46a0522c912ec15c5c Binary files /dev/null and b/class/application/PathSettings.class differ diff --git a/class/application/Settings.class b/class/application/Settings.class new file mode 100644 index 0000000000000000000000000000000000000000..4f44a6cf7664369814f1b0b89d53a653c8b1297f Binary files /dev/null and b/class/application/Settings.class differ diff --git a/class/application/Settings.fxml b/class/application/Settings.fxml index e8b4a5e6b117a27e5152586b8648340e0407fe4b..f6de2a01df9cf32b0ffae916d30b386ffcdf8e69 100644 --- a/class/application/Settings.fxml +++ b/class/application/Settings.fxml @@ -1,6 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.Insets?> +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.CheckBox?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.Slider?> <?import javafx.scene.layout.AnchorPane?> @@ -8,8 +10,7 @@ <?import javafx.scene.layout.VBox?> <?import javafx.scene.text.Font?> - -<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65"> +<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SettingsController"> <children> <VBox layoutX="45.0" layoutY="40.0" prefHeight="320.0" prefWidth="511.0"> <children> @@ -20,7 +21,7 @@ <Font name="System Bold" size="14.0" /> </font> </Label> - <Slider blockIncrement="1.0" majorTickUnit="1.0" max="3.0" min="1.0" minorTickCount="0" prefHeight="44.0" prefWidth="230.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> + <Slider fx:id="sliderNumberOfAIs" blockIncrement="1.0" majorTickUnit="1.0" max="3.0" min="1.0" minorTickCount="0" prefHeight="44.0" prefWidth="230.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> <HBox.margin> <Insets left="50.0" /> </HBox.margin> @@ -34,7 +35,7 @@ <Font name="System Bold" size="14.0" /> </font> </Label> - <Slider blockIncrement="1.0" majorTickUnit="1.0" max="10.0" min="3.0" minorTickCount="0" prefHeight="44.0" prefWidth="233.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> + <Slider fx:id="sliderNumberOfStartingCards" blockIncrement="1.0" majorTickUnit="1.0" max="10.0" min="3.0" minorTickCount="0" prefHeight="44.0" prefWidth="233.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> <HBox.margin> <Insets left="50.0" /> </HBox.margin> @@ -54,7 +55,7 @@ <Insets /> </HBox.margin> </Label> - <Slider blockIncrement="1.0" majorTickUnit="1.0" max="4.0" min="1.0" minorTickCount="0" prefHeight="44.0" prefWidth="233.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> + <Slider fx:id="sliderAISpeed" blockIncrement="1.0" majorTickUnit="1.0" max="4.0" min="1.0" minorTickCount="0" prefHeight="44.0" prefWidth="233.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> <HBox.margin> <Insets left="50.0" /> </HBox.margin> @@ -64,7 +65,45 @@ <Insets top="25.0" /> </VBox.margin> </HBox> + <HBox prefHeight="44.0" prefWidth="412.0"> + <children> + <Label alignment="TOP_RIGHT" contentDisplay="TOP" prefHeight="20.0" prefWidth="150.0" text="Regeln:"> + <font> + <Font name="System Bold" size="14.0" /> + </font> + <HBox.margin> + <Insets /> + </HBox.margin> + </Label> + <VBox> + <HBox.margin> + <Insets left="50.0" /> + </HBox.margin> + <children> + <CheckBox fx:id="checkBoxRule1" mnemonicParsing="false" text="+2 Karten können verlängert werden" /> + <CheckBox fx:id="checkBoxRule2" mnemonicParsing="false" text="+4 Karten können mit +2 Karten verlängert werden"> + <VBox.margin> + <Insets top="10.0" /> + </VBox.margin> + </CheckBox> + <CheckBox fx:id="checkBoxRule3" mnemonicParsing="false" text="+4 Karten können mit +4 Karten verlängert werden"> + <VBox.margin> + <Insets top="10.0" /> + </VBox.margin> + </CheckBox> + </children> + </VBox> + </children> + <VBox.margin> + <Insets top="25.0" /> + </VBox.margin> + </HBox> </children> </VBox> + <Button layoutX="264.0" layoutY="348.0" mnemonicParsing="false" onAction="#save" text="Speichern"> + <font> + <Font name="System Bold" size="12.0" /> + </font> + </Button> </children> </AnchorPane> diff --git a/class/application/SettingsController$1.class b/class/application/SettingsController$1.class new file mode 100644 index 0000000000000000000000000000000000000000..f52ad07f21f51896ac07d7146b980ab1cb6a8641 Binary files /dev/null and b/class/application/SettingsController$1.class differ diff --git a/class/application/SettingsController.class b/class/application/SettingsController.class new file mode 100644 index 0000000000000000000000000000000000000000..b1ad5cd7fb698773a4eeab42acc62785e9b11c4d Binary files /dev/null and b/class/application/SettingsController.class differ diff --git a/class/logic/Game.class b/class/logic/Game.class index 30c9f4d97f0f453d12e3da4b64421989052c693e..8e4517650abb53f2aa52706df849fba4e8862567 100644 Binary files a/class/logic/Game.class and b/class/logic/Game.class differ diff --git a/src/application/Controller.java b/src/application/Controller.java index 4de9069bbf5b0804d5a5b61408f1637d78ccee37..4d20216343a9c1d001c6dbf35eff156c68dd889b 100644 --- a/src/application/Controller.java +++ b/src/application/Controller.java @@ -22,6 +22,9 @@ import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuBar; +import javafx.scene.control.MenuItem; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.image.WritableImage; @@ -59,11 +62,16 @@ public class Controller @FXML private Label labelAI2Name; @FXML private Label labelAI3Name; @FXML private Button buttonStart; - + @FXML private MenuBar menuBar; + @FXML private Menu menu1; + @FXML private MenuItem menuItem1; + @FXML private MenuItem menuItem2; + @FXML private MenuItem menuItem3; public Game game; public Color chosenWishColor; public int drawCounter; + public Settings settings; public Stage stage; public Image icon = new Image("images/icon.png"); @@ -78,7 +86,7 @@ public class Controller private final double CARD_SPACING_ULTRA_SMALL = - 35.0; private Point2D PLAYER_STARTING_POINT; - private final Point2D AI_1_STARTING_POINT = new Point2D(100.0, 50.0); + private final Point2D AI_1_STARTING_POINT = new Point2D(100.0, 75.0); private Point2D AI_2_STARTING_POINT; private Point2D AI_3_STARTING_POINT; @@ -91,10 +99,38 @@ public class Controller { imageViewWishColor.setImage(new Image("/images/circle-all.png")); - PLAYER_STARTING_POINT = new Point2D(100.0, stage.getScene().getHeight() - 60.0 - CARD_HEIGHT); - AI_2_STARTING_POINT = new Point2D(stage.getScene().getWidth() - CARD_HEIGHT - 30, 50.0); - AI_3_STARTING_POINT = new Point2D(60.0, 50.0); + PLAYER_STARTING_POINT = new Point2D(100.0, stage.getScene().getHeight() - 50.0 - CARD_HEIGHT); + AI_2_STARTING_POINT = new Point2D(stage.getScene().getWidth() - CARD_HEIGHT - 30, 70.0); + AI_3_STARTING_POINT = new Point2D(60.0, 70.0); + + clearAll(); + + settings = new Settings(); + try + { + settings.load(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + public void setStage(Stage stage) + { + this.stage = stage; + } + + public void startGame() + { + menuItem2.setDisable(true); + + hideWishColor(); + hideInfo(); + hideLabelChallengeCounter(); + + drawCounter = 0; + iconDeck.setImage(createEmptyBackCard()); iconDeck.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @@ -111,35 +147,9 @@ public class Controller } }); - hideWishColor(); - hideInfo(); - hideLabelChallengeCounter(); - setImageViewDirection(Direction.RIGHT); - labelAI1Name.setVisible(false); - labelAI2Name.setVisible(false); - labelAI3Name.setVisible(false); - buttonStart.setVisible(false); - - startGame(); - } - - public void setStage(Stage stage) - { - this.stage = stage; - } - - public void startGame() - { - hideWishColor(); - hideInfo(); - hideLabelChallengeCounter(); - - drawCounter = 0; - - // DEBUG - game = new Game(this, 2); + game = new Game(this, settings.getNumberOfAIs(), settings.getAiSpeed()); setLabelNames(game.getPlayer(), game.getAIs()); - game.newGame(5); + game.newGame(settings.getNumberOfStartingCards()); buttonStart.setOnAction(new EventHandler<ActionEvent>() { @@ -265,8 +275,17 @@ public class Controller labelChallengeCounter.setVisible(true); } + public void hideImageViewDirection() + { + imageViewDirection.setVisible(false); + labelDirection.setVisible(false); + } + public void setImageViewDirection(Direction direction) { + imageViewDirection.setVisible(true); + labelDirection.setVisible(true); + if(direction.equals(Direction.RIGHT)) { imageViewDirection.setImage(new Image("/images/DIRECTION_RIGHT.png")); @@ -979,7 +998,47 @@ public class Controller } } - //TODO reverse is not working correctly + public void openSettings() + { + try + { + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/application/Settings.fxml")); + + Parent root = (Parent)fxmlLoader.load(); + Stage newStage = new Stage(); + newStage.setScene(new Scene(root, 600, 400)); + newStage.setTitle("Einstellungen"); + newStage.initOwner(stage); + + newStage.getIcons().add(icon); + SettingsController newController = fxmlLoader.getController(); + newController.init(newStage, this); + + newStage.initModality(Modality.APPLICATION_MODAL); + newStage.setResizable(false); + newStage.showAndWait(); + + } + catch(IOException e1) + { + e1.printStackTrace(); + } + } + + public void clearAll() + { + menuItem2.setDisable(false); + hideWishColor(); + hideInfo(); + hideLabelChallengeCounter(); + hideImageViewDirection(); + labelAI1Name.setVisible(false); + labelAI2Name.setVisible(false); + labelAI3Name.setVisible(false); + buttonStart.setVisible(false); + iconDeck.setImage(null); + iconLastCard.setImage(null); + } public void about() { @@ -990,5 +1049,5 @@ public class Controller Stage dialogStage = (Stage)alert.getDialogPane().getScene().getWindow(); dialogStage.getIcons().add(icon); alert.showAndWait(); - } + } } \ No newline at end of file diff --git a/src/application/Main.java b/src/application/Main.java index e83f9ae679d7fa5252b9fb7aba06f662c408f5cf..287fcb504addbe07651ed0d840e2e2a1aa509e61 100644 --- a/src/application/Main.java +++ b/src/application/Main.java @@ -22,7 +22,8 @@ public class Main extends Application stage.setResizable(true); stage.setTitle("UNO"); - stage.setScene(scene); + stage.setScene(scene); + stage.setResizable(false); Controller controller = (Controller)loader.getController(); controller.setStage(stage); diff --git a/src/application/MainGUI.fxml b/src/application/MainGUI.fxml index e4034b73ab3be3bd61c0fba252faf4d57a56802b..979f8741621f2615fdb45dc649d1ca023bc80112 100644 --- a/src/application/MainGUI.fxml +++ b/src/application/MainGUI.fxml @@ -3,6 +3,9 @@ <?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> +<?import javafx.scene.control.Menu?> +<?import javafx.scene.control.MenuBar?> +<?import javafx.scene.control.MenuItem?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.HBox?> @@ -50,17 +53,17 @@ <Font name="System Bold" size="12.0" /> </font> </Label> - <Label fx:id="labelAI2Name" alignment="CENTER" contentDisplay="CENTER" layoutX="661.0" layoutY="95.0" prefHeight="19.0" prefWidth="106.0" text="Computer 2" textAlignment="CENTER"> + <Label fx:id="labelAI2Name" alignment="CENTER" contentDisplay="CENTER" layoutX="661.0" layoutY="107.0" prefHeight="19.0" prefWidth="106.0" text="Computer 2" textAlignment="CENTER"> <font> <Font name="System Bold" size="13.0" /> </font> </Label> - <Label fx:id="labelAI3Name" alignment="CENTER" contentDisplay="CENTER" layoutX="36.0" layoutY="95.0" prefHeight="19.0" prefWidth="106.0" text="Computer 3" textAlignment="CENTER"> + <Label fx:id="labelAI3Name" alignment="CENTER" contentDisplay="CENTER" layoutX="36.0" layoutY="107.0" prefHeight="19.0" prefWidth="106.0" text="Computer 3" textAlignment="CENTER"> <font> <Font name="System Bold" size="13.0" /> </font> </Label> - <Label fx:id="labelAI1Name" alignment="CENTER" contentDisplay="CENTER" layoutX="340.0" layoutY="16.0" prefHeight="19.0" prefWidth="106.0" text="Computer 1" textAlignment="CENTER"> + <Label fx:id="labelAI1Name" alignment="CENTER" contentDisplay="CENTER" layoutX="340.0" layoutY="38.0" prefHeight="19.0" prefWidth="106.0" text="Computer 1" textAlignment="CENTER"> <font> <Font name="System Bold" size="13.0" /> </font> @@ -70,5 +73,16 @@ <Font name="System Bold" size="14.0" /> </font> </Button> + <MenuBar fx:id="menuBar" prefHeight="25.0" prefWidth="304.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"> + <menus> + <Menu fx:id="menu1" mnemonicParsing="false" text="Menü"> + <items> + <MenuItem fx:id="menuItem1" mnemonicParsing="false" onAction="#startGame" text="Neues Spiel" /> + <MenuItem fx:id="menuItem2" mnemonicParsing="false" onAction="#openSettings" text="Einstellungen" /> + <MenuItem fx:id="menuItem3" mnemonicParsing="false" onAction="#about" text="Über" /> + </items> + </Menu> + </menus> + </MenuBar> </children> </AnchorPane> diff --git a/src/application/PathSettings.java b/src/application/PathSettings.java new file mode 100644 index 0000000000000000000000000000000000000000..57b06aa29a43550e13c955fbc787a940a031f50d --- /dev/null +++ b/src/application/PathSettings.java @@ -0,0 +1,66 @@ +package application; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; + +import tools.PathUtils; + +public class PathSettings implements Serializable +{ + private static final long serialVersionUID = 1L; + private String pathLogfile; + private ArrayList<String> folders; + + public PathSettings() + { + pathLogfile = ""; + folders = new ArrayList<String>(); + PathUtils.checkFolder(new File(System.getenv("APPDATA") + "/Deadlocker/PlayCount/")); + } + + public void save() throws Exception + { + FileOutputStream fileOut = new FileOutputStream(System.getenv("APPDATA") + "/Deadlocker/PlayCount/paths.config"); + ObjectOutputStream out = new ObjectOutputStream(fileOut); + out.writeObject(this); + out.close(); + fileOut.close(); + } + + public void load() throws Exception + { + FileInputStream fileIn = new FileInputStream(System.getenv("APPDATA") + "/Deadlocker/PlayCount/paths.config"); + ObjectInputStream in = new ObjectInputStream(fileIn); + PathSettings loaded = (PathSettings) in.readObject(); + in.close(); + fileIn.close(); + + this.pathLogfile = loaded.getPathLogfile(); + this.folders = loaded.getFolders(); + } + + public String getPathLogfile() + { + return pathLogfile; + } + + public ArrayList<String> getFolders() + { + return folders; + } + + public void setPathLogfile(String pathLogfile) + { + this.pathLogfile = pathLogfile; + } + + public void setFolders(ArrayList<String> folders) + { + this.folders = folders; + } +} \ No newline at end of file diff --git a/src/application/Settings.fxml b/src/application/Settings.fxml index e8b4a5e6b117a27e5152586b8648340e0407fe4b..f6de2a01df9cf32b0ffae916d30b386ffcdf8e69 100644 --- a/src/application/Settings.fxml +++ b/src/application/Settings.fxml @@ -1,6 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.Insets?> +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.CheckBox?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.Slider?> <?import javafx.scene.layout.AnchorPane?> @@ -8,8 +10,7 @@ <?import javafx.scene.layout.VBox?> <?import javafx.scene.text.Font?> - -<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65"> +<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SettingsController"> <children> <VBox layoutX="45.0" layoutY="40.0" prefHeight="320.0" prefWidth="511.0"> <children> @@ -20,7 +21,7 @@ <Font name="System Bold" size="14.0" /> </font> </Label> - <Slider blockIncrement="1.0" majorTickUnit="1.0" max="3.0" min="1.0" minorTickCount="0" prefHeight="44.0" prefWidth="230.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> + <Slider fx:id="sliderNumberOfAIs" blockIncrement="1.0" majorTickUnit="1.0" max="3.0" min="1.0" minorTickCount="0" prefHeight="44.0" prefWidth="230.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> <HBox.margin> <Insets left="50.0" /> </HBox.margin> @@ -34,7 +35,7 @@ <Font name="System Bold" size="14.0" /> </font> </Label> - <Slider blockIncrement="1.0" majorTickUnit="1.0" max="10.0" min="3.0" minorTickCount="0" prefHeight="44.0" prefWidth="233.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> + <Slider fx:id="sliderNumberOfStartingCards" blockIncrement="1.0" majorTickUnit="1.0" max="10.0" min="3.0" minorTickCount="0" prefHeight="44.0" prefWidth="233.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> <HBox.margin> <Insets left="50.0" /> </HBox.margin> @@ -54,7 +55,7 @@ <Insets /> </HBox.margin> </Label> - <Slider blockIncrement="1.0" majorTickUnit="1.0" max="4.0" min="1.0" minorTickCount="0" prefHeight="44.0" prefWidth="233.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> + <Slider fx:id="sliderAISpeed" blockIncrement="1.0" majorTickUnit="1.0" max="4.0" min="1.0" minorTickCount="0" prefHeight="44.0" prefWidth="233.0" showTickLabels="true" showTickMarks="true" snapToTicks="true"> <HBox.margin> <Insets left="50.0" /> </HBox.margin> @@ -64,7 +65,45 @@ <Insets top="25.0" /> </VBox.margin> </HBox> + <HBox prefHeight="44.0" prefWidth="412.0"> + <children> + <Label alignment="TOP_RIGHT" contentDisplay="TOP" prefHeight="20.0" prefWidth="150.0" text="Regeln:"> + <font> + <Font name="System Bold" size="14.0" /> + </font> + <HBox.margin> + <Insets /> + </HBox.margin> + </Label> + <VBox> + <HBox.margin> + <Insets left="50.0" /> + </HBox.margin> + <children> + <CheckBox fx:id="checkBoxRule1" mnemonicParsing="false" text="+2 Karten können verlängert werden" /> + <CheckBox fx:id="checkBoxRule2" mnemonicParsing="false" text="+4 Karten können mit +2 Karten verlängert werden"> + <VBox.margin> + <Insets top="10.0" /> + </VBox.margin> + </CheckBox> + <CheckBox fx:id="checkBoxRule3" mnemonicParsing="false" text="+4 Karten können mit +4 Karten verlängert werden"> + <VBox.margin> + <Insets top="10.0" /> + </VBox.margin> + </CheckBox> + </children> + </VBox> + </children> + <VBox.margin> + <Insets top="25.0" /> + </VBox.margin> + </HBox> </children> </VBox> + <Button layoutX="264.0" layoutY="348.0" mnemonicParsing="false" onAction="#save" text="Speichern"> + <font> + <Font name="System Bold" size="12.0" /> + </font> + </Button> </children> </AnchorPane> diff --git a/src/application/Settings.java b/src/application/Settings.java new file mode 100644 index 0000000000000000000000000000000000000000..1fa40c7172cf01078d5c22a4a889120ad0ba506c --- /dev/null +++ b/src/application/Settings.java @@ -0,0 +1,116 @@ +package application; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +import tools.PathUtils; + +public class Settings implements Serializable +{ + private int numberOfAIs; + private int numberOfStartingCards; + private int aiSpeed; + private boolean allowChallengePlusTwo; + private boolean allowChallengePlusFourWithTwo; + private boolean allowChallengePlusFourWithFour; + + private static final long serialVersionUID = 1L; + + + public Settings(int numberOfAIs, int numberOfStartingCards, int aiSpeed, boolean allowChallengePlusTwo, boolean allowChallengePlusFourWithTwo, boolean allowChallengePlusFourWithFour) + { + this.numberOfAIs = numberOfAIs; + this.numberOfStartingCards = numberOfStartingCards; + this.aiSpeed = aiSpeed; + this.allowChallengePlusTwo = allowChallengePlusTwo; + this.allowChallengePlusFourWithTwo = allowChallengePlusFourWithTwo; + this.allowChallengePlusFourWithFour = allowChallengePlusFourWithFour; + } + + public Settings() + { + PathUtils.checkFolder(new File(System.getenv("APPDATA") + "/Deadlocker/UNO/")); + File file = new File(System.getenv("APPDATA") + "/Deadlocker/UNO/settings.config"); + if(!file.exists()) + { + createStandardValues(); + try + { + save(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + } + + public void createStandardValues() + { + numberOfAIs = 1; + numberOfStartingCards = 7; + aiSpeed = 2; + allowChallengePlusTwo = false; + allowChallengePlusFourWithTwo = false; + allowChallengePlusFourWithFour = false; + } + + public void save() throws Exception + { + FileOutputStream fileOut = new FileOutputStream(System.getenv("APPDATA") + "/Deadlocker/UNO/settings.config"); + ObjectOutputStream out = new ObjectOutputStream(fileOut); + out.writeObject(this); + out.close(); + fileOut.close(); + } + + public void load() throws Exception + { + FileInputStream fileIn = new FileInputStream(System.getenv("APPDATA") + "/Deadlocker/UNO/settings.config"); + ObjectInputStream in = new ObjectInputStream(fileIn); + Settings loaded = (Settings) in.readObject(); + in.close(); + fileIn.close(); + + this.numberOfAIs = loaded.getNumberOfAIs(); + this.numberOfStartingCards = loaded.getNumberOfStartingCards(); + this.aiSpeed = loaded.getAiSpeed(); + this.allowChallengePlusTwo = loaded.isAllowChallengePlusTwo(); + this.allowChallengePlusFourWithTwo = loaded.isAllowChallengePlusFourWithTwo(); + this.allowChallengePlusFourWithFour = loaded.isAllowChallengePlusFourWithFour(); + } + + public int getNumberOfAIs() + { + return numberOfAIs; + } + + public int getNumberOfStartingCards() + { + return numberOfStartingCards; + } + + public int getAiSpeed() + { + return aiSpeed; + } + + public boolean isAllowChallengePlusTwo() + { + return allowChallengePlusTwo; + } + + public boolean isAllowChallengePlusFourWithTwo() + { + return allowChallengePlusFourWithTwo; + } + + public boolean isAllowChallengePlusFourWithFour() + { + return allowChallengePlusFourWithFour; + } +} diff --git a/src/application/SettingsController.java b/src/application/SettingsController.java new file mode 100644 index 0000000000000000000000000000000000000000..476bc7a4ea082378417579564cb95767933d211e --- /dev/null +++ b/src/application/SettingsController.java @@ -0,0 +1,100 @@ +package application; + +import javafx.fxml.FXML; +import javafx.scene.control.CheckBox; +import javafx.scene.control.Slider; +import javafx.stage.Stage; +import javafx.util.StringConverter; + +public class SettingsController +{ + @FXML private Slider sliderNumberOfAIs; + @FXML private Slider sliderNumberOfStartingCards; + @FXML private Slider sliderAISpeed; + @FXML private CheckBox checkBoxRule1; + @FXML private CheckBox checkBoxRule2; + @FXML private CheckBox checkBoxRule3; + + private Stage stage; + private Controller controller; + + public void init(Stage stage, Controller controller) + { + this.stage = stage; + this.controller = controller; + sliderAISpeed.setLabelFormatter(new StringConverter<Double>() + { + @Override + public String toString(Double n) + { + if(n < 1.5) + return "Langsam"; + if(n < 2.5) + return "Mittel"; + if(n < 3.5) + return "Schnell"; + + return "Sehr Schnell"; + } + + @Override + public Double fromString(String s) + { + switch(s) + { + case "Langsam": + return 1d; + case "Mittel": + return 2d; + case "Schnell": + return 3d; + + default: + return 4d; + } + } + }); + + Settings settings = controller.settings; + + sliderNumberOfAIs.setValue((double)settings.getNumberOfAIs()); + sliderNumberOfStartingCards.setValue((double)settings.getNumberOfStartingCards()); + sliderAISpeed.setValue((double)settings.getAiSpeed()); + checkBoxRule1.setSelected(settings.isAllowChallengePlusTwo()); + checkBoxRule2.setSelected(settings.isAllowChallengePlusFourWithTwo()); + checkBoxRule3.setSelected(settings.isAllowChallengePlusFourWithFour()); + + + // stage.setOnCloseRequest(new EventHandler<WindowEvent>() + // { + // @Override + // public void handle(WindowEvent event) + // { + // event.consume(); + // } + // }); + } + + public void save() + { + int numberOfAIs = (int)sliderNumberOfAIs.getValue(); + int numberOfStartingCards = (int)sliderNumberOfStartingCards.getValue(); + int aiSpeed = (int)sliderAISpeed.getValue(); + + boolean allowChallengePlusTwo = checkBoxRule1.isSelected(); + boolean allowChallengePlusFourWithTwo = checkBoxRule2.isSelected(); + boolean allowChallengePlusFourWithFour = checkBoxRule3.isSelected(); + + controller.settings = new Settings(numberOfAIs, numberOfStartingCards, aiSpeed, allowChallengePlusTwo, allowChallengePlusFourWithTwo, allowChallengePlusFourWithFour); + try + { + controller.settings.save(); + controller.settings.load(); + } + catch(Exception e) + { + e.printStackTrace(); + } + stage.close(); + } +} \ No newline at end of file diff --git a/src/logic/Game.java b/src/logic/Game.java index d55a95b962c5d82ec52a897e0851640242de653c..4cd3fc82b4e40e50cb172d6d5df384af58c386c5 100644 --- a/src/logic/Game.java +++ b/src/logic/Game.java @@ -27,10 +27,12 @@ public class Game private int counter; private boolean running; private boolean showingInfo; + private int aiSpeed; - public Game(Controller controller, int numberOfAIs) + public Game(Controller controller, int numberOfAIs, int aiSpeed) { this.controller = controller; + this.aiSpeed = aiSpeed; deck = new Deck(); deadDeck = new DeadDeck(); player = new Player("Spieler", this); @@ -182,7 +184,18 @@ public class Game try { - Thread.sleep(500); + switch(aiSpeed) + { + case 1: Thread.sleep(500); + break; + case 2: Thread.sleep(250); + break; + case 3: Thread.sleep(50); + break; + case 4: Thread.sleep(0); + break; + default: break; + } } catch(InterruptedException e) { @@ -236,7 +249,7 @@ public class Game private void end(String name) { controller.clearAllDecks(ais); - + controller.clearAll(); System.err.println("Player " + name + " wins!"); running = false; @@ -267,8 +280,6 @@ public class Game dialogStage.getIcons().add(controller.icon); alert.show(); } - - } public Deck getDeck()