diff --git a/class/application/ColorChooserController$1.class b/class/application/ColorChooserController$1.class index 85395f688ebd45b8f0700226b84bc5c7cf105513..1c74f38cb7e934d7b98bdfd7a02d5b30867b2c5c 100644 Binary files a/class/application/ColorChooserController$1.class and b/class/application/ColorChooserController$1.class differ diff --git a/class/application/ColorChooserController$2.class b/class/application/ColorChooserController$2.class index fc6c75929efa6cda63727bb7e002f61112616edc..e993f20f323a2112ddccc48f8d6cf74a25cf095b 100644 Binary files a/class/application/ColorChooserController$2.class and b/class/application/ColorChooserController$2.class differ diff --git a/class/application/ColorChooserController$3.class b/class/application/ColorChooserController$3.class index 5230175f9388b5b1ab8302573a7f15d4ca958bd8..484b5d94df7df823b4b43eb0e6b17709ff07a4d1 100644 Binary files a/class/application/ColorChooserController$3.class and b/class/application/ColorChooserController$3.class differ diff --git a/class/application/ColorChooserController$4.class b/class/application/ColorChooserController$4.class index a3193630ce7f52340aabead89fafc6e35d77d3e1..f34045217f30e2017f9c3e5af9ff8c033bf52a91 100644 Binary files a/class/application/ColorChooserController$4.class and b/class/application/ColorChooserController$4.class differ diff --git a/class/application/ColorChooserController$5.class b/class/application/ColorChooserController$5.class new file mode 100644 index 0000000000000000000000000000000000000000..aa0538e290b67fff8b8ac17023452860e8e0cb5e Binary files /dev/null and b/class/application/ColorChooserController$5.class differ diff --git a/class/application/ColorChooserController.class b/class/application/ColorChooserController.class index ba11f7c2f89e2ed9473d440537ec127f2ec99b69..1378dc08149456c94e4e45105791504745ea56aa 100644 Binary files a/class/application/ColorChooserController.class and b/class/application/ColorChooserController.class differ diff --git a/class/application/Controller$1.class b/class/application/Controller$1.class index 5f739f9a5a101f6660e74bcd18fc309a2e51c369..1e159b04bcc10e758a54a6ad35ca4ba9fa4b5df2 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 a0aa43b035592b38636ea5ba4e940b4eadbfcad3..8772805082f719d2f4069e28ab38c667cdc86f64 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 4110b5483de2867c4528fd4f6ee2bd18a4a22fed..5af37a53a20cac3ee4c586dd3c0da87139da798f 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 bccccc2fa9f7fb94a704391dfd153344a519d915..83d0a0d6d7d5d44b27d64481536e0e22438f65a6 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 new file mode 100644 index 0000000000000000000000000000000000000000..50f44e4cf0791a6e12b8034d9836a60254a4090e Binary files /dev/null and b/class/application/Controller$5.class differ diff --git a/class/application/Controller$6.class b/class/application/Controller$6.class new file mode 100644 index 0000000000000000000000000000000000000000..3bf96ae40a12298d8a832db127f13f189970680a Binary files /dev/null and b/class/application/Controller$6.class differ diff --git a/class/application/Controller$7.class b/class/application/Controller$7.class new file mode 100644 index 0000000000000000000000000000000000000000..2eaef6fcc54693b6cfbb760248ece358e8144d99 Binary files /dev/null and b/class/application/Controller$7.class differ diff --git a/class/application/Controller$8.class b/class/application/Controller$8.class new file mode 100644 index 0000000000000000000000000000000000000000..f0bab148e9474b147897c65235e50a0deb680447 Binary files /dev/null and b/class/application/Controller$8.class differ diff --git a/class/application/Controller.class b/class/application/Controller.class index 5dd6d2b17b27bddd18875d2c7a9482104c43abe2..02b838e5e9596bac1ddb95e100477043cbca5fd7 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 1f8389d7ab360c6c97e78972a18cef74c369315b..08935e4292693a679681f849b984d2e497e64a36 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 3d499e5acfde1dddf77acd7dd766f95f7eab4863..e4034b73ab3be3bd61c0fba252faf4d57a56802b 100644 --- a/class/application/MainGUI.fxml +++ b/class/application/MainGUI.fxml @@ -1,25 +1,74 @@ <?xml version="1.0" encoding="UTF-8"?> +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> <?import javafx.scene.shape.Circle?> <?import javafx.scene.text.Font?> -<AnchorPane fx:id="mainPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller"> +<AnchorPane fx:id="mainPane" prefHeight="650.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller"> <children> - <ImageView fx:id="iconDeck" fitHeight="90.0" fitWidth="57.0" layoutX="447.0" layoutY="230.0" pickOnBounds="true" preserveRatio="true" /> - <ImageView fx:id="iconLastCard" fitHeight="90.0" fitWidth="57.0" layoutX="277.0" layoutY="230.0" pickOnBounds="true" preserveRatio="true" /> - <Label fx:id="labelCurrentPlayer" alignment="CENTER" contentDisplay="CENTER" layoutX="320.0" layoutY="377.0" prefHeight="31.0" prefWidth="162.0" textAlignment="CENTER"> + <ImageView fx:id="iconDeck" fitHeight="90.0" fitWidth="57.0" layoutX="447.0" layoutY="253.0" pickOnBounds="true" preserveRatio="true" /> + <ImageView fx:id="iconLastCard" fitHeight="90.0" fitWidth="57.0" layoutX="277.0" layoutY="253.0" pickOnBounds="true" preserveRatio="true" /> + <Label fx:id="labelCurrentPlayer" alignment="CENTER" contentDisplay="CENTER" layoutX="250.0" layoutY="420.0" prefHeight="31.0" prefWidth="286.0" textAlignment="CENTER"> <font> <Font name="System Bold" size="19.0" /> </font> </Label> - <Circle fx:id="circleWishColor" fill="DODGERBLUE" layoutX="392.0" layoutY="275.0" radius="16.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" /> - <Label fx:id="labelWishColor" layoutX="355.0" layoutY="230.0" text="Wunschfarbe"> + <Circle fx:id="circleWishColor" fill="DODGERBLUE" layoutX="392.0" layoutY="298.0" radius="16.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" /> + <Label fx:id="labelWishColor" layoutX="355.0" layoutY="253.0" text="Wunschfarbe"> <font> <Font name="System Bold" size="12.0" /> </font> </Label> + <ImageView fx:id="imageViewWishColor" fitHeight="40.0" fitWidth="40.0" layoutX="372.0" layoutY="278.0" pickOnBounds="true" preserveRatio="true" /> + <HBox fx:id="hboxInfo" alignment="CENTER" layoutX="207.0" layoutY="611.0" prefHeight="25.0" prefWidth="338.0"> + <children> + <Label fx:id="labelInfo" alignment="CENTER" contentDisplay="CENTER" prefHeight="30.0" prefWidth="255.0" text="Du kannst nicht kontern. Ziehe xx Karten." textAlignment="CENTER"> + <font> + <Font name="System Bold" size="13.0" /> + </font> + </Label> + <Button fx:id="buttonInfo" mnemonicParsing="false" text="OK"> + <HBox.margin> + <Insets left="15.0" /> + </HBox.margin> + </Button> + </children> + </HBox> + <Label fx:id="labelChallengeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="297.0" layoutY="352.0" prefHeight="17.0" prefWidth="190.0" text="Verlierer zieht 12 Karten" textAlignment="CENTER"> + <font> + <Font name="System Bold" size="14.0" /> + </font> + </Label> + <ImageView fx:id="imageViewDirection" fitHeight="30.0" fitWidth="30.0" layoutX="543.0" layoutY="282.0" pickOnBounds="true" preserveRatio="true" /> + <Label fx:id="labelDirection" layoutX="520.0" layoutY="252.0" text="Spielrichtung:"> + <font> + <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"> + <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"> + <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"> + <font> + <Font name="System Bold" size="13.0" /> + </font> + </Label> + <Button fx:id="buttonStart" layoutX="360.0" layoutY="390.0" mnemonicParsing="false" text="START"> + <font> + <Font name="System Bold" size="14.0" /> + </font> + </Button> </children> </AnchorPane> diff --git a/class/application/Settings.fxml b/class/application/Settings.fxml new file mode 100644 index 0000000000000000000000000000000000000000..e8b4a5e6b117a27e5152586b8648340e0407fe4b --- /dev/null +++ b/class/application/Settings.fxml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.Slider?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> +<?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"> + <children> + <VBox layoutX="45.0" layoutY="40.0" prefHeight="320.0" prefWidth="511.0"> + <children> + <HBox prefHeight="44.0" prefWidth="412.0"> + <children> + <Label alignment="TOP_RIGHT" contentDisplay="TOP" prefHeight="20.0" prefWidth="150.0" text="Gegner:" textAlignment="RIGHT"> + <font> + <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"> + <HBox.margin> + <Insets left="50.0" /> + </HBox.margin> + </Slider> + </children> + </HBox> + <HBox prefHeight="44.0" prefWidth="412.0"> + <children> + <Label alignment="TOP_RIGHT" contentDisplay="TOP" prefHeight="20.0" prefWidth="150.0" text="Startkarten:"> + <font> + <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"> + <HBox.margin> + <Insets left="50.0" /> + </HBox.margin> + </Slider> + </children> + <VBox.margin> + <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="Gegner Schnelligkeit:"> + <font> + <Font name="System Bold" size="14.0" /> + </font> + <HBox.margin> + <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"> + <HBox.margin> + <Insets left="50.0" /> + </HBox.margin> + </Slider> + </children> + <VBox.margin> + <Insets top="25.0" /> + </VBox.margin> + </HBox> + </children> + </VBox> + </children> +</AnchorPane> diff --git a/class/images/DIRECTION_LEFT.png b/class/images/DIRECTION_LEFT.png new file mode 100644 index 0000000000000000000000000000000000000000..706648400fff06bf709c5d7043d0ad5110883dea Binary files /dev/null and b/class/images/DIRECTION_LEFT.png differ diff --git a/class/images/DIRECTION_RIGHT.png b/class/images/DIRECTION_RIGHT.png new file mode 100644 index 0000000000000000000000000000000000000000..40ed3602ff3ff41be31c8decdd24ebdde5f3c1f5 Binary files /dev/null and b/class/images/DIRECTION_RIGHT.png differ diff --git a/class/images/circle-all.png b/class/images/circle-all.png new file mode 100644 index 0000000000000000000000000000000000000000..52aaf07c8cb4b4e6963f47c806155d9b3078b52e Binary files /dev/null and b/class/images/circle-all.png differ diff --git a/class/logic/AI.class b/class/logic/AI.class index 68664ed635474773ba6a443f1bf0ad73a92f5fe3..df353ee3ae663b8b959e6662320e38974158bf54 100644 Binary files a/class/logic/AI.class and b/class/logic/AI.class differ diff --git a/class/logic/Deck.class b/class/logic/Deck.class index 99c39a2a9fc6e052f2d75d33bbdc907f736e4020..284a93fb80529382331825a609ac3c30afdc8008 100644 Binary files a/class/logic/Deck.class and b/class/logic/Deck.class differ diff --git a/class/logic/Game.class b/class/logic/Game.class index 8ae00fbb42cdc13ac97f064a4ffbb982b656d220..96d0da5970d79a85319aa8ca68ad9face9bcbbc4 100644 Binary files a/class/logic/Game.class and b/class/logic/Game.class differ diff --git a/class/logic/Player.class b/class/logic/Player.class index a991580beea6eb679688e8daee102f1c1ff3f109..64d765b10b80130190a1a0418170d1fa24fbc3e7 100644 Binary files a/class/logic/Player.class and b/class/logic/Player.class differ diff --git a/src/application/ColorChooserController.java b/src/application/ColorChooserController.java index 3dd0f96526bf1a9a3867900c047c65c91b3ef16f..4bf9af666ccd7b2f169d4db9ae21dda896ad383e 100644 --- a/src/application/ColorChooserController.java +++ b/src/application/ColorChooserController.java @@ -5,6 +5,7 @@ import javafx.fxml.FXML; import javafx.scene.input.MouseEvent; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; +import javafx.stage.WindowEvent; import logic.Color; public class ColorChooserController @@ -57,6 +58,13 @@ public class ColorChooserController } }); - //TODO prevent closing without choosing a color --> but cancel button + stage.setOnCloseRequest(new EventHandler<WindowEvent>() + { + @Override + public void handle(WindowEvent event) + { + event.consume(); + } + }); } } \ No newline at end of file diff --git a/src/application/Controller.java b/src/application/Controller.java index 18552430b26200e4539b79cfd27b6089f81c6405..510ebe8507c2a4a974e65b78bf971438157d58fd 100644 --- a/src/application/Controller.java +++ b/src/application/Controller.java @@ -20,12 +20,14 @@ import javafx.scene.Scene; import javafx.scene.SnapshotParameters; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.image.WritableImage; import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.HBox; import javafx.scene.shape.Circle; import javafx.stage.Modality; import javafx.stage.Stage; @@ -34,7 +36,9 @@ import logic.AI; import logic.Card; import logic.CardType; import logic.Color; +import logic.Direction; import logic.Game; +import logic.Player; public class Controller { @@ -44,99 +48,233 @@ public class Controller @FXML private AnchorPane mainPane; @FXML private Label labelWishColor; @FXML private Circle circleWishColor; + @FXML private ImageView imageViewWishColor; + @FXML private HBox hboxInfo; + @FXML private Label labelInfo; + @FXML private Button buttonInfo; + @FXML private Label labelChallengeCounter; + @FXML private ImageView imageViewDirection; + @FXML private Label labelDirection; + @FXML private Label labelAI1Name; + @FXML private Label labelAI2Name; + @FXML private Label labelAI3Name; + @FXML private Button buttonStart; + public Game game; public Color chosenWishColor; + public int drawCounter; public Stage stage; public Image icon = new Image("images/icon.png"); private final ResourceBundle bundle = ResourceBundle.getBundle("application/", Locale.GERMANY); - + private final double CARD_HEIGHT = 90.0; - private final double CARD_WIDTH = 57.0; - private final double CARD_SPACING_HORIZONTAL_LARGE = 14.0; - private final double CARD_SPACING_HORIZONTAL_MEDIUM = -3.0; - private final double CARD_SPACING_HORIZONTAL_SMALL = -25.0; - private final double CARD_SPACING_HORIZONTAL_ULTRA_SMALL = -35.0; + private final double CARD_WIDTH = 57.0; + private final double CARD_SPACING_LARGE = 14.0; + private final double CARD_SPACING_MEDIUM = - 3.0; + private final double CARD_SPACING_SMALL = - 25.0; + 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, 30.0); - + private final Point2D AI_1_STARTING_POINT = new Point2D(100.0, 50.0); + private Point2D AI_2_STARTING_POINT; + private Point2D AI_3_STARTING_POINT; + private final javafx.scene.paint.Color COLOR_YELLOW = javafx.scene.paint.Color.web("#FFAA00"); private final javafx.scene.paint.Color COLOR_RED = javafx.scene.paint.Color.web("#FF5555"); private final javafx.scene.paint.Color COLOR_BLUE = javafx.scene.paint.Color.web("#5555FD"); - private final javafx.scene.paint.Color COLOR_GREEN = javafx.scene.paint.Color.web("#55AA55"); - private final javafx.scene.paint.Color COLOR_CARD_INVALID = javafx.scene.paint.Color.web("#CCCCCC"); - - + private final javafx.scene.paint.Color COLOR_GREEN = javafx.scene.paint.Color.web("#55AA55"); + public void init() { - PLAYER_STARTING_POINT = new Point2D(100.0, stage.getScene().getHeight() - 30.0 - CARD_HEIGHT); - + 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); + iconDeck.setImage(createEmptyBackCard()); iconDeck.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { - if(game.isRunning() && game.getCurrentPlayer() == 1) + if(game.isRunning() && game.getCurrentPlayer() == 1 && !game.isShowingInfo()) { - game.getPlayer().drawCard(game.getDeck().drawCard(game.getDeadDeck())); - setPlayerDeck(game.getPlayer().getDeck()); - - // TODO move card toPlayerDeck moveCardToDeadDeck(imageView, - // card, newWishColor); - // --> in "onFinish" - game.draw(); + Card drawedCard = game.getDeck().drawCard(game.getDeadDeck()); + ArrayList<Card> allCards = new ArrayList<Card>(); + allCards.add(drawedCard); + moveCardFromDeckToPlayer(allCards); } } }); + + 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; + this.stage = stage; } public void startGame() { - hideCircleWishColor(); + hideWishColor(); + hideInfo(); + hideLabelChallengeCounter(); - // DEBUG - game = new Game(this, 1); + drawCounter = 0; + + // DEBUG + game = new Game(this, 3); + setLabelNames(game.getPlayer(), game.getAIs()); game.newGame(5); + + buttonStart.setOnAction(new EventHandler<ActionEvent>() + { + @Override + public void handle(ActionEvent event) + { + buttonStart.setVisible(false); + game.start(); + } + }); + buttonStart.setVisible(true); } + public void setLabelNames(Player player, ArrayList<AI> ais) + { + labelAI2Name.setVisible(false); + labelAI3Name.setVisible(false); + + labelAI1Name.setText(ais.get(0).getName()); + labelAI1Name.setVisible(true); + + if(ais.size() >= 2) + { + labelAI2Name.setText(ais.get(1).getName()); + labelAI2Name.setVisible(true); + } + + if(ais.size() == 3) + { + labelAI3Name.setText(ais.get(2).getName()); + labelAI3Name.setVisible(true); + } + } + + public void showCircleWishColor(Color color) { + hideImageViewWishColor(); + switch(color) { - case YELLOW: circleWishColor.setFill(COLOR_YELLOW); - break; - case RED: circleWishColor.setFill(COLOR_RED); - break; - case BLUE: circleWishColor.setFill(COLOR_BLUE); - break; - case GREEN: circleWishColor.setFill(COLOR_GREEN); - break; - case ALL: //TODO show quartered circle (all four colors) - break; - default: break; + case YELLOW: + circleWishColor.setFill(COLOR_YELLOW); + circleWishColor.setVisible(true); + break; + case RED: + circleWishColor.setFill(COLOR_RED); + circleWishColor.setVisible(true); + break; + case BLUE: + circleWishColor.setFill(COLOR_BLUE); + circleWishColor.setVisible(true); + break; + case GREEN: + circleWishColor.setFill(COLOR_GREEN); + circleWishColor.setVisible(true); + break; + case ALL: + showImageViewWishColor(); + break; + default: + break; } - + labelWishColor.setVisible(true); - circleWishColor.setVisible(true); } - + + public void showImageViewWishColor() + { + hideCircleWishColor(); + + imageViewWishColor.setVisible(true); + } + public void hideCircleWishColor() { labelWishColor.setVisible(false); - circleWishColor.setVisible(false); + circleWishColor.setVisible(false); + } + + public void hideImageViewWishColor() + { + imageViewWishColor.setVisible(false); + circleWishColor.setVisible(false); + } + + public void hideWishColor() + { + hideCircleWishColor(); + hideImageViewWishColor(); + } + + public void hideInfo() + { + hboxInfo.setVisible(false); + } + + public void showInfo(String text, int numberOfCards) + { + labelInfo.setText(text); + buttonInfo.setOnAction(new EventHandler<ActionEvent>() + { + @Override + public void handle(ActionEvent event) + { + moveCardFromDeckToPlayer(game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck())); + } + }); + + hboxInfo.setVisible(true); } + public void hideLabelChallengeCounter() + { + labelChallengeCounter.setVisible(false); + } + + public void showLabelChallengeCounter(String text) + { + labelChallengeCounter.setText(text); + labelChallengeCounter.setVisible(true); + } + + public void setImageViewDirection(Direction direction) + { + if(direction.equals(Direction.RIGHT)) + { + imageViewDirection.setImage(new Image("/images/DIRECTION_RIGHT.png")); + } + else + { + imageViewDirection.setImage(new Image("/images/DIRECTION_LEFT.png")); + } + } + public void setLabelCurrentPlayer(String text) { labelCurrentPlayer.setText(text); @@ -169,14 +307,16 @@ public class Controller if(!valid) { - WritableImage snapshot = imageView.snapshot(new SnapshotParameters(), null); - + SnapshotParameters parameters = new SnapshotParameters(); + parameters.setFill(javafx.scene.paint.Color.TRANSPARENT); + WritableImage snapshot = imageView.snapshot(parameters, null); + if(card.getType().equals(CardType.DRAW_FOUR) && card.getType().equals(CardType.WILD)) { for(int x = 0; x < snapshot.getWidth(); x++) { for(int y = 0; y < snapshot.getHeight(); y++) - { + { javafx.scene.paint.Color oldColor = snapshot.getPixelReader().getColor(x, y).desaturate().desaturate().brighter(); snapshot.getPixelWriter().setColor(x, y, new javafx.scene.paint.Color(oldColor.getRed(), oldColor.getGreen(), oldColor.getBlue(), oldColor.getOpacity() * 1.0)); } @@ -188,14 +328,13 @@ public class Controller for(int x = 0; x < snapshot.getWidth(); x++) { for(int y = 0; y < snapshot.getHeight(); y++) - { - javafx.scene.paint.Color oldColor = snapshot.getPixelReader().getColor(x, y).desaturate().desaturate().desaturate(); + { + javafx.scene.paint.Color oldColor = snapshot.getPixelReader().getColor(x, y).darker().desaturate(); snapshot.getPixelWriter().setColor(x, y, new javafx.scene.paint.Color(oldColor.getRed(), oldColor.getGreen(), oldColor.getBlue(), oldColor.getOpacity() * 1.0)); } } imageView.setImage(snapshot); } - } Controller main = this; @@ -240,7 +379,7 @@ public class Controller chosenWishColor = null; } - moveCardToDeadDeck(imageView, card, chosenWishColor); + moveCardToDeadDeck(imageView, card, chosenWishColor); } } } @@ -250,18 +389,18 @@ public class Controller } public void moveCardToDeadDeck(ImageView view, Card card, Color newWishColor) - { - Point2D deckPosition = iconLastCard.localToScene(Point2D.ZERO); - + { + Point2D deckPosition = iconLastCard.localToScene(Point2D.ZERO); + TranslateTransition translateTransition = new TranslateTransition(); translateTransition.setDuration(Duration.millis(500)); translateTransition.setNode(view); translateTransition.setCycleCount(1); - translateTransition.setAutoReverse(false); + translateTransition.setAutoReverse(false); translateTransition.setFromX(0); translateTransition.setFromY(0); - translateTransition.setToX(- (view.getX() - deckPosition.getX())); - translateTransition.setToY(- (view.getY() - deckPosition.getY())); + translateTransition.setToX( - (view.getX() - deckPosition.getX())); + translateTransition.setToY( - (view.getY() - deckPosition.getY())); translateTransition.setOnFinished(new EventHandler<ActionEvent>() { @Override @@ -273,10 +412,10 @@ public class Controller } else { - hideCircleWishColor(); + hideWishColor(); } setPlayerDeck(game.getPlayer().getDeck()); - game.playCard(game.getPlayer().playCard(card), newWishColor); + game.playCard(game.getPlayer().playCard(card), newWishColor); } }); @@ -286,33 +425,33 @@ public class Controller public void moveAICardToDeadDeck(AI ai, int currentPlayer, Card card, Color newWishColor) { ObservableList<Node> nodes = mainPane.getChildren(); - ArrayList<Integer> possibleNodes = new ArrayList<Integer>(); - for(int i = 0; i < nodes.size(); i++) + ArrayList<Integer> possibleNodes = new ArrayList<Integer>(); + for(int i = 0; i < nodes.size(); i++) { - Node current = nodes.get(i); + Node current = nodes.get(i); if(current.getId().contains("ai" + ai.getID())) - { - possibleNodes.add(i); + { + possibleNodes.add(i); } - } - + } + Random random = new Random(); - int viewNumber = random.nextInt(possibleNodes.size()); + int viewNumber = random.nextInt(possibleNodes.size()); - ImageView view = (ImageView)mainPane.getChildren().get(possibleNodes.get(viewNumber)); - view.setImage(new Image("images/" + card.getType() + "-" + card.getColor() + ".png")); + ImageView view = (ImageView)mainPane.getChildren().get(possibleNodes.get(viewNumber)); + view.setImage(new Image("images/" + card.getType() + "-" + card.getColor() + ".png")); + + Point2D deckPosition = iconLastCard.localToScene(Point2D.ZERO); - Point2D deckPosition = iconLastCard.localToScene(Point2D.ZERO); - TranslateTransition translateTransition = new TranslateTransition(); translateTransition.setDuration(Duration.millis(500)); translateTransition.setNode(view); translateTransition.setCycleCount(1); - translateTransition.setAutoReverse(false); + translateTransition.setAutoReverse(false); translateTransition.setFromX(0); translateTransition.setFromY(0); - translateTransition.setToX(- (view.getX() - deckPosition.getX())); - translateTransition.setToY(- (view.getY() - deckPosition.getY())); + translateTransition.setToX( - (view.getX() - deckPosition.getX())); + translateTransition.setToY( - (view.getY() - deckPosition.getY())); translateTransition.setOnFinished(new EventHandler<ActionEvent>() { @Override @@ -324,21 +463,234 @@ public class Controller } else { - hideCircleWishColor(); + hideWishColor(); } - setAIDeck(ai, ai.getDeck()); + setAIDeck(ai); game.playCard(ai.playCard(card), newWishColor); } }); - translateTransition.play(); + translateTransition.play(); } + public void moveCardFromDeckToPlayer(ArrayList<Card> cards) + { + Point2D deckPosition = iconDeck.localToScene(Point2D.ZERO); + + ImageView view = createCard(cards.get(drawCounter), true); + view.setId("drawAnimation"); + view.setX(deckPosition.getX()); + view.setY(deckPosition.getY()); + mainPane.getChildren().add(view); + + TranslateTransition translateTransition = new TranslateTransition(); + translateTransition.setDuration(Duration.millis(500)); + translateTransition.setNode(view); + translateTransition.setCycleCount(1); + translateTransition.setAutoReverse(false); + translateTransition.setFromX(0); + translateTransition.setFromY(0); + translateTransition.setToX( - (view.getX() - getPositionOfRightCard(null))); + translateTransition.setToY( - (view.getY() - PLAYER_STARTING_POINT.getY())); + translateTransition.setOnFinished(new EventHandler<ActionEvent>() + { + @Override + public void handle(ActionEvent event) + { + ObservableList<Node> nodes = mainPane.getChildren(); + Iterator<Node> iterator = nodes.iterator(); + while(iterator.hasNext()) + { + if(iterator.next().getId().equals("drawAnimation")) + { + iterator.remove(); + } + } + + game.getPlayer().drawCard(cards.get(drawCounter)); + setPlayerDeck(game.getPlayer().getDeck()); + drawCounter++; + + if(drawCounter < cards.size()) + { + moveCardFromDeckToPlayer(cards); + } + else + { + game.setShowingInfo(false); + hideInfo(); + drawCounter = 0; + game.draw(); + } + } + }); + + translateTransition.play(); + } + + private double getPositionOfRightCard(AI ai) + { + if(ai == null) + { + double maxWidth = stage.getScene().getWidth() - (PLAYER_STARTING_POINT.getX() * 2) - CARD_WIDTH; + int deckSize = game.getPlayer().getDeckSize(); + if((deckSize * (CARD_WIDTH + CARD_SPACING_LARGE)) > maxWidth) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_MEDIUM)) > maxWidth) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_SMALL)) > maxWidth) + { + return (PLAYER_STARTING_POINT.getX() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_ULTRA_SMALL))); + } + else + { + return (PLAYER_STARTING_POINT.getX() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_SMALL))); + } + } + else + { + return (PLAYER_STARTING_POINT.getX() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_MEDIUM))); + } + } + else + { + return (PLAYER_STARTING_POINT.getX() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_LARGE))); + } + } + //AI 1 (Above Player) + else + { + double maxWidth = stage.getScene().getWidth() - (AI_1_STARTING_POINT.getX() * 2) - CARD_WIDTH; + int deckSize = ai.getDeckSize(); + if((deckSize * (CARD_WIDTH + CARD_SPACING_LARGE)) > maxWidth) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_MEDIUM)) > maxWidth) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_SMALL)) > maxWidth) + { + return (AI_1_STARTING_POINT.getX() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_ULTRA_SMALL))); + } + else + { + return (AI_1_STARTING_POINT.getX() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_SMALL))); + } + } + else + { + return (AI_1_STARTING_POINT.getX() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_MEDIUM))); + } + } + else + { + return (AI_1_STARTING_POINT.getX() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_LARGE))); + } + } + } + + private double getPositionOfBottomCard(AI ai) + { + double maxHeight = stage.getScene().getHeight() - ((AI_2_STARTING_POINT.getY() + 50.0) * 2) - CARD_WIDTH; + int deckSize = ai.getDeckSize(); + + if((deckSize * (CARD_WIDTH + CARD_SPACING_LARGE)) > maxHeight) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_MEDIUM)) > maxHeight) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_SMALL)) > maxHeight) + { + return AI_2_STARTING_POINT.getY() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_ULTRA_SMALL)); + } + else + { + return AI_2_STARTING_POINT.getY() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_SMALL)); + } + } + else + { + return AI_2_STARTING_POINT.getY() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_MEDIUM)); + } + } + else + { + return AI_2_STARTING_POINT.getY() + ((deckSize + 1) * (CARD_WIDTH + CARD_SPACING_LARGE)); + } + } + + public void moveCardFromDeckToAI(AI ai, ArrayList<Card> cards) + { + Card card = game.getDeck().drawCard(game.getDeadDeck()); + + Point2D deckPosition = iconDeck.localToScene(Point2D.ZERO); + + ImageView view = createBackCard(); + view.setId("drawAnimation"); + view.setX(deckPosition.getX()); + view.setY(deckPosition.getY()); + mainPane.getChildren().add(view); + + TranslateTransition translateTransition = new TranslateTransition(); + translateTransition.setDuration(Duration.millis(500)); + translateTransition.setNode(view); + translateTransition.setCycleCount(1); + translateTransition.setAutoReverse(false); + translateTransition.setFromX(0); + translateTransition.setFromY(0); + + switch(ai.getID()) + { + case 1: translateTransition.setToX( - (view.getX() - getPositionOfRightCard(ai))); + translateTransition.setToY( - (view.getY() - AI_1_STARTING_POINT.getY())); + break; + case 2: translateTransition.setToX( - (view.getX() - AI_2_STARTING_POINT.getX())); + translateTransition.setToY( - (view.getY() - getPositionOfBottomCard(ai))); + break; + case 3: translateTransition.setToX( - (view.getX() - AI_3_STARTING_POINT.getX())); + translateTransition.setToY( - (view.getY() - getPositionOfBottomCard(ai))); + break; + default: break; + } + + translateTransition.setOnFinished(new EventHandler<ActionEvent>() + { + @Override + public void handle(ActionEvent event) + { + ObservableList<Node> nodes = mainPane.getChildren(); + Iterator<Node> iterator = nodes.iterator(); + while(iterator.hasNext()) + { + if(iterator.next().getId().equals("drawAnimation")) + { + iterator.remove(); + } + } + + ai.drawCard(cards.get(drawCounter)); + setAIDeck(ai); + drawCounter++; + + if(drawCounter < cards.size()) + { + moveCardFromDeckToAI(ai, cards); + } + else + { + game.setShowingInfo(false); + hideInfo(); + drawCounter = 0; + game.draw(); + } + } + }); + + translateTransition.play(); + } + public void clearPlayerDeck() { ObservableList<Node> nodes = mainPane.getChildren(); Iterator<Node> iterator = nodes.iterator(); - while(iterator.hasNext()) + while(iterator.hasNext()) { if(iterator.next().getId().equals("player")) { @@ -348,42 +700,44 @@ public class Controller } public void setPlayerDeck(ArrayList<Card> deck) - { + { clearPlayerDeck(); - + int counter = 1; - + for(Card currentCard : deck) { ImageView current = createCard(currentCard, true); - + current.setId("player"); mainPane.getChildren().add(current); - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE)) > (stage.getScene().getWidth() - PLAYER_STARTING_POINT.getX() * 2)) + + double maxWidth = stage.getScene().getWidth() - (PLAYER_STARTING_POINT.getX() * 2) - CARD_WIDTH; + if((deck.size() * (CARD_WIDTH + CARD_SPACING_LARGE)) > maxWidth) { - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM)) > (stage.getScene().getWidth() - PLAYER_STARTING_POINT.getX() * 2)) + if((deck.size() * (CARD_WIDTH + CARD_SPACING_MEDIUM)) > maxWidth) { - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL)) > (stage.getScene().getWidth() - PLAYER_STARTING_POINT.getX() * 2)) + if((deck.size() * (CARD_WIDTH + CARD_SPACING_SMALL)) > maxWidth) { - current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_ULTRA_SMALL))); + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_ULTRA_SMALL))); } else { - current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL))); + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_SMALL))); } } else { - current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM))); + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_MEDIUM))); } } else { - current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE))); + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_LARGE))); } - - current.setY(PLAYER_STARTING_POINT.getY()); - + + current.setY(PLAYER_STARTING_POINT.getY()); + counter++; } } @@ -391,62 +745,62 @@ public class Controller public void setValidPlayerDeck(ArrayList<Card> deck, ArrayList<Card> validDeck) { clearPlayerDeck(); - + int counter = 1; - + for(Card currentCard : deck) { ImageView current; - + if(validDeck.contains(currentCard)) { current = createCard(currentCard, true); + current.setY(PLAYER_STARTING_POINT.getY() - CARD_HEIGHT/4); } else { current = createCard(currentCard, false); + current.setY(PLAYER_STARTING_POINT.getY()); } - + current.setId("player"); mainPane.getChildren().add(current); - + double maxWidth = stage.getScene().getWidth() - (PLAYER_STARTING_POINT.getX() * 2) - CARD_WIDTH; - - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE)) > maxWidth) + + if((deck.size() * (CARD_WIDTH + CARD_SPACING_LARGE)) > maxWidth) { - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM)) > maxWidth) + if((deck.size() * (CARD_WIDTH + CARD_SPACING_MEDIUM)) > maxWidth) { - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL)) > maxWidth) + if((deck.size() * (CARD_WIDTH + CARD_SPACING_SMALL)) > maxWidth) { - current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_ULTRA_SMALL))); + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_ULTRA_SMALL))); } else { - current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL))); + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_SMALL))); } } else { - current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM))); + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_MEDIUM))); } } else { - current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE))); + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_LARGE))); } - current.setY(PLAYER_STARTING_POINT.getY()); - counter++; } } - + public void clearAIDeck(AI ai) { ObservableList<Node> nodes = mainPane.getChildren(); Iterator<Node> iterator = nodes.iterator(); - while(iterator.hasNext()) + while(iterator.hasNext()) { if(iterator.next().getId().contains("ai" + ai.getID())) { @@ -454,59 +808,135 @@ public class Controller } } } - - public void setAIDeck(AI ai, ArrayList<Card> deck) + + public void setAIDeck(AI ai) { clearAIDeck(ai); + ArrayList<Card> deck = ai.getDeck(); + int counter = 1; - + for(Card currentCard : deck) { ImageView current = createBackCard(); - + current.setId("ai" + ai.getID()); - //TODO other AIs (vertical) --> flip imageViews by 90 degrees mainPane.getChildren().add(current); - double maxWidth = stage.getScene().getWidth() - (AI_1_STARTING_POINT.getX() * 2) - CARD_WIDTH; - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE)) > maxWidth) - { - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM)) > maxWidth) - { - if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL)) > maxWidth) - { - current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_ULTRA_SMALL))); - } - else - { - current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL))); - } - } - else - { - current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM))); - } - } - else + double maxWidth; + double maxHeight; + int deckSize; + + switch(ai.getID()) { - current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE))); - } + case 1: maxWidth = stage.getScene().getWidth() - ((AI_1_STARTING_POINT.getX() + 25.0) * 2) - CARD_WIDTH; + deckSize = ai.getDeckSize(); + + if((deckSize * (CARD_WIDTH + CARD_SPACING_LARGE)) > maxWidth) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_MEDIUM)) > maxWidth) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_SMALL)) > maxWidth) + { + current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_ULTRA_SMALL))); + } + else + { + current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_SMALL))); + } + } + else + { + current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_MEDIUM))); + } + } + else + { + current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_LARGE))); + } + + current.setY(AI_1_STARTING_POINT.getY()); + break; + + case 2: maxHeight = stage.getScene().getHeight() - ((AI_2_STARTING_POINT.getY() + 50.0) * 2) - CARD_WIDTH; + deckSize = ai.getDeckSize(); + + current.setRotate(90.0); + + if((deckSize * (CARD_WIDTH + CARD_SPACING_LARGE)) > maxHeight) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_MEDIUM)) > maxHeight) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_SMALL)) > maxHeight) + { + current.setY(AI_2_STARTING_POINT.getY() + (counter * (CARD_WIDTH + CARD_SPACING_ULTRA_SMALL))); + } + else + { + current.setY(AI_2_STARTING_POINT.getY() + (counter * (CARD_WIDTH + CARD_SPACING_SMALL))); + } + } + else + { + current.setY(AI_2_STARTING_POINT.getY() + (counter * (CARD_WIDTH + CARD_SPACING_MEDIUM))); + } + } + else + { + current.setY(AI_2_STARTING_POINT.getY() + (counter * (CARD_WIDTH + CARD_SPACING_LARGE))); + } + + current.setX(AI_2_STARTING_POINT.getX()); + break; + + case 3: maxHeight = stage.getScene().getHeight() - ((AI_3_STARTING_POINT.getY() + 50.0) * 2) - CARD_WIDTH; + deckSize = ai.getDeckSize(); + + current.setRotate(90.0); + + if((deckSize * (CARD_WIDTH + CARD_SPACING_LARGE)) > maxHeight) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_MEDIUM)) > maxHeight) + { + if((deckSize * (CARD_WIDTH + CARD_SPACING_SMALL)) > maxHeight) + { + current.setY(AI_3_STARTING_POINT.getY() + (counter * (CARD_WIDTH + CARD_SPACING_ULTRA_SMALL))); + } + else + { + current.setY(AI_3_STARTING_POINT.getY() + (counter * (CARD_WIDTH + CARD_SPACING_SMALL))); + } + } + else + { + current.setY(AI_3_STARTING_POINT.getY() + (counter * (CARD_WIDTH + CARD_SPACING_MEDIUM))); + } + } + else + { + current.setY(AI_3_STARTING_POINT.getY() + (counter * (CARD_WIDTH + CARD_SPACING_LARGE))); + } + + current.setX(AI_3_STARTING_POINT.getX()); + break; + default: break; + } - counter++; - } + counter++; + } } - + public void clearAllDecks(ArrayList<AI> ais) { clearPlayerDeck(); - + for(AI currentAI : ais) { clearAIDeck(currentAI); - } - } + } + } public void about() { diff --git a/src/application/Main.java b/src/application/Main.java index 3729b324f9cee3c7b7e936931d68a5655851a555..0199cb4db2b939088b05853e76e93d043d7d7b27 100644 --- a/src/application/Main.java +++ b/src/application/Main.java @@ -17,7 +17,7 @@ public class Main extends Application FXMLLoader loader = new FXMLLoader(getClass().getResource("MainGUI.fxml")); Parent root = (Parent)loader.load(); - Scene scene = new Scene(root, 800, 600); + Scene scene = new Scene(root, 800, 650); stage.setResizable(true); stage.setTitle("UNO"); @@ -27,6 +27,7 @@ public class Main extends Application controller.setStage(stage); controller.init(); + //TODO set minWidth and Height stage.getIcons().add(new Image("images/icon.png")); stage.show(); } diff --git a/src/application/MainGUI.fxml b/src/application/MainGUI.fxml index 3d499e5acfde1dddf77acd7dd766f95f7eab4863..e4034b73ab3be3bd61c0fba252faf4d57a56802b 100644 --- a/src/application/MainGUI.fxml +++ b/src/application/MainGUI.fxml @@ -1,25 +1,74 @@ <?xml version="1.0" encoding="UTF-8"?> +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> <?import javafx.scene.shape.Circle?> <?import javafx.scene.text.Font?> -<AnchorPane fx:id="mainPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller"> +<AnchorPane fx:id="mainPane" prefHeight="650.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller"> <children> - <ImageView fx:id="iconDeck" fitHeight="90.0" fitWidth="57.0" layoutX="447.0" layoutY="230.0" pickOnBounds="true" preserveRatio="true" /> - <ImageView fx:id="iconLastCard" fitHeight="90.0" fitWidth="57.0" layoutX="277.0" layoutY="230.0" pickOnBounds="true" preserveRatio="true" /> - <Label fx:id="labelCurrentPlayer" alignment="CENTER" contentDisplay="CENTER" layoutX="320.0" layoutY="377.0" prefHeight="31.0" prefWidth="162.0" textAlignment="CENTER"> + <ImageView fx:id="iconDeck" fitHeight="90.0" fitWidth="57.0" layoutX="447.0" layoutY="253.0" pickOnBounds="true" preserveRatio="true" /> + <ImageView fx:id="iconLastCard" fitHeight="90.0" fitWidth="57.0" layoutX="277.0" layoutY="253.0" pickOnBounds="true" preserveRatio="true" /> + <Label fx:id="labelCurrentPlayer" alignment="CENTER" contentDisplay="CENTER" layoutX="250.0" layoutY="420.0" prefHeight="31.0" prefWidth="286.0" textAlignment="CENTER"> <font> <Font name="System Bold" size="19.0" /> </font> </Label> - <Circle fx:id="circleWishColor" fill="DODGERBLUE" layoutX="392.0" layoutY="275.0" radius="16.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" /> - <Label fx:id="labelWishColor" layoutX="355.0" layoutY="230.0" text="Wunschfarbe"> + <Circle fx:id="circleWishColor" fill="DODGERBLUE" layoutX="392.0" layoutY="298.0" radius="16.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" /> + <Label fx:id="labelWishColor" layoutX="355.0" layoutY="253.0" text="Wunschfarbe"> <font> <Font name="System Bold" size="12.0" /> </font> </Label> + <ImageView fx:id="imageViewWishColor" fitHeight="40.0" fitWidth="40.0" layoutX="372.0" layoutY="278.0" pickOnBounds="true" preserveRatio="true" /> + <HBox fx:id="hboxInfo" alignment="CENTER" layoutX="207.0" layoutY="611.0" prefHeight="25.0" prefWidth="338.0"> + <children> + <Label fx:id="labelInfo" alignment="CENTER" contentDisplay="CENTER" prefHeight="30.0" prefWidth="255.0" text="Du kannst nicht kontern. Ziehe xx Karten." textAlignment="CENTER"> + <font> + <Font name="System Bold" size="13.0" /> + </font> + </Label> + <Button fx:id="buttonInfo" mnemonicParsing="false" text="OK"> + <HBox.margin> + <Insets left="15.0" /> + </HBox.margin> + </Button> + </children> + </HBox> + <Label fx:id="labelChallengeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="297.0" layoutY="352.0" prefHeight="17.0" prefWidth="190.0" text="Verlierer zieht 12 Karten" textAlignment="CENTER"> + <font> + <Font name="System Bold" size="14.0" /> + </font> + </Label> + <ImageView fx:id="imageViewDirection" fitHeight="30.0" fitWidth="30.0" layoutX="543.0" layoutY="282.0" pickOnBounds="true" preserveRatio="true" /> + <Label fx:id="labelDirection" layoutX="520.0" layoutY="252.0" text="Spielrichtung:"> + <font> + <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"> + <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"> + <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"> + <font> + <Font name="System Bold" size="13.0" /> + </font> + </Label> + <Button fx:id="buttonStart" layoutX="360.0" layoutY="390.0" mnemonicParsing="false" text="START"> + <font> + <Font name="System Bold" size="14.0" /> + </font> + </Button> </children> </AnchorPane> diff --git a/src/application/Settings.fxml b/src/application/Settings.fxml new file mode 100644 index 0000000000000000000000000000000000000000..e8b4a5e6b117a27e5152586b8648340e0407fe4b --- /dev/null +++ b/src/application/Settings.fxml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.Slider?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> +<?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"> + <children> + <VBox layoutX="45.0" layoutY="40.0" prefHeight="320.0" prefWidth="511.0"> + <children> + <HBox prefHeight="44.0" prefWidth="412.0"> + <children> + <Label alignment="TOP_RIGHT" contentDisplay="TOP" prefHeight="20.0" prefWidth="150.0" text="Gegner:" textAlignment="RIGHT"> + <font> + <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"> + <HBox.margin> + <Insets left="50.0" /> + </HBox.margin> + </Slider> + </children> + </HBox> + <HBox prefHeight="44.0" prefWidth="412.0"> + <children> + <Label alignment="TOP_RIGHT" contentDisplay="TOP" prefHeight="20.0" prefWidth="150.0" text="Startkarten:"> + <font> + <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"> + <HBox.margin> + <Insets left="50.0" /> + </HBox.margin> + </Slider> + </children> + <VBox.margin> + <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="Gegner Schnelligkeit:"> + <font> + <Font name="System Bold" size="14.0" /> + </font> + <HBox.margin> + <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"> + <HBox.margin> + <Insets left="50.0" /> + </HBox.margin> + </Slider> + </children> + <VBox.margin> + <Insets top="25.0" /> + </VBox.margin> + </HBox> + </children> + </VBox> + </children> +</AnchorPane> diff --git a/src/images/DIRECTION_LEFT.png b/src/images/DIRECTION_LEFT.png new file mode 100644 index 0000000000000000000000000000000000000000..706648400fff06bf709c5d7043d0ad5110883dea Binary files /dev/null and b/src/images/DIRECTION_LEFT.png differ diff --git a/src/images/DIRECTION_RIGHT.png b/src/images/DIRECTION_RIGHT.png new file mode 100644 index 0000000000000000000000000000000000000000..40ed3602ff3ff41be31c8decdd24ebdde5f3c1f5 Binary files /dev/null and b/src/images/DIRECTION_RIGHT.png differ diff --git a/src/images/circle-all.png b/src/images/circle-all.png new file mode 100644 index 0000000000000000000000000000000000000000..52aaf07c8cb4b4e6963f47c806155d9b3078b52e Binary files /dev/null and b/src/images/circle-all.png differ diff --git a/src/logic/AI.java b/src/logic/AI.java index b18d3334b62e604e0328050d436a0497e65c73ef..30414e21cadb8fc83c44607b5429086c4ebaf399 100644 --- a/src/logic/AI.java +++ b/src/logic/AI.java @@ -43,13 +43,13 @@ public class AI public void drawCard(Card card) { deck.add(card); - game.getController().setAIDeck(this, deck); + game.getController().setAIDeck(this); } public void drawCards(ArrayList<Card> cards) { deck.addAll(cards); - game.getController().setAIDeck(this, deck); + game.getController().setAIDeck(this); } public Card playCard(Card card) @@ -59,19 +59,25 @@ public class AI } public ArrayList<Card> getValidCards(Card lastCard, Color wishColor, boolean challenge) - { - ArrayList<Card> validCards = new ArrayList<Card>(); - + { + ArrayList<Card> validCards = new ArrayList<Card>(); if(challenge) { for(Card currentCard : deck) - { + { if(wishColor == null) { if(currentCard.getType().equals(CardType.DRAW_TWO) || currentCard.getType().equals(CardType.DRAW_FOUR)) { validCards.add(currentCard); } + } + else if(wishColor.equals(Color.ALL)) + { + if(currentCard.getType().equals(CardType.DRAW_TWO) || currentCard.getType().equals(CardType.DRAW_FOUR)) + { + validCards.add(currentCard); + } } else { @@ -85,14 +91,23 @@ public class AI else { if(wishColor == null) + { + for(Card currentCard : deck) + { + if(currentCard.getColor().equals(lastCard.getColor()) || currentCard.getType().equals(lastCard.getType()) || currentCard.getType().equals(CardType.WILD) || currentCard.getType().equals(CardType.DRAW_FOUR)) + { + validCards.add(currentCard); + } + } + } + else if(wishColor.equals(Color.ALL)) { for(Card currentCard : deck) - { - if(currentCard.getColor().equals(lastCard.getColor()) || currentCard.getType().equals(lastCard.getType()) || currentCard.getType().equals(CardType.WILD) - || currentCard.getType().equals(CardType.DRAW_FOUR)) + { + if(!currentCard.getType().equals(CardType.WILD) && !currentCard.getType().equals(CardType.DRAW_FOUR)) { validCards.add(currentCard); - } + } } } else @@ -102,11 +117,11 @@ public class AI if(currentCard.getColor().equals(wishColor)) { validCards.add(currentCard); - } + } } - } - } - + } + } + return validCards; } @@ -134,17 +149,18 @@ public class AI { if(challenge) { - drawCards(game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck())); System.out.println("draw " + game.getChallengeCounter() + " cards"); - System.out.println("deack after draw: " + deck); - game.draw(); + ArrayList<Card> drawedCards = game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck()); + game.getController().moveCardFromDeckToAI(this, drawedCards); + System.out.println("deack after draw: " + deck); } else { - drawCard(game.getDeck().drawCard(game.getDeadDeck())); System.out.println("draw one card"); - System.out.println("deack after draw: " + deck); - game.draw(); + ArrayList<Card> drawedCards = new ArrayList<Card>(); + drawedCards.add(game.getDeck().drawCard(game.getDeadDeck())); + game.getController().moveCardFromDeckToAI(this, drawedCards); + System.out.println("deack after draw: " + deck); } } else @@ -174,7 +190,7 @@ public class AI } } - game.getController().moveAICardToDeadDeck(this,game.getCurrentPlayer(), playedCard, newWishColor); + game.getController().moveAICardToDeadDeck(this, game.getCurrentPlayer(), playedCard, newWishColor); } } diff --git a/src/logic/Deck.java b/src/logic/Deck.java index df0070893419779de0be418e1eb911e1feafb52a..766c0a3f990564f2f0a5a7ac3dd82b1d21a481ef 100644 --- a/src/logic/Deck.java +++ b/src/logic/Deck.java @@ -14,7 +14,7 @@ public class Deck for(Color currentColor : Color.values()) { - if(currentColor != Color.BLACK) + if(currentColor != Color.BLACK && currentColor != Color.ALL) { cards.add(new Card(CardType.ZERO, currentColor, 0)); @@ -92,28 +92,5 @@ public class Deck return cards; } - //TODO --> refill should let newest card of deadDeck in deadDeck - public static void main(String[] args) - { - Deck deck = new Deck(); - System.out.println(deck.getCards()); - // deck.shuffle(); - System.out.println(deck.getCards()); - System.out.println(); - - DeadDeck deadDeck = new DeadDeck(); - - for(int i = 0; i < 107; i++) - { - System.out.println(i); - - Card newCard = deck.drawCard(deadDeck); - deadDeck.add(newCard); - System.out.println(newCard); - - System.out.println(newCard.equals(new Card(CardType.DRAW_TWO, Color.RED, 0))); - } - - - } + //TODO --> refill should let newest card of deadDeck in deadDeck } \ No newline at end of file diff --git a/src/logic/Game.java b/src/logic/Game.java index 00969b31962e79d59aadf7ffd68e2c1a8550e57c..dca0ec965f836f846405a60765178335736649d1 100644 --- a/src/logic/Game.java +++ b/src/logic/Game.java @@ -3,6 +3,9 @@ package logic; import java.util.ArrayList; import java.util.Random; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.stage.Stage; import application.Controller; public class Game @@ -23,6 +26,7 @@ public class Game private boolean skipped; private int counter; private boolean running; + private boolean showingInfo; public Game(Controller controller, int numberOfAIs) { @@ -31,10 +35,22 @@ public class Game deadDeck = new DeadDeck(); player = new Player("Spieler", this); ais = new ArrayList<AI>(); - for(int i = 1; i <= numberOfAIs; i++) + + if(numberOfAIs == 1) + { + ais.add(new AI("Computer 1", 1, this)); + } + else if(numberOfAIs == 2) { - ais.add(new AI("AI " + i, i-1, this)); + ais.add(new AI("Computer 1", 1, this)); + ais.add(new AI("Computer 2", 2, this)); } + else if(numberOfAIs == 3) + { + ais.add(new AI("Computer 3", 3, this)); + ais.add(new AI("Computer 1", 1, this)); + ais.add(new AI("Computer 2", 2, this)); + } gameCount = 0; challengeCounter = 0; @@ -42,7 +58,7 @@ public class Game public void newGame(int numberOfStartingCards) { - deck = new Deck(); + deck = new Deck(); deck.shuffle(); deadDeck = new DeadDeck(); gameCount++; @@ -51,8 +67,10 @@ public class Game wishColor = null; challenge = false; direction = Direction.RIGHT; + controller.setImageViewDirection(Direction.RIGHT); lastPlayerDraw = false; skipped = false; + showingInfo = false; player.initialize(); @@ -65,16 +83,28 @@ public class Game } deadDeck.add(deck.drawCard(deadDeck)); - lastCard = deadDeck.getCards().get(deadDeck.getCards().size()-1); + lastCard = deadDeck.getCards().get(deadDeck.getCards().size()-1); + controller.setLastCard(lastCard); - if(lastCard.getType().equals(CardType.DRAW_FOUR) || lastCard.getType().equals(CardType.WILD)) + if(lastCard.getType().equals(CardType.WILD)) { wishColor = Color.ALL; controller.chosenWishColor = wishColor; controller.showCircleWishColor(wishColor); } - - start(); + else if(lastCard.getType().equals(CardType.DRAW_FOUR)) + { + wishColor = Color.ALL; + controller.chosenWishColor = wishColor; + controller.showCircleWishColor(wishColor); + challenge = true; + challengeCounter = 4; + } + else if(lastCard.getType().equals(CardType.DRAW_TWO)) + { + challenge = true; + challengeCounter = 2; + } } public int getGameCount() @@ -123,15 +153,15 @@ public class Game if(direction.equals(Direction.RIGHT)) { direction = Direction.LEFT; + controller.setImageViewDirection(Direction.LEFT); + } else { direction = Direction.RIGHT; - } - //TODO show icon direction in UI - } - - //TODO mark currentPlayer in UI + controller.setImageViewDirection(Direction.RIGHT); + } + } if(currentPlayer == 1) { @@ -148,7 +178,17 @@ public class Game controller.setLabelCurrentPlayer(currentAI.getName() + " ist am Zug"); - controller.setAIDeck(currentAI, currentAI.getDeck()); + controller.setAIDeck(currentAI); + + try + { + Thread.sleep(500); + } + catch(InterruptedException e) + { + //ERRORHANDLING + e.printStackTrace(); + } currentAI.turn(lastCard, wishColor, challenge); } @@ -194,9 +234,7 @@ public class Game } private void end(String name) - { - //TODO alert - + { controller.clearAllDecks(ais); System.err.println("Player " + name + " wins!"); @@ -206,11 +244,31 @@ public class Game if(currentPlayer == 1) { controller.setLabelCurrentPlayer(player.getName() + " gewinnt!"); + + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Sieg!"); + alert.setHeaderText(""); + alert.setContentText("Du gewinnst"); + alert.initOwner(controller.stage); + Stage dialogStage = (Stage)alert.getDialogPane().getScene().getWindow(); + dialogStage.getIcons().add(controller.icon); + alert.show(); } else { controller.setLabelCurrentPlayer(ais.get(currentPlayer - 2).getName() + " gewinnt!"); - } + + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Niederlage!"); + alert.setHeaderText(""); + alert.setContentText(ais.get(currentPlayer - 2).getName() + " hat gewonnen."); + alert.initOwner(controller.stage); + Stage dialogStage = (Stage)alert.getDialogPane().getScene().getWindow(); + dialogStage.getIcons().add(controller.icon); + alert.show(); + } + + } public Deck getDeck() @@ -233,6 +291,11 @@ public class Game return player; } + public ArrayList<AI> getAIs() + { + return ais; + } + public boolean isRunning() { return running; @@ -248,11 +311,22 @@ public class Game return controller; } + public boolean isShowingInfo() + { + return showingInfo; + } + + public void setShowingInfo(boolean showingInfo) + { + this.showingInfo = showingInfo; + } + public void draw() { challenge = false; challengeCounter = 0; lastPlayerDraw = true; + controller.hideLabelChallengeCounter(); run(); } @@ -267,16 +341,19 @@ public class Game { challenge = true; challengeCounter += 2; + controller.showLabelChallengeCounter("Verlierer zieht " + challengeCounter + " Karten"); } else if(card.getType().equals(CardType.DRAW_FOUR)) { challenge = true; - challengeCounter += 4; + challengeCounter += 4; + controller.showLabelChallengeCounter("Verlierer zieht " + challengeCounter + " Karten"); } else { challenge = false; challengeCounter = 0; + controller.hideLabelChallengeCounter(); } lastPlayerDraw = false; diff --git a/src/logic/Player.java b/src/logic/Player.java index 3ce45434010dc19165ced45a70d80fcb65d08128..df490f3d6f8abf22df3668b2a898a905d50d2b8a 100644 --- a/src/logic/Player.java +++ b/src/logic/Player.java @@ -42,6 +42,7 @@ public class Player { deck.addAll(cards); game.getController().setPlayerDeck(deck); + game.getController().hideInfo(); } public Card playCard(Card card) @@ -52,8 +53,7 @@ public class Player public ArrayList<Card> getValidCards(Card lastCard, Color wishColor, boolean challenge) { - ArrayList<Card> validCards = new ArrayList<Card>(); - + ArrayList<Card> validCards = new ArrayList<Card>(); if(challenge) { for(Card currentCard : deck) @@ -64,6 +64,13 @@ public class Player { validCards.add(currentCard); } + } + else if(wishColor.equals(Color.ALL)) + { + if(currentCard.getType().equals(CardType.DRAW_TWO) || currentCard.getType().equals(CardType.DRAW_FOUR)) + { + validCards.add(currentCard); + } } else { @@ -86,6 +93,16 @@ public class Player } } } + else if(wishColor.equals(Color.ALL)) + { + for(Card currentCard : deck) + { + if(!currentCard.getType().equals(CardType.WILD) && !currentCard.getType().equals(CardType.DRAW_FOUR)) + { + validCards.add(currentCard); + } + } + } else { for(Card currentCard : deck) @@ -124,11 +141,9 @@ public class Player if(validDeck.size() == 0) { if(challenge) - { - //TODO notification - drawCards(game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck())); - System.out.println("You can't challenge --> please draw " + game.getChallengeCounter() + " cards"); - game.draw(); + { + game.setShowingInfo(true); + game.getController().showInfo("Du kannst nicht kontern. Ziehe " + game.getChallengeCounter() + " Karten.", game.getChallengeCounter()); } else { @@ -137,8 +152,7 @@ public class Player } else { - System.out.println("choose"); - //playerInput (draw or turnCard) + System.out.println("choose"); } } } \ No newline at end of file