diff --git a/.classpath b/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..92aea57ea522117b997a45b58875f3217c837d5f --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <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 kind="output" path="class"/> +</classpath> diff --git a/.project b/.project new file mode 100644 index 0000000000000000000000000000000000000000..e2444601a0009e0463f6f0daadf7335fdf5fc3cb --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>UNO</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.xtext.ui.shared.xtextBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.xtext.ui.shared.xtextNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 0000000000000000000000000000000000000000..1bcd01a3451e2139b8e477d4844f8fd6dfffef8e --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,14 @@ +[CHANGELOG] +=========== + +UNO +====== + +>>> start-date: 09.04.16 +>>> status-date: 10.04.16 +____________________________________________________ + + +____________________________________________________ + +[/CHANGELOG] \ No newline at end of file diff --git a/README.md b/README.md index e8c013da14f5f460098c9a04375728b9393af978..44266795cd89e84eec4ee63f5af4ef352621662f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # UNO +- startdate: 09.04.16 +- current version: 0.0.0 (0) - 10.04.16 + +### Description + +The card game UNO \ No newline at end of file diff --git a/build.fxbuild b/build.fxbuild new file mode 100644 index 0000000000000000000000000000000000000000..41f5542bbead5fe275bbb13569d2e287d3e91ff9 --- /dev/null +++ b/build.fxbuild @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="ASCII"?> +<anttasks:AntTask xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:anttasks="http://org.eclipse.fx.ide.jdt/1.0" buildDirectory="${project}/build"> + <deploy> + <application name="UNO"/> + <info/> + </deploy> + <signjar/> +</anttasks:AntTask> diff --git a/build/icon.png b/build/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4b756db39463446f4151a2bfcdaca7d9661ca682 Binary files /dev/null and b/build/icon.png differ diff --git a/class/application/Controller.class b/class/application/Controller.class new file mode 100644 index 0000000000000000000000000000000000000000..3747acbe08a1f8d139621d7310cb271edd6a1480 Binary files /dev/null and b/class/application/Controller.class differ diff --git a/class/application/Main.class b/class/application/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..54a3483c65fb7d25c3387372cf37c101fc24da0a Binary files /dev/null and b/class/application/Main.class differ diff --git a/class/application/_de.properties b/class/application/_de.properties new file mode 100644 index 0000000000000000000000000000000000000000..c412094f4bb7009585701e9b6b1106fbb8c12919 --- /dev/null +++ b/class/application/_de.properties @@ -0,0 +1,4 @@ +app.name=PlayCount +version.code=2 +version.name=1.1.0 +version.date=23.03.16 \ No newline at end of file diff --git a/class/application/application.css b/class/application/application.css new file mode 100644 index 0000000000000000000000000000000000000000..83d6f3343843c65d5dfaf3fedb97b6494c19113d --- /dev/null +++ b/class/application/application.css @@ -0,0 +1 @@ +/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/class/logic/AI.class b/class/logic/AI.class new file mode 100644 index 0000000000000000000000000000000000000000..2244de046670dc6c2f863e8836304ceb02c3c410 Binary files /dev/null and b/class/logic/AI.class differ diff --git a/class/logic/Card.class b/class/logic/Card.class new file mode 100644 index 0000000000000000000000000000000000000000..360393c94f623c1e06b98d4968e78a174d1bc3ea Binary files /dev/null and b/class/logic/Card.class differ diff --git a/class/logic/CardType.class b/class/logic/CardType.class new file mode 100644 index 0000000000000000000000000000000000000000..7a0e7d46a194c21d6788fe797c8ad6b04351f74a Binary files /dev/null and b/class/logic/CardType.class differ diff --git a/class/logic/Color.class b/class/logic/Color.class new file mode 100644 index 0000000000000000000000000000000000000000..ba614dc211afed9fcd1e6a133b535bb1c33a9648 Binary files /dev/null and b/class/logic/Color.class differ diff --git a/class/logic/DeadDeck.class b/class/logic/DeadDeck.class new file mode 100644 index 0000000000000000000000000000000000000000..0fd069d07e3f409625d8ba35b5bf9003c3608799 Binary files /dev/null and b/class/logic/DeadDeck.class differ diff --git a/class/logic/Deck.class b/class/logic/Deck.class new file mode 100644 index 0000000000000000000000000000000000000000..99c39a2a9fc6e052f2d75d33bbdc907f736e4020 Binary files /dev/null and b/class/logic/Deck.class differ diff --git a/class/logic/Direction.class b/class/logic/Direction.class new file mode 100644 index 0000000000000000000000000000000000000000..0624f71db464314a106c7336ceb8a8833d2ef5a4 Binary files /dev/null and b/class/logic/Direction.class differ diff --git a/class/logic/Game.class b/class/logic/Game.class new file mode 100644 index 0000000000000000000000000000000000000000..4fb5ee7d10b44dfdcdddb12d39f9bfc04947f1d6 Binary files /dev/null and b/class/logic/Game.class differ diff --git a/class/logic/Player.class b/class/logic/Player.class new file mode 100644 index 0000000000000000000000000000000000000000..2c3c3947fa1214bfed2714dbbd8c94cea195c36f Binary files /dev/null and b/class/logic/Player.class differ diff --git a/src/application/Controller.java b/src/application/Controller.java new file mode 100644 index 0000000000000000000000000000000000000000..454479b161e72babdb6b4f6d73c518cd4b1060f1 --- /dev/null +++ b/src/application/Controller.java @@ -0,0 +1,38 @@ +package application; + +import java.util.Locale; +import java.util.ResourceBundle; + +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.image.Image; +import javafx.stage.Stage; + +public class Controller +{ + public Stage stage; + public Image icon = new Image("application/icon.png"); + private final ResourceBundle bundle = ResourceBundle.getBundle("application/", Locale.GERMANY); + + public void init() + { + + } + + public void setStage(Stage stage) + { + this.stage = stage; + } + + + public void about() + { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("�ber " + bundle.getString("app.name")); + alert.setHeaderText(bundle.getString("app.name")); + alert.setContentText("Version: " + bundle.getString("version.name") + "\r\nDatum: " + bundle.getString("version.date") + "\r\nAutor: Robert Goldmann\r\n"); + Stage dialogStage = (Stage)alert.getDialogPane().getScene().getWindow(); + dialogStage.getIcons().add(icon); + alert.showAndWait(); + } +} \ No newline at end of file diff --git a/src/application/Main.java b/src/application/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..9bc82570d498dd295703973518a68a7f3f47d6f6 --- /dev/null +++ b/src/application/Main.java @@ -0,0 +1,48 @@ +package application; + +import javafx.application.Application; +import javafx.concurrent.Worker; +import javafx.event.EventHandler; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.stage.Stage; +import javafx.stage.WindowEvent; + +public class Main extends Application +{ + @Override + public void start(Stage stage) + { + try + { + FXMLLoader loader = new FXMLLoader(getClass().getResource("MainGUI.fxml")); + Parent root = (Parent)loader.load(); + + Scene scene = new Scene(root, 800, 600); + + stage.setResizable(true); + stage.setTitle("PlayCount"); + stage.setScene(scene); + stage.setMinHeight(400); + stage.setMinWidth(750); + + Controller controller = (Controller)loader.getController(); + controller.setStage(stage); + controller.init(); + + stage.getIcons().add(new Image("application/icon.png")); + stage.show(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static void main(String[] args) + { + launch(args); + } +} \ No newline at end of file diff --git a/src/application/_de.properties b/src/application/_de.properties new file mode 100644 index 0000000000000000000000000000000000000000..c412094f4bb7009585701e9b6b1106fbb8c12919 --- /dev/null +++ b/src/application/_de.properties @@ -0,0 +1,4 @@ +app.name=PlayCount +version.code=2 +version.name=1.1.0 +version.date=23.03.16 \ No newline at end of file diff --git a/src/application/application.css b/src/application/application.css new file mode 100644 index 0000000000000000000000000000000000000000..83d6f3343843c65d5dfaf3fedb97b6494c19113d --- /dev/null +++ b/src/application/application.css @@ -0,0 +1 @@ +/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/src/application/icon.png b/src/application/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4b756db39463446f4151a2bfcdaca7d9661ca682 Binary files /dev/null and b/src/application/icon.png differ diff --git a/src/logic/AI.java b/src/logic/AI.java new file mode 100644 index 0000000000000000000000000000000000000000..182d1d2f40cf248e4074aa2ef9adecc8c6391516 --- /dev/null +++ b/src/logic/AI.java @@ -0,0 +1,177 @@ +package logic; + +import java.util.ArrayList; +import java.util.Random; + +public class AI +{ + private String name; + private ArrayList<Card> deck; + private int wins; + private Game game; + + public AI(String name, Game game) + { + this.name = name; + deck = new ArrayList<Card>(); + wins = 0; + this.game = game; + } + + public void initialize() + { + deck = new ArrayList<Card>(); + } + + public void win() + { + wins++; + } + + public int getWins() + { + return wins; + } + + public void drawCard(Card card) + { + deck.add(card); + } + + public void drawCards(ArrayList<Card> cards) + { + deck.addAll(cards); + } + + public Card playCard(Card card) + { + deck.remove(card); + return card; + } + + public ArrayList<Card> getValidCards(Card lastCard, Color wishColor, boolean challenge) + { + 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(currentCard.getColor().equals(wishColor) && currentCard.getType().equals(CardType.DRAW_TWO) || currentCard.getType().equals(CardType.DRAW_FOUR)) + { + validCards.add(currentCard); + } + } + } + } + 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 + { + for(Card currentCard : deck) + { + if(currentCard.getColor().equals(wishColor)) + { + validCards.add(currentCard); + } + } + } + } + + return validCards; + } + + public int getDeckSize() + { + return deck.size(); + } + + public String getName() + { + return name; + } + + public void turn(Card lastCard, Color wishColor, boolean challenge) + { + System.out.println("All cards on hand: \n" + deck); + ArrayList<Card> validDeck = getValidCards(lastCard, wishColor, challenge); + System.out.println("validCards: \n" + validDeck); + if(validDeck.size() == 0) + { + if(challenge) + { + drawCards(game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck())); + System.out.println("draw " + game.getChallengeCounter() + " cards"); + 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); + } + } + else + { + System.out.println("choose"); + System.out.println("AI chooses: " + getHighestValuedCard(validDeck)); + + + Card playedCard = getHighestValuedCard(validDeck); + Color newWishColor = null; + + if(playedCard.getType().equals(CardType.WILD) || playedCard.getType().equals(CardType.DRAW_TWO)) + { + Random random = new Random(); + int colorInt = random.nextInt(4) + 1; + switch(colorInt) + { + case 1: newWishColor = Color.YELLOW; + break; + case 2: newWishColor = Color.RED; + break; + case 3: newWishColor = Color.BLUE; + break; + case 4: newWishColor = Color.GREEN; + break; + } + } + + game.playCard(playCard(playedCard), newWishColor); + } + } + + private Card getHighestValuedCard(ArrayList<Card> validDeck) + { + Card highestValuedCard = validDeck.get(0); + for(Card currentCard : validDeck) + { + if(currentCard.getValue() > highestValuedCard.getValue()) + { + highestValuedCard = currentCard; + } + } + + return highestValuedCard; + } +} \ No newline at end of file diff --git a/src/logic/Card.java b/src/logic/Card.java new file mode 100644 index 0000000000000000000000000000000000000000..0359c52bc8077a891d2d6596aa8ce0ad7f3fc485 --- /dev/null +++ b/src/logic/Card.java @@ -0,0 +1,41 @@ +package logic; + +public class Card +{ + private CardType type; + private Color color; + private int value; + + public Card(CardType type, Color color, int value) + { + this.type = type; + this.color = color; + this.value = value; + } + + public CardType getType() + { + return type; + } + + public Color getColor() + { + return color; + } + + public int getValue() + { + return value; + } + + public boolean equals(Card other) + { + return type.equals(other.getType()) && color.equals(other.getColor()); + } + + @Override + public String toString() + { + return "(" + type + ", " + color + ", value=" + value + ")\n"; + } +} \ No newline at end of file diff --git a/src/logic/CardType.java b/src/logic/CardType.java new file mode 100644 index 0000000000000000000000000000000000000000..9b27ebdfe8dd18218a4b37ad495bbb3000d22760 --- /dev/null +++ b/src/logic/CardType.java @@ -0,0 +1,6 @@ +package logic; + +public enum CardType +{ + ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, SKIP, REVERSE, DRAW_TWO, DRAW_FOUR, WILD +} \ No newline at end of file diff --git a/src/logic/Color.java b/src/logic/Color.java new file mode 100644 index 0000000000000000000000000000000000000000..95a7ffdc27535b13edad0492253b1def1ff6db31 --- /dev/null +++ b/src/logic/Color.java @@ -0,0 +1,6 @@ +package logic; + +public enum Color +{ + YELLOW, RED, BLUE, GREEN, BLACK +} diff --git a/src/logic/DeadDeck.java b/src/logic/DeadDeck.java new file mode 100644 index 0000000000000000000000000000000000000000..66d82b14d4635bedd20c85f2d12e52018deec7a6 --- /dev/null +++ b/src/logic/DeadDeck.java @@ -0,0 +1,23 @@ +package logic; + +import java.util.ArrayList; + +public class DeadDeck +{ + private ArrayList<Card> cards; + + public DeadDeck() + { + cards = new ArrayList<Card>(); + } + + public void add(Card card) + { + cards.add(card); + } + + public ArrayList<Card> getCards() + { + return cards; + } +} \ No newline at end of file diff --git a/src/logic/Deck.java b/src/logic/Deck.java new file mode 100644 index 0000000000000000000000000000000000000000..df0070893419779de0be418e1eb911e1feafb52a --- /dev/null +++ b/src/logic/Deck.java @@ -0,0 +1,119 @@ +package logic; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Stack; + +public class Deck +{ + private Stack<Card> cards; + + public Deck() + { + cards = new Stack<Card>(); + + for(Color currentColor : Color.values()) + { + if(currentColor != Color.BLACK) + { + cards.add(new Card(CardType.ZERO, currentColor, 0)); + + for(int i = 0; i < 2; i++) + { + cards.add(new Card(CardType.ONE, currentColor, 0)); + cards.add(new Card(CardType.TWO, currentColor, 0)); + cards.add(new Card(CardType.THREE, currentColor, 0)); + cards.add(new Card(CardType.FOUR, currentColor, 0)); + cards.add(new Card(CardType.FIVE, currentColor, 0)); + cards.add(new Card(CardType.SIX , currentColor, 0)); + cards.add(new Card(CardType.SEVEN, currentColor, 0)); + cards.add(new Card(CardType.EIGHT, currentColor, 0)); + cards.add(new Card(CardType.NINE, currentColor, 0)); + + cards.add(new Card(CardType.REVERSE, currentColor, 1)); + cards.add(new Card(CardType.SKIP, currentColor, 1)); + cards.add(new Card(CardType.DRAW_TWO, currentColor, 2)); + } + } + } + + cards.add(new Card(CardType.DRAW_FOUR, Color.BLACK, 10)); + cards.add(new Card(CardType.DRAW_FOUR, Color.BLACK, 10)); + cards.add(new Card(CardType.DRAW_FOUR, Color.BLACK, 10)); + cards.add(new Card(CardType.DRAW_FOUR, Color.BLACK, 10)); + + cards.add(new Card(CardType.WILD, Color.BLACK, 5)); + cards.add(new Card(CardType.WILD, Color.BLACK, 5)); + cards.add(new Card(CardType.WILD, Color.BLACK, 5)); + cards.add(new Card(CardType.WILD, Color.BLACK, 5)); + } + + public void shuffle() + { + Collections.shuffle(cards); + } + + public Card drawCard(DeadDeck deadDeck) + { + if(cards.size() > 0) + { + return cards.pop(); + } + else + { + refill(deadDeck); + return cards.pop(); + } + } + + public ArrayList<Card> drawCards(int numberOfCards, DeadDeck deadDeck) + { + ArrayList<Card> drawedCards = new ArrayList<Card>(); + for(int i = 0; i < numberOfCards; i++) + { + drawedCards.add(drawCard(deadDeck)); + } + + return drawedCards; + } + + public void refill(DeadDeck deadDeck) + { + for(Card currentCard : deadDeck.getCards()) + { + cards.add(currentCard); + } + + shuffle(); + } + + public Stack<Card> getCards() + { + 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))); + } + + + } +} \ No newline at end of file diff --git a/src/logic/Direction.java b/src/logic/Direction.java new file mode 100644 index 0000000000000000000000000000000000000000..52fd1f8c3dcfe678cad19a6f64139b4a27d554d9 --- /dev/null +++ b/src/logic/Direction.java @@ -0,0 +1,6 @@ +package logic; + +public enum Direction +{ + RIGHT, LEFT +} diff --git a/src/logic/Game.java b/src/logic/Game.java new file mode 100644 index 0000000000000000000000000000000000000000..d2167c813c80ff2e56a4059ee838d5fe92ab080e --- /dev/null +++ b/src/logic/Game.java @@ -0,0 +1,191 @@ +package logic; + +import java.util.ArrayList; +import java.util.Random; + +public class Game +{ + private Deck deck; + private DeadDeck deadDeck; + private Player player; + private ArrayList<AI> ais; + private int gameCount; + private int challengeCounter; + private int currentPlayer; + private Card lastCard; + private Color wishColor; + private boolean challenge; + private Direction direction; + + public Game(int numberOfAIs) + { + deck = new Deck(); + deadDeck = new DeadDeck(); + player = new Player("Spieler", this); + ais = new ArrayList<AI>(); + for(int i = 0; i < numberOfAIs; i++) + { + ais.add(new AI("AI " + i, this)); + } + + gameCount = 0; + challengeCounter = 0; + } + + public void newGame(int numberOfStartingCards) + { + deck = new Deck(); + deck.shuffle(); + deadDeck = new DeadDeck(); + gameCount++; + challengeCounter = 0; + lastCard = null; + wishColor = null; + challenge = false; + direction = Direction.RIGHT; + + player.initialize(); + + player.drawCards(deck.drawCards(numberOfStartingCards, deadDeck)); + + for(AI currentAI : ais) + { + currentAI.initialize(); + currentAI.drawCards(deck.drawCards(numberOfStartingCards, deadDeck)); + } + + deadDeck.add(deck.drawCard(deadDeck)); + lastCard = deadDeck.getCards().get(deadDeck.getCards().size()-1); + System.out.println("lastCard: " + lastCard); + } + + public int getGameCount() + { + return gameCount; + } + + private void start() + { + Random random = new Random(); + currentPlayer = random.nextInt(ais.size() + 1) + 1; + + // DEBUG + currentPlayer = 1; + + while(true) + { + if(!lastCard.getType().equals(CardType.SKIP)) + { + if(lastCard.getType().equals(CardType.REVERSE)) + { + if(direction.equals(Direction.RIGHT)) + { + direction = Direction.LEFT; + } + else + { + direction = Direction.RIGHT; + } + } + + determineNextPlayer(); + + if(currentPlayer == 1) + { + player.turn(lastCard, wishColor, challenge); + if(player.getDeckSize() == 0) + { + end(player.getName()); + break; + } + } + else + { + ais.get(currentPlayer - 2).turn(lastCard, wishColor, challenge); + if(ais.get(currentPlayer - 2).getDeckSize() == 0) + { + end(ais.get(currentPlayer - 2).getName()); + break; + } + } + } + } + } + + private void determineNextPlayer() + { + if(direction.equals(Direction.RIGHT)) + { + if(currentPlayer == ais.size() + 1) + { + currentPlayer = 1; + } + else + { + currentPlayer++; + } + } + else + { + if(currentPlayer == 1) + { + currentPlayer = ais.size() + 1; + } + else + { + currentPlayer--; + } + } + } + + private void end(String name) + { + System.out.println("Player " + name + " wins!"); + } + + public Deck getDeck() + { + return deck; + } + + public DeadDeck getDeadDeck() + { + return deadDeck; + } + + public int getChallengeCounter() + { + return challengeCounter; + } + + public void playCard(Card card, Color wishColor) + { + deadDeck.add(card); + lastCard = card; + this.wishColor = wishColor; + + if(card.getType().equals(CardType.DRAW_TWO)) + { + challenge = true; + challengeCounter += 2; + } + else if(card.getType().equals(CardType.DRAW_FOUR)) + { + challenge = true; + challengeCounter += 4; + } + + System.out.println("new lastCard: " + lastCard); + System.out.println("new wishColor: " + this.wishColor); + System.out.println("new challenge: " + challenge); + System.out.println("new challengeCounter: " + challengeCounter); + } + + public static void main(String[] args) + { + Game game = new Game(3); + game.newGame(5); + game.start(); + } + +} \ No newline at end of file diff --git a/src/logic/Player.java b/src/logic/Player.java new file mode 100644 index 0000000000000000000000000000000000000000..064c659534be8785545d9f87e90727a65206218a --- /dev/null +++ b/src/logic/Player.java @@ -0,0 +1,151 @@ +package logic; + +import java.util.ArrayList; + +public class Player +{ + private String name; + private ArrayList<Card> deck; + private int wins; + private Game game; + + public Player(String name, Game game) + { + this.name = name; + deck = new ArrayList<Card>(); + wins = 0; + this.game = game; + } + + public void initialize() + { + deck = new ArrayList<Card>(); + } + + public void win() + { + wins++; + } + + public int getWins() + { + return wins; + } + + public void drawCard(Card card) + { + deck.add(card); + } + + public void drawCards(ArrayList<Card> cards) + { + deck.addAll(cards); + } + + public Card playCard(Card card) + { + deck.remove(card); + return card; + } + + public ArrayList<Card> getValidCards(Card lastCard, Color wishColor, boolean challenge) + { + 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(currentCard.getColor().equals(wishColor) && currentCard.getType().equals(CardType.DRAW_TWO) || currentCard.getType().equals(CardType.DRAW_FOUR)) + { + validCards.add(currentCard); + } + } + } + } + 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 + { + for(Card currentCard : deck) + { + if(currentCard.getColor().equals(wishColor)) + { + validCards.add(currentCard); + } + } + } + } + + return validCards; + } + + public int getDeckSize() + { + return deck.size(); + } + + public String getName() + { + return name; + } + + public void turn(Card lastCard, Color wishColor, boolean challenge) + { + System.out.println("All cards on hand: \n" + deck); + ArrayList<Card> validDeck = getValidCards(lastCard, wishColor, challenge); + System.out.println("validCards: \n" + validDeck); + if(validDeck.size() == 0) + { + if(challenge) + { + drawCards(game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck())); + System.err.println("draw " + game.getChallengeCounter() + " cards"); + System.out.println("deack after draw: " + deck); + } + else + { + drawCard(game.getDeck().drawCard(game.getDeadDeck())); + System.err.println("draw one card"); + System.out.println("deack after draw: " + deck); + } + } + else + { + System.out.println("choose"); + //playerInput (draw or turnCard) + + //DEBUG + Card playedCard = null; + Color newWishColor = null; + + if(playedCard.getType().equals(CardType.WILD) || playedCard.getType().equals(CardType.DRAW_TWO)) + { + //TODO choose color + //DEBUG + newWishColor = Color.BLUE; + } + + game.playCard(playCard(playedCard), newWishColor); + } + } +} \ No newline at end of file