diff --git a/class/application/Controller$1.class b/class/application/Controller$1.class index 154ab12fbf846e42a90063e45e5a95853ff7e53a..5f739f9a5a101f6660e74bcd18fc309a2e51c369 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 6a6a82ff33f514c2bb8a046e5a3be2ca0f72c852..a0aa43b035592b38636ea5ba4e940b4eadbfcad3 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 091fa891b3c63021ded8942c8403116b95207def..4110b5483de2867c4528fd4f6ee2bd18a4a22fed 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 5200445f2fd0a8b6748aea9edda41cde39bc77c0..bccccc2fa9f7fb94a704391dfd153344a519d915 100644 Binary files a/class/application/Controller$4.class and b/class/application/Controller$4.class differ diff --git a/class/application/Controller.class b/class/application/Controller.class index 6afc1b70e257b2fdf4f41c1bf254efe22010c1b2..5dd6d2b17b27bddd18875d2c7a9482104c43abe2 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 74c58d8ca9022bf49f3ea01d2e9017f112bbc567..3d499e5acfde1dddf77acd7dd766f95f7eab4863 100644 --- a/class/application/MainGUI.fxml +++ b/class/application/MainGUI.fxml @@ -3,19 +3,23 @@ <?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"> <children> - <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="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" /> </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"> + <font> + <Font name="System Bold" size="12.0" /> + </font> + </Label> </children> </AnchorPane> diff --git a/class/logic/AI.class b/class/logic/AI.class index cfd69f7bb8728c5a71b60f2deeaeb448adb0a207..68664ed635474773ba6a443f1bf0ad73a92f5fe3 100644 Binary files a/class/logic/AI.class and b/class/logic/AI.class differ diff --git a/class/logic/Card.class b/class/logic/Card.class index e21b50bed056790848ca47787baacb679e226b56..9f06a7928ed6839bf8de65f7a53f7d0aaa9261fd 100644 Binary files a/class/logic/Card.class and b/class/logic/Card.class differ diff --git a/class/logic/Color.class b/class/logic/Color.class index ba614dc211afed9fcd1e6a133b535bb1c33a9648..3f5928566b37a74f9c5e4545c3a55f6129582ad4 100644 Binary files a/class/logic/Color.class and b/class/logic/Color.class differ diff --git a/class/logic/Game.class b/class/logic/Game.class index fa7e6721b5cbc646c4da8a106395a6fc9f946aef..8ae00fbb42cdc13ac97f064a4ffbb982b656d220 100644 Binary files a/class/logic/Game.class and b/class/logic/Game.class differ diff --git a/src/application/ColorChooserController.java b/src/application/ColorChooserController.java index bdb06d4f9997163f4028e7a56609a94b66ea27f7..3dd0f96526bf1a9a3867900c047c65c91b3ef16f 100644 --- a/src/application/ColorChooserController.java +++ b/src/application/ColorChooserController.java @@ -57,6 +57,6 @@ public class ColorChooserController } }); - //TODO prevent closing without choosing a color + //TODO prevent closing without choosing a color --> but cancel button } } \ No newline at end of file diff --git a/src/application/Controller.java b/src/application/Controller.java index a63d076c3cbcb140a2e71230033361163d18ba73..18552430b26200e4539b79cfd27b6089f81c6405 100644 --- a/src/application/Controller.java +++ b/src/application/Controller.java @@ -26,7 +26,7 @@ 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; import javafx.util.Duration; @@ -40,20 +40,39 @@ public class Controller { @FXML private ImageView iconLastCard; @FXML private ImageView iconDeck; - @FXML private HBox hboxPlayerDeck; - @FXML private HBox hboxAI1; @FXML private Label labelCurrentPlayer; @FXML private AnchorPane mainPane; - + @FXML private Label labelWishColor; + @FXML private Circle circleWishColor; + public Game game; public Color chosenWishColor; 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 Point2D PLAYER_STARTING_POINT; + private final Point2D AI_1_STARTING_POINT = new Point2D(100.0, 30.0); + + 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"); + + public void init() { + PLAYER_STARTING_POINT = new Point2D(100.0, stage.getScene().getHeight() - 30.0 - CARD_HEIGHT); + iconDeck.setImage(createEmptyBackCard()); iconDeck.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @@ -73,16 +92,51 @@ public class Controller } }); - // DEBUG - game = new Game(this, 1); - game.newGame(5); + + startGame(); } public void setStage(Stage stage) { - this.stage = stage; + this.stage = stage; } + public void startGame() + { + hideCircleWishColor(); + + // DEBUG + game = new Game(this, 1); + game.newGame(5); + } + + public void showCircleWishColor(Color color) + { + 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; + } + + labelWishColor.setVisible(true); + circleWishColor.setVisible(true); + } + + public void hideCircleWishColor() + { + labelWishColor.setVisible(false); + circleWishColor.setVisible(false); + } + public void setLabelCurrentPlayer(String text) { labelCurrentPlayer.setText(text); @@ -101,8 +155,8 @@ public class Controller private ImageView createBackCard() { ImageView imageView = new ImageView(new Image("images/card-back.png")); - imageView.setFitHeight(90.0); - imageView.setFitWidth(57.0); + imageView.setFitHeight(CARD_HEIGHT); + imageView.setFitWidth(CARD_WIDTH); return imageView; } @@ -110,21 +164,38 @@ public class Controller private ImageView createCard(Card card, boolean valid) { ImageView imageView = new ImageView(new Image("images/" + card.getType() + "-" + card.getColor() + ".png")); - imageView.setFitHeight(90.0); - imageView.setFitWidth(57.0); + imageView.setFitHeight(CARD_HEIGHT); + imageView.setFitWidth(CARD_WIDTH); if(!valid) { WritableImage snapshot = imageView.snapshot(new SnapshotParameters(), null); - for(int x = 0; x < snapshot.getWidth(); x++) + + if(card.getType().equals(CardType.DRAW_FOUR) && card.getType().equals(CardType.WILD)) { - for(int y = 0; y < snapshot.getHeight(); y++) + for(int x = 0; x < snapshot.getWidth(); x++) { - 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)); + 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)); + } } + imageView.setImage(snapshot); } - imageView.setImage(snapshot); + else + { + 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(); + 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; @@ -169,7 +240,7 @@ public class Controller chosenWishColor = null; } - moveCardToDeadDeck(imageView, card, chosenWishColor); + moveCardToDeadDeck(imageView, card, chosenWishColor); } } } @@ -179,8 +250,7 @@ public class Controller } 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(); @@ -190,46 +260,49 @@ public class Controller translateTransition.setAutoReverse(false); translateTransition.setFromX(0); translateTransition.setFromY(0); - translateTransition.setToX(- (cardPosition.getX() - deckPosition.getX())); - translateTransition.setToY(- (cardPosition.getY() - deckPosition.getY())); + translateTransition.setToX(- (view.getX() - deckPosition.getX())); + translateTransition.setToY(- (view.getY() - deckPosition.getY())); translateTransition.setOnFinished(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { - game.playCard(game.getPlayer().playCard(card), newWishColor); + if(newWishColor != null) + { + showCircleWishColor(newWishColor); + } + else + { + hideCircleWishColor(); + } + setPlayerDeck(game.getPlayer().getDeck()); + game.playCard(game.getPlayer().playCard(card), newWishColor); } }); translateTransition.play(); } - public void moveAICardToDeadDeck(AI ai, Card card, Color newWishColor) + public void moveAICardToDeadDeck(AI ai, int currentPlayer, Card card, Color newWishColor) { ObservableList<Node> nodes = mainPane.getChildren(); - Iterator<Node> iterator = nodes.iterator(); - ArrayList<Node> possibleNodes = new ArrayList<Node>(); - while(iterator.hasNext()) + ArrayList<Integer> possibleNodes = new ArrayList<Integer>(); + for(int i = 0; i < nodes.size(); i++) { - Node current = iterator.next(); - if(current.getId().equals("ai")) - { - possibleNodes.add(current); + Node current = nodes.get(i); + if(current.getId().contains("ai" + ai.getID())) + { + possibleNodes.add(i); } - } - - + } + 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); + ImageView view = (ImageView)mainPane.getChildren().get(possibleNodes.get(viewNumber)); + view.setImage(new Image("images/" + card.getType() + "-" + card.getColor() + ".png")); - System.out.println(view.localToScene(Point2D.ZERO)); - //TODO cardPosition is always 0, 0 + Point2D deckPosition = iconLastCard.localToScene(Point2D.ZERO); TranslateTransition translateTransition = new TranslateTransition(); translateTransition.setDuration(Duration.millis(500)); @@ -238,21 +311,31 @@ public class Controller translateTransition.setAutoReverse(false); translateTransition.setFromX(0); translateTransition.setFromY(0); - translateTransition.setToX((deckPosition.getX() - cardPosition.getX())); - translateTransition.setToY((deckPosition.getY() - cardPosition.getY())); + translateTransition.setToX(- (view.getX() - deckPosition.getX())); + translateTransition.setToY(- (view.getY() - deckPosition.getY())); translateTransition.setOnFinished(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { + if(newWishColor != null) + { + showCircleWishColor(newWishColor); + } + else + { + hideCircleWishColor(); + } + setAIDeck(ai, ai.getDeck()); game.playCard(ai.playCard(card), newWishColor); } }); - translateTransition.play(); } - - public void setPlayerDeck(ArrayList<Card> deck) - { + translateTransition.play(); + } + + public void clearPlayerDeck() + { ObservableList<Node> nodes = mainPane.getChildren(); Iterator<Node> iterator = nodes.iterator(); while(iterator.hasNext()) @@ -262,6 +345,11 @@ public class Controller iterator.remove(); } } + } + + public void setPlayerDeck(ArrayList<Card> deck) + { + clearPlayerDeck(); int counter = 1; @@ -271,25 +359,38 @@ public class Controller current.setId("player"); mainPane.getChildren().add(current); - AnchorPane.setBottomAnchor(current, 30.0); - AnchorPane.setLeftAnchor(current, 100.0 + (counter * (57 + 14))); + if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE)) > (stage.getScene().getWidth() - PLAYER_STARTING_POINT.getX() * 2)) + { + if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM)) > (stage.getScene().getWidth() - PLAYER_STARTING_POINT.getX() * 2)) + { + if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL)) > (stage.getScene().getWidth() - PLAYER_STARTING_POINT.getX() * 2)) + { + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_ULTRA_SMALL))); + } + else + { + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL))); + } + } + else + { + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM))); + } + } + else + { + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE))); + } + + current.setY(PLAYER_STARTING_POINT.getY()); - //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(); - } - } + clearPlayerDeck(); int counter = 1; @@ -309,26 +410,54 @@ public class Controller 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 + 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_HORIZONTAL_MEDIUM)) > maxWidth) + { + if((deck.size() * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL)) > maxWidth) + { + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_ULTRA_SMALL))); + } + else + { + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_SMALL))); + } + } + else + { + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_MEDIUM))); + } + } + else + { + current.setX(PLAYER_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE))); + } + + current.setY(PLAYER_STARTING_POINT.getY()); + counter++; } } - - // TODO other AIs - public void setAI1Deck(ArrayList<Card> deck) + + public void clearAIDeck(AI ai) { ObservableList<Node> nodes = mainPane.getChildren(); Iterator<Node> iterator = nodes.iterator(); while(iterator.hasNext()) { - if(iterator.next().getId().equals("ai")) + if(iterator.next().getId().contains("ai" + ai.getID())) { iterator.remove(); } } + } + + public void setAIDeck(AI ai, ArrayList<Card> deck) + { + clearAIDeck(ai); int counter = 1; @@ -336,13 +465,46 @@ public class Controller { ImageView current = createBackCard(); - current.setId("ai"); + current.setId("ai" + ai.getID()); + + //TODO other AIs (vertical) --> flip imageViews by 90 degrees mainPane.getChildren().add(current); - AnchorPane.setTopAnchor(current, 30.0); - AnchorPane.setLeftAnchor(current, 100.0 + (counter * (57 + 14))); + double maxWidth = stage.getScene().getWidth() - (AI_1_STARTING_POINT.getX() * 2) - CARD_WIDTH; - //TODO if larger then maxWidth - counter++; + 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 + { + current.setX(AI_1_STARTING_POINT.getX() + (counter * (CARD_WIDTH + CARD_SPACING_HORIZONTAL_LARGE))); + } + + counter++; + } + } + + public void clearAllDecks(ArrayList<AI> ais) + { + clearPlayerDeck(); + + for(AI currentAI : ais) + { + clearAIDeck(currentAI); } } diff --git a/src/application/MainGUI.fxml b/src/application/MainGUI.fxml index 74c58d8ca9022bf49f3ea01d2e9017f112bbc567..3d499e5acfde1dddf77acd7dd766f95f7eab4863 100644 --- a/src/application/MainGUI.fxml +++ b/src/application/MainGUI.fxml @@ -3,19 +3,23 @@ <?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"> <children> - <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="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" /> </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"> + <font> + <Font name="System Bold" size="12.0" /> + </font> + </Label> </children> </AnchorPane> diff --git a/src/logic/AI.java b/src/logic/AI.java index daa365927a8fc77cc84b7922a95c7ef7cf324156..b18d3334b62e604e0328050d436a0497e65c73ef 100644 --- a/src/logic/AI.java +++ b/src/logic/AI.java @@ -6,13 +6,15 @@ import java.util.Random; public class AI { private String name; + private int id; private ArrayList<Card> deck; private int wins; private Game game; - public AI(String name, Game game) + public AI(String name, int id, Game game) { this.name = name; + this.id = id; deck = new ArrayList<Card>(); wins = 0; this.game = game; @@ -32,17 +34,22 @@ public class AI { return wins; } + + public int getID() + { + return id; + } public void drawCard(Card card) { deck.add(card); - game.getController().setAI1Deck(deck); + game.getController().setAIDeck(this, deck); } public void drawCards(ArrayList<Card> cards) { deck.addAll(cards); - game.getController().setAI1Deck(deck); + game.getController().setAIDeck(this, deck); } public Card playCard(Card card) @@ -151,6 +158,7 @@ public class AI if(playedCard.getType().equals(CardType.WILD) || playedCard.getType().equals(CardType.DRAW_FOUR)) { + //TODO choose color that is mostly in deck (except black) Random random = new Random(); int colorInt = random.nextInt(4) + 1; switch(colorInt) @@ -166,7 +174,7 @@ public class AI } } - game.getController().moveAICardToDeadDeck(this ,playedCard, newWishColor); + game.getController().moveAICardToDeadDeck(this,game.getCurrentPlayer(), playedCard, newWishColor); } } diff --git a/src/logic/Color.java b/src/logic/Color.java index 09818fb7cd669d3c8c5400282e10e7d4d27391b5..de174c5116083418683cca8877a393b6425c8a59 100644 --- a/src/logic/Color.java +++ b/src/logic/Color.java @@ -2,5 +2,5 @@ package logic; public enum Color { - YELLOW, RED, BLUE, GREEN, BLACK + YELLOW, RED, BLUE, GREEN, BLACK, ALL } \ No newline at end of file diff --git a/src/logic/Game.java b/src/logic/Game.java index 16355aa68e50f092c960df2293679ee52e141d57..00969b31962e79d59aadf7ffd68e2c1a8550e57c 100644 --- a/src/logic/Game.java +++ b/src/logic/Game.java @@ -33,7 +33,7 @@ public class Game ais = new ArrayList<AI>(); for(int i = 1; i <= numberOfAIs; i++) { - ais.add(new AI("AI " + i, this)); + ais.add(new AI("AI " + i, i-1, this)); } gameCount = 0; @@ -67,6 +67,12 @@ public class Game deadDeck.add(deck.drawCard(deadDeck)); lastCard = deadDeck.getCards().get(deadDeck.getCards().size()-1); controller.setLastCard(lastCard); + if(lastCard.getType().equals(CardType.DRAW_FOUR) || lastCard.getType().equals(CardType.WILD)) + { + wishColor = Color.ALL; + controller.chosenWishColor = wishColor; + controller.showCircleWishColor(wishColor); + } start(); } @@ -142,16 +148,7 @@ public class Game controller.setLabelCurrentPlayer(currentAI.getName() + " ist am Zug"); - switch(currentPlayer) - { - case 2: controller.setAI1Deck(currentAI.getDeck()); - break; -// case 3: controller.setAI2Deck(currentAI.getDeck()); -// break; -// case 4: controller.setAI3Deck(currentAI.getDeck()); -// break; - default: break; - } + controller.setAIDeck(currentAI, currentAI.getDeck()); currentAI.turn(lastCard, wishColor, challenge); } @@ -199,6 +196,9 @@ public class Game private void end(String name) { //TODO alert + + controller.clearAllDecks(ais); + System.err.println("Player " + name + " wins!"); running = false;