diff --git a/.classpath b/.classpath index 92aea57ea522117b997a45b58875f3217c837d5f..bcd2772f9d0add3acd138f0c144c4a7879b847f9 100644 --- a/.classpath +++ b/.classpath @@ -3,5 +3,6 @@ <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/> + <classpathentry combineaccessrules="false" kind="src" path="/_Tools"/> <classpathentry kind="output" path="class"/> </classpath> diff --git a/class/application/ColorChooser.fxml b/class/application/ColorChooser.fxml new file mode 100644 index 0000000000000000000000000000000000000000..38868c90c2c203f3cc0229507832da10196ca8e3 --- /dev/null +++ b/class/application/ColorChooser.fxml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.control.Label?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.shape.Rectangle?> +<?import javafx.scene.text.Font?> + +<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ColorChooserController"> + <children> + <Label layoutX="39.0" layoutY="29.0" text="Wähle deine Wunschfarbe"> + <font> + <Font name="System Bold" size="18.0" /> + </font> + </Label> + <Rectangle fx:id="rectRed" arcHeight="5.0" arcWidth="5.0" fill="#ff1f1f" height="58.0" layoutX="170.0" layoutY="101.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="58.0" /> + <Rectangle fx:id="rectYellow" arcHeight="5.0" arcWidth="5.0" fill="#ffd821" height="58.0" layoutX="73.0" layoutY="101.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="58.0" /> + <Rectangle fx:id="rectGreen" arcHeight="5.0" arcWidth="5.0" fill="#44a119" height="58.0" layoutX="170.0" layoutY="190.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="58.0" /> + <Rectangle fx:id="rectBlue" arcHeight="5.0" arcWidth="5.0" fill="#215eff" height="58.0" layoutX="73.0" layoutY="190.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="58.0" /> + </children> +</AnchorPane> diff --git a/class/application/ColorChooserController$1.class b/class/application/ColorChooserController$1.class new file mode 100644 index 0000000000000000000000000000000000000000..85395f688ebd45b8f0700226b84bc5c7cf105513 Binary files /dev/null and b/class/application/ColorChooserController$1.class differ diff --git a/class/application/ColorChooserController$2.class b/class/application/ColorChooserController$2.class new file mode 100644 index 0000000000000000000000000000000000000000..fc6c75929efa6cda63727bb7e002f61112616edc Binary files /dev/null and b/class/application/ColorChooserController$2.class differ diff --git a/class/application/ColorChooserController$3.class b/class/application/ColorChooserController$3.class new file mode 100644 index 0000000000000000000000000000000000000000..5230175f9388b5b1ab8302573a7f15d4ca958bd8 Binary files /dev/null and b/class/application/ColorChooserController$3.class differ diff --git a/class/application/ColorChooserController$4.class b/class/application/ColorChooserController$4.class new file mode 100644 index 0000000000000000000000000000000000000000..a3193630ce7f52340aabead89fafc6e35d77d3e1 Binary files /dev/null and b/class/application/ColorChooserController$4.class differ diff --git a/class/application/ColorChooserController.class b/class/application/ColorChooserController.class new file mode 100644 index 0000000000000000000000000000000000000000..ba11f7c2f89e2ed9473d440537ec127f2ec99b69 Binary files /dev/null and b/class/application/ColorChooserController.class differ diff --git a/class/application/Controller$1.class b/class/application/Controller$1.class index 51b66919e71c48372e4c9fa9a1ea11909dccc0b2..154ab12fbf846e42a90063e45e5a95853ff7e53a 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 new file mode 100644 index 0000000000000000000000000000000000000000..6a6a82ff33f514c2bb8a046e5a3be2ca0f72c852 Binary files /dev/null and b/class/application/Controller$2.class differ diff --git a/class/application/Controller$3.class b/class/application/Controller$3.class new file mode 100644 index 0000000000000000000000000000000000000000..091fa891b3c63021ded8942c8403116b95207def Binary files /dev/null and b/class/application/Controller$3.class differ diff --git a/class/application/Controller$4.class b/class/application/Controller$4.class new file mode 100644 index 0000000000000000000000000000000000000000..5200445f2fd0a8b6748aea9edda41cde39bc77c0 Binary files /dev/null and b/class/application/Controller$4.class differ diff --git a/class/application/Controller.class b/class/application/Controller.class index 6266957965d0fc7670da3eab97f411957e16d2aa..6afc1b70e257b2fdf4f41c1bf254efe22010c1b2 100644 Binary files a/class/application/Controller.class and b/class/application/Controller.class differ diff --git a/class/application/MainGUI.fxml b/class/application/MainGUI.fxml index a6a521c7ea37697baa6dcb4a0347695000b69b8a..74c58d8ca9022bf49f3ea01d2e9017f112bbc567 100644 --- a/class/application/MainGUI.fxml +++ b/class/application/MainGUI.fxml @@ -6,12 +6,12 @@ <?import javafx.scene.layout.HBox?> <?import javafx.scene.text.Font?> -<AnchorPane 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="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller"> <children> - <HBox fx:id="hboxPlayerDeck" alignment="CENTER" layoutX="83.0" layoutY="450.0" prefHeight="107.0" prefWidth="634.0" /> + <HBox fx:id="hboxPlayerDeck" alignment="CENTER" layoutX="85.0" layoutY="453.0" prefHeight="107.0" prefWidth="634.0" /> <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" /> - <HBox fx:id="hboxAI1" layoutX="246.0" layoutY="31.0" prefHeight="107.0" prefWidth="309.0" /> + <HBox fx:id="hboxAI1" layoutX="246.0" layoutY="44.0" prefHeight="107.0" prefWidth="309.0" /> <Label fx:id="labelCurrentPlayer" alignment="CENTER" contentDisplay="CENTER" layoutX="320.0" layoutY="377.0" prefHeight="31.0" prefWidth="162.0" textAlignment="CENTER"> <font> <Font name="System Bold" size="19.0" /> diff --git a/class/images/SEVEN-GREEN.png b/class/images/SEVEN-GREEN.png index 04d0ccf7fb9d9e16f180a580ef3d01c53c35c8cf..aa8e061313d5762341ae9c3fdced136162675849 100644 Binary files a/class/images/SEVEN-GREEN.png and b/class/images/SEVEN-GREEN.png differ diff --git a/class/logic/AI.class b/class/logic/AI.class index 653ed62e7299254dd07b0cfe2810c0db4bc913c5..cfd69f7bb8728c5a71b60f2deeaeb448adb0a207 100644 Binary files a/class/logic/AI.class and b/class/logic/AI.class differ diff --git a/class/logic/Game.class b/class/logic/Game.class index c148f6bd2cd1beeec9a4af410ccf6433248bb8e8..fa7e6721b5cbc646c4da8a106395a6fc9f946aef 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 8f921401c014056841767dd73eb99de384d60a20..a991580beea6eb679688e8daee102f1c1ff3f109 100644 Binary files a/class/logic/Player.class and b/class/logic/Player.class differ diff --git a/src/application/ColorChooser.fxml b/src/application/ColorChooser.fxml new file mode 100644 index 0000000000000000000000000000000000000000..38868c90c2c203f3cc0229507832da10196ca8e3 --- /dev/null +++ b/src/application/ColorChooser.fxml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.control.Label?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.shape.Rectangle?> +<?import javafx.scene.text.Font?> + +<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ColorChooserController"> + <children> + <Label layoutX="39.0" layoutY="29.0" text="Wähle deine Wunschfarbe"> + <font> + <Font name="System Bold" size="18.0" /> + </font> + </Label> + <Rectangle fx:id="rectRed" arcHeight="5.0" arcWidth="5.0" fill="#ff1f1f" height="58.0" layoutX="170.0" layoutY="101.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="58.0" /> + <Rectangle fx:id="rectYellow" arcHeight="5.0" arcWidth="5.0" fill="#ffd821" height="58.0" layoutX="73.0" layoutY="101.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="58.0" /> + <Rectangle fx:id="rectGreen" arcHeight="5.0" arcWidth="5.0" fill="#44a119" height="58.0" layoutX="170.0" layoutY="190.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="58.0" /> + <Rectangle fx:id="rectBlue" arcHeight="5.0" arcWidth="5.0" fill="#215eff" height="58.0" layoutX="73.0" layoutY="190.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="58.0" /> + </children> +</AnchorPane> diff --git a/src/application/ColorChooserController.java b/src/application/ColorChooserController.java new file mode 100644 index 0000000000000000000000000000000000000000..bdb06d4f9997163f4028e7a56609a94b66ea27f7 --- /dev/null +++ b/src/application/ColorChooserController.java @@ -0,0 +1,62 @@ +package application; + +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.input.MouseEvent; +import javafx.scene.shape.Rectangle; +import javafx.stage.Stage; +import logic.Color; + +public class ColorChooserController +{ + + @FXML private Rectangle rectYellow; + @FXML private Rectangle rectRed; + @FXML private Rectangle rectBlue; + @FXML private Rectangle rectGreen; + + public void init(Stage stage, Controller controller) + { + rectYellow.setOnMouseClicked(new EventHandler<MouseEvent>() + { + @Override + public void handle(MouseEvent event) + { + controller.chosenWishColor = Color.YELLOW; + stage.close(); + } + }); + + rectRed.setOnMouseClicked(new EventHandler<MouseEvent>() + { + @Override + public void handle(MouseEvent event) + { + controller.chosenWishColor = Color.RED; + stage.close(); + } + }); + + rectBlue.setOnMouseClicked(new EventHandler<MouseEvent>() + { + @Override + public void handle(MouseEvent event) + { + controller.chosenWishColor = Color.BLUE; + stage.close(); + } + }); + + rectGreen.setOnMouseClicked(new EventHandler<MouseEvent>() + { + @Override + public void handle(MouseEvent event) + { + controller.chosenWishColor = Color.GREEN; + stage.close(); + } + }); + + //TODO prevent closing without choosing a color + } +} \ No newline at end of file diff --git a/src/application/Controller.java b/src/application/Controller.java index e889885b3373f5a0accf72b4172af7ce86b50949..a63d076c3cbcb140a2e71230033361163d18ba73 100644 --- a/src/application/Controller.java +++ b/src/application/Controller.java @@ -1,20 +1,36 @@ package application; +import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.Locale; +import java.util.Random; import java.util.ResourceBundle; +import javafx.animation.TranslateTransition; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; -import javafx.geometry.Insets; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Point2D; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.SnapshotParameters; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; 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.stage.Modality; import javafx.stage.Stage; +import javafx.util.Duration; +import logic.AI; import logic.Card; import logic.CardType; import logic.Color; @@ -27,8 +43,10 @@ public class Controller @FXML private HBox hboxPlayerDeck; @FXML private HBox hboxAI1; @FXML private Label labelCurrentPlayer; + @FXML private AnchorPane mainPane; public Game game; + public Color chosenWishColor; public Stage stage; public Image icon = new Image("images/icon.png"); @@ -36,7 +54,24 @@ public class Controller public void init() { - iconDeck.setImage(createBackCard()); + iconDeck.setImage(createEmptyBackCard()); + iconDeck.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() + { + @Override + public void handle(MouseEvent event) + { + if(game.isRunning() && game.getCurrentPlayer() == 1) + { + game.getPlayer().drawCard(game.getDeck().drawCard(game.getDeadDeck())); + setPlayerDeck(game.getPlayer().getDeck()); + + // TODO move card toPlayerDeck moveCardToDeadDeck(imageView, + // card, newWishColor); + // --> in "onFinish" + game.draw(); + } + } + }); // DEBUG game = new Game(this, 1); @@ -58,11 +93,20 @@ public class Controller iconLastCard.setImage(createCard(card, true).getImage()); } - private Image createBackCard() + private Image createEmptyBackCard() { return new Image("images/card-back.png"); } + private ImageView createBackCard() + { + ImageView imageView = new ImageView(new Image("images/card-back.png")); + imageView.setFitHeight(90.0); + imageView.setFitWidth(57.0); + + return imageView; + } + private ImageView createCard(Card card, boolean valid) { ImageView imageView = new ImageView(new Image("images/" + card.getType() + "-" + card.getColor() + ".png")); @@ -70,27 +114,63 @@ public class Controller imageView.setFitWidth(57.0); if(!valid) - { - //TODO -// imageView.setImage(new Image("images/transparent/" + card.getType() + "-" + card.getColor() + ".png")); -// imageView.setStyle("-fx-background-color: transparent;"); + { + WritableImage snapshot = imageView.snapshot(new SnapshotParameters(), null); + 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); + snapshot.getPixelWriter().setColor(x, y, new javafx.scene.paint.Color(oldColor.getRed(), oldColor.getGreen(), oldColor.getBlue(), oldColor.getOpacity() * 0.3)); + } + } + imageView.setImage(snapshot); } + Controller main = this; imageView.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { - if(valid) + if(game.isRunning() && game.getCurrentPlayer() == 1) { - Color newWishColor = null; - - if(card.getType().equals(CardType.WILD) || card.getType().equals(CardType.DRAW_FOUR)) + if(valid) { - // TODO chose wishColor - } + if(card.getType().equals(CardType.WILD) || card.getType().equals(CardType.DRAW_FOUR)) + { + try + { + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/application/ColorChooser.fxml")); + + Parent root = (Parent)fxmlLoader.load(); + Stage newStage = new Stage(); + newStage.setScene(new Scene(root, 300, 300)); + newStage.setTitle("Wunschfarbe"); + newStage.initOwner(stage); + + newStage.getIcons().add(icon); + + ColorChooserController newController = fxmlLoader.getController(); + newController.init(newStage, main); + + newStage.initModality(Modality.APPLICATION_MODAL); + newStage.setResizable(false); + newStage.showAndWait(); + + } + catch(IOException e1) + { + e1.printStackTrace(); + } + } + else + { + chosenWishColor = null; + } - game.playCard(game.getPlayer().playCard(card), newWishColor); + moveCardToDeadDeck(imageView, card, chosenWishColor); + } } } }); @@ -98,45 +178,172 @@ public class Controller return imageView; } - public void setPlayerDeck(ArrayList<Card> deck) - { - hboxPlayerDeck.getChildren().clear(); - - for(Card currentCard : deck) + public void moveCardToDeadDeck(ImageView view, Card card, Color newWishColor) + { + Point2D cardPosition = view.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.setFromX(0); + translateTransition.setFromY(0); + translateTransition.setToX(- (cardPosition.getX() - deckPosition.getX())); + translateTransition.setToY(- (cardPosition.getY() - deckPosition.getY())); + translateTransition.setOnFinished(new EventHandler<ActionEvent>() { - hboxPlayerDeck.getChildren().add(createCard(currentCard, true)); - HBox.setMargin(hboxPlayerDeck.getChildren().get(hboxPlayerDeck.getChildren().size() - 1), new Insets(0, 15, 0, 0)); - } + @Override + public void handle(ActionEvent event) + { + game.playCard(game.getPlayer().playCard(card), newWishColor); + } + }); + + translateTransition.play(); } - // TODO other AIs - // TODO set Cards to back - public void setAI1Deck(ArrayList<Card> deck) + public void moveAICardToDeadDeck(AI ai, Card card, Color newWishColor) { - hboxAI1.getChildren().clear(); + ObservableList<Node> nodes = mainPane.getChildren(); + Iterator<Node> iterator = nodes.iterator(); + ArrayList<Node> possibleNodes = new ArrayList<Node>(); + while(iterator.hasNext()) + { + Node current = iterator.next(); + if(current.getId().equals("ai")) + { + possibleNodes.add(current); + } + } + + + Random random = new Random(); + int viewNumber = random.nextInt(possibleNodes.size()); + + ImageView view = (ImageView)possibleNodes.get(viewNumber); + view.setImage(new Image("images/" + card.getType() + "-" + card.getColor() + ".png")); + + Point2D cardPosition = view.localToScene(Point2D.ZERO); + Point2D deckPosition = iconLastCard.localToScene(Point2D.ZERO); + System.out.println(view.localToScene(Point2D.ZERO)); + //TODO cardPosition is always 0, 0 + + 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((deckPosition.getX() - cardPosition.getX())); + translateTransition.setToY((deckPosition.getY() - cardPosition.getY())); + translateTransition.setOnFinished(new EventHandler<ActionEvent>() + { + @Override + public void handle(ActionEvent event) + { + game.playCard(ai.playCard(card), newWishColor); + } + }); + + translateTransition.play(); } + + public void setPlayerDeck(ArrayList<Card> deck) + { + ObservableList<Node> nodes = mainPane.getChildren(); + Iterator<Node> iterator = nodes.iterator(); + while(iterator.hasNext()) + { + if(iterator.next().getId().equals("player")) + { + iterator.remove(); + } + } + + int counter = 1; + for(Card currentCard : deck) { - hboxAI1.getChildren().add(createCard(currentCard, true)); - HBox.setMargin(hboxAI1.getChildren().get(hboxAI1.getChildren().size() - 1), new Insets(0, 15, 0, 0)); + ImageView current = createCard(currentCard, true); + + current.setId("player"); + mainPane.getChildren().add(current); + AnchorPane.setBottomAnchor(current, 30.0); + AnchorPane.setLeftAnchor(current, 100.0 + (counter * (57 + 14))); + + //TODO if larger then maxWidth + counter++; } } public void setValidPlayerDeck(ArrayList<Card> deck, ArrayList<Card> validDeck) { + ObservableList<Node> nodes = mainPane.getChildren(); + Iterator<Node> iterator = nodes.iterator(); + while(iterator.hasNext()) + { + if(iterator.next().getId().equals("player")) + { + iterator.remove(); + } + } + + int counter = 1; + for(Card currentCard : deck) { + ImageView current; + if(validDeck.contains(currentCard)) { - hboxPlayerDeck.getChildren().add(createCard(currentCard, true)); + current = createCard(currentCard, true); } else { - hboxPlayerDeck.getChildren().add(createCard(currentCard, false)); + current = createCard(currentCard, false); } + + current.setId("player"); + + mainPane.getChildren().add(current); + AnchorPane.setBottomAnchor(current, 30.0); + AnchorPane.setLeftAnchor(current, 100.0 + (counter * (57 + 14))); + + //TODO if larger then maxWidth + counter++; + } + } - HBox.setMargin(hboxPlayerDeck.getChildren().get(hboxPlayerDeck.getChildren().size() - 1), new Insets(0, 15, 0, 0)); + // TODO other AIs + public void setAI1Deck(ArrayList<Card> deck) + { + ObservableList<Node> nodes = mainPane.getChildren(); + Iterator<Node> iterator = nodes.iterator(); + while(iterator.hasNext()) + { + if(iterator.next().getId().equals("ai")) + { + iterator.remove(); + } } + + int counter = 1; + + for(Card currentCard : deck) + { + ImageView current = createBackCard(); + + current.setId("ai"); + mainPane.getChildren().add(current); + AnchorPane.setTopAnchor(current, 30.0); + AnchorPane.setLeftAnchor(current, 100.0 + (counter * (57 + 14))); + + //TODO if larger then maxWidth + counter++; + } } public void about() diff --git a/src/application/MainGUI.fxml b/src/application/MainGUI.fxml index a6a521c7ea37697baa6dcb4a0347695000b69b8a..74c58d8ca9022bf49f3ea01d2e9017f112bbc567 100644 --- a/src/application/MainGUI.fxml +++ b/src/application/MainGUI.fxml @@ -6,12 +6,12 @@ <?import javafx.scene.layout.HBox?> <?import javafx.scene.text.Font?> -<AnchorPane 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="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller"> <children> - <HBox fx:id="hboxPlayerDeck" alignment="CENTER" layoutX="83.0" layoutY="450.0" prefHeight="107.0" prefWidth="634.0" /> + <HBox fx:id="hboxPlayerDeck" alignment="CENTER" layoutX="85.0" layoutY="453.0" prefHeight="107.0" prefWidth="634.0" /> <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" /> - <HBox fx:id="hboxAI1" layoutX="246.0" layoutY="31.0" prefHeight="107.0" prefWidth="309.0" /> + <HBox fx:id="hboxAI1" layoutX="246.0" layoutY="44.0" prefHeight="107.0" prefWidth="309.0" /> <Label fx:id="labelCurrentPlayer" alignment="CENTER" contentDisplay="CENTER" layoutX="320.0" layoutY="377.0" prefHeight="31.0" prefWidth="162.0" textAlignment="CENTER"> <font> <Font name="System Bold" size="19.0" /> diff --git a/src/images/SEVEN-GREEN.png b/src/images/SEVEN-GREEN.png index 04d0ccf7fb9d9e16f180a580ef3d01c53c35c8cf..aa8e061313d5762341ae9c3fdced136162675849 100644 Binary files a/src/images/SEVEN-GREEN.png and b/src/images/SEVEN-GREEN.png differ diff --git a/src/logic/AI.java b/src/logic/AI.java index 6dbd96ab03bbb39447ee3682b394bb18bee71d37..daa365927a8fc77cc84b7922a95c7ef7cf324156 100644 --- a/src/logic/AI.java +++ b/src/logic/AI.java @@ -36,11 +36,13 @@ public class AI public void drawCard(Card card) { deck.add(card); + game.getController().setAI1Deck(deck); } public void drawCards(ArrayList<Card> cards) { deck.addAll(cards); + game.getController().setAI1Deck(deck); } public Card playCard(Card card) @@ -162,9 +164,9 @@ public class AI case 4: newWishColor = Color.GREEN; break; } - } + } - game.playCard(playCard(playedCard), newWishColor); + game.getController().moveAICardToDeadDeck(this ,playedCard, newWishColor); } } diff --git a/src/logic/Game.java b/src/logic/Game.java index 26af13581c791c9b1050d2eb90443431a592a3d5..16355aa68e50f092c960df2293679ee52e141d57 100644 --- a/src/logic/Game.java +++ b/src/logic/Game.java @@ -22,7 +22,8 @@ public class Game private boolean lastPlayerDraw; private boolean skipped; private int counter; - + private boolean running; + public Game(Controller controller, int numberOfAIs) { this.controller = controller; @@ -65,9 +66,7 @@ public class Game deadDeck.add(deck.drawCard(deadDeck)); lastCard = deadDeck.getCards().get(deadDeck.getCards().size()-1); - controller.setLastCard(lastCard); - - //TODO abfangen wenn +4 oder +2 oder wild am anfang kommt + controller.setLastCard(lastCard); start(); } @@ -79,10 +78,11 @@ public class Game public void start() { + running = true; Random random = new Random(); currentPlayer = random.nextInt(ais.size() + 1) + 1; - counter = 1; + counter = 0; run(); } @@ -104,7 +104,7 @@ public class Game } } - System.out.println("ROUND: " + counter / 4); + System.out.println("ROUND: " + counter / 4 + 1); determineNextPlayer(); @@ -130,20 +130,18 @@ public class Game if(currentPlayer == 1) { controller.setLabelCurrentPlayer(player.getName() + " ist am Zug"); - + controller.setValidPlayerDeck(player.getDeck(), player.getValidCards(lastCard, wishColor, challenge)); - player.turn(lastCard, wishColor, challenge); - controller.setPlayerDeck(player.getDeck()); + player.turn(lastCard, wishColor, challenge); } else - { + { + AI currentAI = ais.get(currentPlayer - 2); controller.setLabelCurrentPlayer(currentAI.getName() + " ist am Zug"); - currentAI.turn(lastCard, wishColor, challenge); - switch(currentPlayer) { case 2: controller.setAI1Deck(currentAI.getDeck()); @@ -153,7 +151,9 @@ public class Game // case 4: controller.setAI3Deck(currentAI.getDeck()); // break; default: break; - } + } + + currentAI.turn(lastCard, wishColor, challenge); } } else @@ -198,9 +198,11 @@ public class Game private void end(String name) { - //TODO in UI + //TODO alert System.err.println("Player " + name + " wins!"); + running = false; + if(currentPlayer == 1) { controller.setLabelCurrentPlayer(player.getName() + " gewinnt!"); @@ -231,6 +233,21 @@ public class Game return player; } + public boolean isRunning() + { + return running; + } + + public int getCurrentPlayer() + { + return currentPlayer; + } + + public Controller getController() + { + return controller; + } + public void draw() { challenge = false; @@ -238,10 +255,10 @@ public class Game lastPlayerDraw = true; run(); - } + } public void playCard(Card card, Color wishColor) - { + { deadDeck.add(card); lastCard = card; this.wishColor = wishColor; diff --git a/src/logic/Player.java b/src/logic/Player.java index 57931d34bc75b602307354f62b77e4a08ff9a006..3ce45434010dc19165ced45a70d80fcb65d08128 100644 --- a/src/logic/Player.java +++ b/src/logic/Player.java @@ -35,11 +35,13 @@ public class Player public void drawCard(Card card) { deck.add(card); + game.getController().setPlayerDeck(deck); } public void drawCards(ArrayList<Card> cards) { deck.addAll(cards); + game.getController().setPlayerDeck(deck); } public Card playCard(Card card) @@ -123,23 +125,20 @@ public class Player { if(challenge) { + //TODO notification drawCards(game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck())); - System.out.println("draw " + game.getChallengeCounter() + " cards"); - System.out.println("deack after draw: " + deck); + System.out.println("You can't challenge --> please draw " + game.getChallengeCounter() + " cards"); + game.draw(); } else - { - drawCard(game.getDeck().drawCard(game.getDeadDeck())); - System.out.println("draw one card"); - System.out.println("deack after draw: " + deck); + { + System.out.println("No valid cards --> please draw"); } } else { System.out.println("choose"); - //playerInput (draw or turnCard) - - //TODO add "draw" - Button + //playerInput (draw or turnCard) } } } \ No newline at end of file