diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..659bf43 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..467eb98 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..69a9715 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..744e882 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MSYS* | MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/Controller/Controller.java b/src/main/java/Controller/Controller.java index 6df8dc0..c10fd08 100644 --- a/src/main/java/Controller/Controller.java +++ b/src/main/java/Controller/Controller.java @@ -3,16 +3,15 @@ import java.util.ArrayList; import Entity.Card; -import Entity.Player; -import UseCase.BasicOperations; -import UseCase.Status; +import UseCase.FunctionManager; +import UseCase.GameStatusManager; /** * The main.Controller to run a game. */ public class Controller { - private BasicOperations basicOperations; + private FunctionManager functionManager; private EachRound eachRound; /** @@ -20,7 +19,7 @@ public class Controller { * @return the player that wins. */ public String runGame() { - Status vars = basicOperations.getVars(); + GameStatusManager vars = functionManager.getGameStatusManager(); // if winFlag is true, it means the winner appears and the while loop exits. while (!vars.isWinFlag()) { // cardToPlay is the card that the player wants to play. @@ -37,13 +36,13 @@ public String runGame() { // Move to the next player vars.setCurrentPlayerIndex( - basicOperations.getVars().moveToNextPlayer(vars.isReverse())); + functionManager.getGameStatusManager().moveToNextPlayer(vars.isReverse())); } return vars.getPlayerWins().getId(); } - public void setBasicOperations(BasicOperations basicOperations) { - this.basicOperations = basicOperations; + public void setBasicOperations(FunctionManager functionManager) { + this.functionManager = functionManager; } public void setEachRound(EachRound eachRound) { diff --git a/src/main/java/Controller/ControllerBuilder.java b/src/main/java/Controller/ControllerBuilder.java index a43f62a..2a8df55 100644 --- a/src/main/java/Controller/ControllerBuilder.java +++ b/src/main/java/Controller/ControllerBuilder.java @@ -15,7 +15,7 @@ public class ControllerBuilder implements Builder { private ArrayList colors; private Dealer dealer; private EachRound eachRound; - private BasicOperations basicOperations; + private FunctionManager functionManager; public ControllerBuilder(int numberOfPlayers){ this.numberOfPlayers = numberOfPlayers; @@ -46,7 +46,7 @@ public void cardDeal(){ } public void buildColors(){ - Readfile readfile = new Cardreadfile(); + Readfile readfile = new cardreadfile(); this.colors = readfile.readFromFile("src/main/resources/numbercards.txt", "src/main/resources/functioncards.txt", cardManager); } @@ -56,13 +56,13 @@ public void buildDealer(){ } public void buildBasicOperations(){ - Status status = new Status(numberOfPlayers); - GameBoard gameBoard = new GameBoard(numberOfPlayers); - this.basicOperations = new BasicOperations(status, gameBoard); + GameStatusManager gameStatusManager = new GameStatusManager(numberOfPlayers); + LastCardManager lastCardManager = new LastCardManager(); + this.functionManager = new FunctionManager(gameStatusManager, lastCardManager); } public void buildEachRound(){ - this.eachRound = new EachRound(playerManager, cardManager, dealer, basicOperations); + this.eachRound = new EachRound(playerManager, cardManager, dealer, functionManager); } public Controller buildUnoController(){ @@ -74,7 +74,7 @@ public Controller buildUnoController(){ this.buildBasicOperations(); this.buildEachRound(); Controller temp = new Controller(); - temp.setBasicOperations(basicOperations); + temp.setBasicOperations(functionManager); temp.setEachRound(eachRound); return temp; diff --git a/src/main/java/Controller/Dealer.java b/src/main/java/Controller/Dealer.java index dcaa8a8..5e07f56 100644 --- a/src/main/java/Controller/Dealer.java +++ b/src/main/java/Controller/Dealer.java @@ -1,10 +1,10 @@ package Controller; import Entity.Card; -import UseCase.BasicOperations; +import UseCase.FunctionManager; import UseCase.DeckManager; import UseCase.PlayerManager; -import UseCase.Status; +import UseCase.GameStatusManager; import java.util.ArrayList; import java.util.Collections; @@ -82,10 +82,10 @@ public void plusManyNextPlayer(int currentPlayerIndex, int num) { /** * Check whether the last card played is valid * @param cardToPlay the card player would play - * @param basicOperations variables and settings + * @param functionManager variables and settings */ - public void checkLastCard(Card cardToPlay, BasicOperations basicOperations){ - Status vars = basicOperations.getVars(); + public void checkLastCard(Card cardToPlay, FunctionManager functionManager){ + GameStatusManager vars = functionManager.getGameStatusManager(); // create the arrayList for all possible number features ArrayList num = new ArrayList<>(); @@ -96,12 +96,12 @@ public void checkLastCard(Card cardToPlay, BasicOperations basicOperations){ String feature = cardManager.feature(cardToPlay); // if the player plays a function card if (!num.contains(feature)) { - // if it is the last card that the palyer plays is a function card, draw a card. + // if it is the last card that the player plays is a function card, draw a card. if (playerManager.winOrNot(vars.getCurrentPlayerIndex())) { Card c = cardManager.drawCardFromUnusedDeck(); playerManager.getPlayers()[vars.getCurrentPlayerIndex()].drawCard(c); } - basicOperations.functionCardResponse(vars, feature); + functionManager.functionCardResponse(vars, feature); } } } @@ -109,20 +109,20 @@ public void checkLastCard(Card cardToPlay, BasicOperations basicOperations){ /** * Operations when current player has no card to play * @param currentCardsPlayerCanPlay cards can be played - * @param basicOperations variables and settings + * @param functionManager variables and settings */ public void operationsWhenNoCardToPlay(ArrayList currentCardsPlayerCanPlay, - BasicOperations basicOperations) { - if (basicOperations.getVars().getPlus() > 0) { - plusManyNextPlayer(basicOperations.getVars().getCurrentPlayerIndex(), - basicOperations.getVars().getPlus()); - basicOperations.getVars().setPlus(0); + FunctionManager functionManager) { + if (functionManager.getGameStatusManager().getPlus() > 0) { + plusManyNextPlayer(functionManager.getGameStatusManager().getCurrentPlayerIndex(), + functionManager.getGameStatusManager().getPlus()); + functionManager.getGameStatusManager().setPlus(0); } else if (!cardManager.feature(playerManager.getLastCard()).equals("skip") || (cardManager.feature(playerManager.getLastCard()).equals("skip") && - !basicOperations.getVars().isSkip())){ + !functionManager.getGameStatusManager().isSkip())){ // draw a card when there is no valid card can play drawCardWhenNoCardToPlay(currentCardsPlayerCanPlay, - basicOperations.getVars().getCurrentPlayerIndex()); + functionManager.getGameStatusManager().getCurrentPlayerIndex()); } } diff --git a/src/main/java/Controller/EachRound.java b/src/main/java/Controller/EachRound.java index 8cfa79d..69c5f9d 100644 --- a/src/main/java/Controller/EachRound.java +++ b/src/main/java/Controller/EachRound.java @@ -1,10 +1,10 @@ package Controller; import Entity.Card; -import UseCase.BasicOperations; +import UseCase.FunctionManager; import UseCase.DeckManager; import UseCase.PlayerManager; -import UseCase.Status; +import UseCase.GameStatusManager; import java.util.ArrayList; import java.util.Scanner; @@ -14,14 +14,14 @@ public class EachRound { private final PlayerManager playerManager; private final DeckManager cardManager; private final Dealer dealer; - private final BasicOperations basicOperations; + private final FunctionManager functionManager; public EachRound(PlayerManager playerManager, DeckManager cardManager, - Dealer dealer, BasicOperations basicOperations) { + Dealer dealer, FunctionManager functionManager) { this.playerManager = playerManager; this.cardManager = cardManager; this.dealer = dealer; - this.basicOperations = basicOperations; + this.functionManager = functionManager; } public Card createNullCard(){ @@ -80,14 +80,14 @@ public Card letPlayerPlayCard(ArrayList currentCardsPlayerCanPlay, * @return Cards player can play in this round */ public ArrayList beginStage(){ - Status vars = basicOperations.getVars(); + GameStatusManager vars = functionManager.getGameStatusManager(); // show the current player System.out.println(); System.out.println("Current player: " + playerManager.getPlayers()[vars.getCurrentPlayerIndex()]); // get cards player can play considering special cases of function cards - return basicOperations.getCardsCurrentPlayerCanPlay + return functionManager.getCardsCurrentPlayerCanPlay (playerManager.getPlayers()[vars.getCurrentPlayerIndex()]); } @@ -98,9 +98,9 @@ public ArrayList beginStage(){ * @return the updated cardToPlay player has played */ public Card playStage(ArrayList currentCardsPlayerCanPlay, Card cardToPlay){ - Status vars = basicOperations.getVars(); + GameStatusManager vars = functionManager.getGameStatusManager(); if (currentCardsPlayerCanPlay.isEmpty()) { - dealer.operationsWhenNoCardToPlay(currentCardsPlayerCanPlay, basicOperations); + dealer.operationsWhenNoCardToPlay(currentCardsPlayerCanPlay, functionManager); } else { // print all the information @@ -117,7 +117,7 @@ public Card playStage(ArrayList currentCardsPlayerCanPlay, Card cardToPlay if (!cardManager.color(cardToPlay).equals("white") && !cardManager.whetherNull(cardToPlay)){ // update the last card stored in gameBoard - basicOperations.getGameBoard().setLastCard(cardToPlay); + functionManager.getGameBoard().setLastCard(cardToPlay); } } return cardToPlay; @@ -128,12 +128,12 @@ public Card playStage(ArrayList currentCardsPlayerCanPlay, Card cardToPlay * @param cardToPlay the card player has played this turn */ public void endStage(Card cardToPlay){ - Status vars = basicOperations.getVars(); + GameStatusManager vars = functionManager.getGameStatusManager(); // set the skip to false since the function skip has passed. vars.setSkip(false); - dealer.checkLastCard(cardToPlay, basicOperations); + dealer.checkLastCard(cardToPlay, functionManager); // Determine whether the player wins or not. if (playerManager.winOrNot(vars.getCurrentPlayerIndex())) { diff --git a/src/main/java/Controller/Readfile.java b/src/main/java/Controller/Readfile.java index 3213e8f..9ddd1fc 100644 --- a/src/main/java/Controller/Readfile.java +++ b/src/main/java/Controller/Readfile.java @@ -13,11 +13,6 @@ import java.util.ArrayList; public interface Readfile { -// /** -// * @param filepath location of ser file -// * @param o object to be serialized -// */ -// void saveToFile(String filepath, Object o) throws IOException; /** * @param numfilepath number card location diff --git a/src/main/java/Controller/Cardreadfile.java b/src/main/java/Controller/cardreadfile.java similarity index 91% rename from src/main/java/Controller/Cardreadfile.java rename to src/main/java/Controller/cardreadfile.java index 6df6290..132d1cd 100644 --- a/src/main/java/Controller/Cardreadfile.java +++ b/src/main/java/Controller/cardreadfile.java @@ -6,7 +6,7 @@ import java.io.*; import java.util.ArrayList; -public class Cardreadfile implements Readfile { +public class cardreadfile implements Readfile { // gateway class // @Override // public void saveToFile(String filepath, Object users) throws IOException { @@ -20,7 +20,7 @@ public class Cardreadfile implements Readfile { // output.close(); // } - public ArrayList readFromFile(String numfilePath, String funfilepath, DeckManager deckManager){ + public ArrayList readFromFile(String numFilePath, String funFilePath, DeckManager deckManager){ // InputStream file = new FileInputStream(filePath); // InputStream buffer = new BufferedInputStream(file); @@ -34,8 +34,8 @@ public ArrayList readFromFile(String numfilePath, String funfilepath, De ArrayList colors = new ArrayList<>(); try { - BufferedReader numberFile = new BufferedReader(new FileReader(numfilePath)); - BufferedReader functionFile = new BufferedReader(new FileReader(funfilepath)); + BufferedReader numberFile = new BufferedReader(new FileReader(numFilePath)); + BufferedReader functionFile = new BufferedReader(new FileReader(funFilePath)); String numberLine = numberFile.readLine(); String functionLine = functionFile.readLine(); while (numberLine != null){ diff --git a/src/main/java/Entity/Card.java b/src/main/java/Entity/Card.java index 17efe1c..53a73a4 100644 --- a/src/main/java/Entity/Card.java +++ b/src/main/java/Entity/Card.java @@ -11,9 +11,10 @@ public class Card implements Serializable { /** * Construct the individual card with info implemented in UNO card game. * - * giving the card the given color, number, function + * Giving the card the given color, number, function * - * @param color The card's color + * @param color The card's color . + * @param id The card's id, for distinguish different cards of the same number and color. */ public Card(String color, String id){ @@ -26,31 +27,41 @@ public Card(String color, String id){ */ public Card(){ this.color = "black"; - this.id = "nullid"; + this.id = "null"; } /** - * Variety of getter functions that returns the param of the card accordingly + * Variety of getter functions that returns the param of the card accordingly. */ public String getColor(){ return color; } + /** + * Get the id of the card. + * + * @return A string respond to the id of the card. + */ public String getId() { return id; } + /** + * String representation for the Card. + */ public String toString() { return "Id:" + id; } + /** + * Feature of the card. + * + * @return String "null", which means the card is a default card. + * Number for a number card and function for a function card. + */ public String getFeature(){ - return "nullfeature"; + return "null"; } - // test code -// public static void main(String[] args){ -// Card c1 = new Card("red", 2, null); -// System.out.println(c1.getColor()); -// } } + diff --git a/src/main/java/Entity/Deck.java b/src/main/java/Entity/Deck.java index 2a5172e..02ff08a 100644 --- a/src/main/java/Entity/Deck.java +++ b/src/main/java/Entity/Deck.java @@ -9,7 +9,7 @@ public class Deck implements Serializable{ private ArrayList unused; /** - * Construct the Deck in UNO card game. + * Construct a empty deck in UNO card game. * */ public Deck(){ @@ -18,7 +18,7 @@ public Deck(){ } /** - * To check whether the unused_card_deck is empty. + * Check whether the unused_card_deck is empty. * * If the card deck is empty, Placed all the used card into the card deck. */ @@ -27,60 +27,74 @@ public boolean isEmpty(){ } /** - * To add a card into the used_card_deck. + * Add a card into the used_card_deck. * */ - public void addcard(Card card) { + public void addCard(Card card) { unused.add(card); } /** - * To return the numbers of card in a card deck. + * Get the numbers of card in a card deck. * - * @return the numbers of card in a card deck. + * @return The number of card in a card deck. */ public int numOfCards(ArrayList deck) { return deck.size(); } /** - * getter - * @return unsed_card_deck + * Get the number of used card in the deck. + * + * @return Number of used card in the deck. */ public ArrayList getUsedCardDeck(){ return used; } /** - * setter - * @param replacement the new deck to replace the old one + * Set the used card deck. + * + * @param replacement the new deck to replace the old one. */ public void setUsedCardDeck(ArrayList replacement){ used = replacement; } /** - * getter - * @return unused_card_deck + * Get the number of unused card in the deck. + * + * @return umber of unused card in the deck. */ public ArrayList getUnusedCardDeck(){ return unused; } /** - * setter - * @param replacement the new deck to replace the old one + * Set the unused card deck. + * + * @param replacement the new deck to replace the old one. */ public void setUnusedCardDeck(ArrayList replacement){ unused = replacement; } + /** + * Draw card form the unused card deck. + * + * @return The card that drawn from unused deck. + */ public Card drawCardFromUnusedDeck() { Random rand = new Random(); int index = rand.nextInt(unused.size()); return unused.remove(index); } + /** + * Shuffle the card from the used card deck to the unused card deck. + * + * @return Whether successful or not. + */ public boolean shuffleFromUsedToUnused() { if (used.isEmpty()) { return false; @@ -93,8 +107,13 @@ public boolean shuffleFromUsedToUnused() { } - public void putCardToUsedDeck(Card c) { - used.add(c); + /** + * Put card in to the used Card deck. + * + * @param card The card that will be put. + */ + public void putCardToUsedDeck(Card card) { + used.add(card); } } diff --git a/src/main/java/Entity/FunctionCard.java b/src/main/java/Entity/FunctionCard.java index 40dc158..5e63f89 100644 --- a/src/main/java/Entity/FunctionCard.java +++ b/src/main/java/Entity/FunctionCard.java @@ -5,21 +5,30 @@ public class FunctionCard extends Card{ private String function; /** + * Construct a function card. * - * @param color The color of the function card - * @param id The id of the function card - * @param function The card's function + * @param color The color of the function card . + * @param id The id of the function card. + * @param function The card's function . */ public FunctionCard(String color, String function, String id) { super(color ,id); this.function = function; } + /** + * Construct a function card with default value. + */ public FunctionCard(){ super(); - this.function = "nullfunction"; + this.function = "null"; } + /** + * Get the function. + * + * @return Function the card can do. + */ public String getFunction() { return function; } diff --git a/src/main/java/Entity/NumberCard.java b/src/main/java/Entity/NumberCard.java index 51898b7..a30bec3 100644 --- a/src/main/java/Entity/NumberCard.java +++ b/src/main/java/Entity/NumberCard.java @@ -5,21 +5,30 @@ public class NumberCard extends Card { private int number; /** + * Construct a number card. * - * @param color - * @param number The card's number <0~9, -1> - * @param id + * @param color The color of the card . + * @param number The card's number <0~9, -1>. + * @param id The id of the card. */ public NumberCard(String color, int number, String id) { super(color, id); this.number = number; } + /** + * Construct a number card with default value. + */ public NumberCard() { super(); this.number = -1; } + /** + * Get the number of this card. + * + * @return Number of the card. + */ public int getNumber(){ return number; } diff --git a/src/main/java/Entity/Player.java b/src/main/java/Entity/Player.java index eabe94f..8f10693 100644 --- a/src/main/java/Entity/Player.java +++ b/src/main/java/Entity/Player.java @@ -6,38 +6,74 @@ import Entity.Card; -public class Player implements Iterable{ - - private String id; - private int position; - private ArrayList handCard; - +public class Player implements Iterable{ + + private final String id; + private final int position; + private final ArrayList handCard; + + /** + * Construct a player with certain id and position. + * + * @param id The id of the player. + * @param position The position of the player in this round. + */ public Player(String id, int position){ this.id = id; this.position = position; this.handCard = new ArrayList(); } - public void drawCard(Card c){ - handCard.add(c); + /** + * Draw a card from deck. + * @param card Drawn card. + */ + public void drawCard(Card card){ + handCard.add(card); } - public Card playCard(Card c){ - return handCard.remove(handCard.indexOf(c)); + /** + * Play this card, after that, the card should be removed from our hand. + * + * @param card The card we tried to play. + * @return The card which is removed from our hand. + */ + public Card playCard(Card card){ + return handCard.remove(handCard.indexOf(card)); } + /** + * Get how many card the Player holds. + * + * @return An int which represent the number of cards in the players hand. + */ public int getCardNum(){ return handCard.size(); } + /** + * Get cards in the players hand. + * + * @return An arraylist which include all cards in the players hand. + */ public ArrayList getHandCard(){ return handCard; } + /** + * Get the id of the player. + * + * @return A string which is the id of the player. + */ public String getId(){ return id; } + /** + * Get the position of the player. + * + * @return A string which is the position of the player. + */ public int getPosition(){ return position; } diff --git a/src/main/java/UseCase/DeckManager.java b/src/main/java/UseCase/DeckManager.java index a568574..72bb785 100644 --- a/src/main/java/UseCase/DeckManager.java +++ b/src/main/java/UseCase/DeckManager.java @@ -2,45 +2,44 @@ import Entity.*; -import java.io.IOException; import java.util.ArrayList; public class DeckManager { - private Deck d; + private Deck deck; public DeckManager() { - this.d = new Deck(); + this.deck = new Deck(); } - public DeckManager(Deck d) { - this.d = d; + public DeckManager(Deck deck) { + this.deck = deck; } public void shuffleFromUsedToUnused() { - d.shuffleFromUsedToUnused(); + deck.shuffleFromUsedToUnused(); } public void initializeCard(ArrayList cards) { - d.setUnusedCardDeck(cards); + deck.setUnusedCardDeck(cards); } public void putCardToUsedDeck(Card c) { - d.putCardToUsedDeck(c); + deck.putCardToUsedDeck(c); } public Card drawCardFromUnusedDeck() { - if (d.getUnusedCardDeck().size() == 0) { - boolean noCard = d.shuffleFromUsedToUnused(); + if (deck.getUnusedCardDeck().size() == 0) { + boolean noCard = deck.shuffleFromUsedToUnused(); if (!noCard) { return new Card(); // shouldn't we throw exception here? } } - return d.drawCardFromUnusedDeck(); + return deck.drawCardFromUnusedDeck(); } public boolean checkShuffle() { - return d.getUnusedCardDeck().size() == 0; + return deck.getUnusedCardDeck().size() == 0; } public Card extractCard(ArrayList cards, String id) { @@ -53,7 +52,7 @@ public Card extractCard(ArrayList cards, String id) { } public boolean whetherNull(Card c) { - return c.getId().equals("nullid"); + return c.getId().equals("null"); } public String color(Card c){ @@ -75,7 +74,7 @@ public static boolean compareTwoCardsHaveSameFeature(Card lastCard, Card c2, Str c2.getColor().equals(currentColor); } return lastCard.getFeature().equals(c2.getFeature())|| lastCard.getColor().equals(c2.getColor()) - || c2.getId().equals("nullid"); + || c2.getId().equals("null"); } public boolean compareTwoCardsHaveSameColor(Card c1, Card c2) { @@ -95,6 +94,6 @@ public String feature(Card c) { } public void addCard(Card c) { - d.addcard(c); + deck.addCard(c); } } diff --git a/src/main/java/UseCase/BasicOperations.java b/src/main/java/UseCase/FunctionManager.java similarity index 69% rename from src/main/java/UseCase/BasicOperations.java rename to src/main/java/UseCase/FunctionManager.java index 5afdf9d..07796e8 100644 --- a/src/main/java/UseCase/BasicOperations.java +++ b/src/main/java/UseCase/FunctionManager.java @@ -11,39 +11,39 @@ * Contains the basic operations and game status variables, * which are extracted from controller */ -public class BasicOperations { +public class FunctionManager { - private final Status vars; - private final GameBoard gameBoard; + private final GameStatusManager gameStatusManager; + private final LastCardManager lastCardManager; - public BasicOperations(Status statVars, GameBoard gameBoard){ - this.vars = statVars; - this.gameBoard = gameBoard; + public FunctionManager(GameStatusManager gameStatusManager, LastCardManager lastCardManager){ + this.gameStatusManager = gameStatusManager; + this.lastCardManager = lastCardManager; } /** * Extracted from controller - * @param vars the variables, will be changed correspondingly + * @param gameStatusManager the status, will be changed correspondingly * @param feature feature of the played function card */ - public void functionCardResponse(Status vars, String feature){ + public void functionCardResponse(GameStatusManager gameStatusManager, String feature){ switch (feature) { case "skip": - vars.setSkip(true); + gameStatusManager.setSkip(true); break; case "reverse": - vars.setReverse(!vars.isReverse()); + gameStatusManager.setReverse(!gameStatusManager.isReverse()); break; case "plustwo": - vars.setPlus(vars.getPlus() + 2); + gameStatusManager.setPlus(gameStatusManager.getPlus() + 2); break; case "switch": { - gameBoard.typeSetColor(); + lastCardManager.typeSetColor(); break; } default: { - vars.setPlus(vars.getPlus() + 4); - gameBoard.typeSetColor(); + gameStatusManager.setPlus(gameStatusManager.getPlus() + 4); + lastCardManager.typeSetColor(); break; } } @@ -57,11 +57,11 @@ public void functionCardResponse(Status vars, String feature){ public ArrayList getCardsCurrentPlayerCanPlay(Player player){ // Get the cards that the current player can play. // if the last card is skip, player only can play skip - if (vars.isSkip()) { + if (gameStatusManager.isSkip()) { return skipsPlayerCanPlay(player.getHandCard()); - } else if (vars.getPlus() > 0){ + } else if (gameStatusManager.getPlus() > 0){ // if the last card is plus2, player can play plus2 or plus4. - if (gameBoard.getLastCard().getFeature().equals("plustwo")) { + if (lastCardManager.getLastCard().getFeature().equals("plustwo")) { return plustwoPlayerCanPlay(player.getHandCard()); } else { // if the last card is plus4, player can only play plus4. @@ -71,7 +71,7 @@ public ArrayList getCardsCurrentPlayerCanPlay(Player player){ // get the cards that the current player can play normally return cardsPlayerCanPlay( player.getHandCard(), - gameBoard.getLastCard()); + lastCardManager.getLastCard()); } } @@ -109,7 +109,7 @@ public ArrayList plusfourPlayerCanPlay(ArrayList cards) { public ArrayList cardsPlayerCanPlay(ArrayList cards, Card lastCard) { ArrayList cardsCanPlay = new ArrayList(); - if (lastCard.getId().equals("nullid")) { + if (lastCard.getId().equals("null")) { return (ArrayList) cards.clone(); } for (Card c: cards) { @@ -121,15 +121,15 @@ public ArrayList cardsPlayerCanPlay(ArrayList cards, Card lastCard) return cardsCanPlay; } - public Status getVars() { - return vars; + public GameStatusManager getGameStatusManager() { + return gameStatusManager; } - public GameBoard getGameBoard() { - return gameBoard; + public LastCardManager getGameBoard() { + return lastCardManager; } public String getColor(){ - return gameBoard.getColor(); + return lastCardManager.getColor(); } } diff --git a/src/main/java/UseCase/GameStatusManager.java b/src/main/java/UseCase/GameStatusManager.java new file mode 100644 index 0000000..45a9138 --- /dev/null +++ b/src/main/java/UseCase/GameStatusManager.java @@ -0,0 +1,162 @@ +package UseCase; + +import Entity.Player; + +import java.util.Random; +/** + *This class manages the status of a game, status contains six main attributes: + * 1.Whether a winner appears. + * 2.The current player. + * 3.Whether the current player need to skip the turn. + * 4.How many card the current player need to draw. + * 5.Order of the game. + * 6.Number of players. + *Also, it contains two ability: + * 1.Construct the status of a new game with a random player started. + * 2.Control the next player by the order of the game. + */ +public class GameStatusManager { + // Winner. + private Player Winner = null; + // The order of the game. + private boolean reverse = false; + // WinFlag is used to indicate whether a winner appears. + private boolean winFlag = false; + // Randomly select a player to play the first card. + private final Random rand = new Random(); + private int currentPlayerIndex; + // Whether the current player need to skip the turn. + private boolean skip = false; + // How many card the current player need to draw. + private int plus = 0; + // Number of players. + private final int numberOfPlayers; + + /** + * Construct the status of a new game with a random player started. + * + * @param numberOfPlayers Number of players. + */ + public GameStatusManager(int numberOfPlayers){ + this.numberOfPlayers = numberOfPlayers; + this.currentPlayerIndex = rand.nextInt(numberOfPlayers); + } + + /** + * + * @return Whether a winner appears. If no, return "null". + */ + public Player getPlayerWins() { + return Winner; + } + + /** + * + * @param winner Set a winner. + */ + public void setPlayerWins(Player winner) { + this.Winner = winner; + } + + /** + * + * @return Order of the game. + */ + public boolean isReverse() { + return reverse; + } + + /** + * + * @param reverse Set the order of the game. + */ + public void setReverse(boolean reverse) { + this.reverse = reverse; + } + + /** + * + * @return Whether a winner appears. + */ + public boolean isWinFlag() { + return winFlag; + } + + /** + * + * @param winFlag Set whether a winner appears. + */ + public void setWinFlag(boolean winFlag) { + this.winFlag = winFlag; + } + + /** + * + * @return Current player. + */ + public int getCurrentPlayerIndex() { + return currentPlayerIndex; + } + + /** + * + * @param currentPlayerIndex Set the current player. + */ + public void setCurrentPlayerIndex(int currentPlayerIndex) { + this.currentPlayerIndex = currentPlayerIndex; + } + + /** + * Extracted from controller, which control the next player by the order of the game. + * @param reverse Order of the game. + * + * @return The next player. + */ + public int moveToNextPlayer(boolean reverse) { + // Move to the next player + if (!reverse){ + currentPlayerIndex++; + if (currentPlayerIndex == numberOfPlayers) { + currentPlayerIndex = 0; + } + } else { + currentPlayerIndex--; + if (currentPlayerIndex == -1) { + currentPlayerIndex = numberOfPlayers - 1; + } + } + return currentPlayerIndex; + } + + /** + * + * @return Whether the current player need to skip the turn. + */ + public boolean isSkip() { + return skip; + } + + /** + * + * @param skip Set whether the current player need to skip the turn. + */ + public void setSkip(boolean skip) { + this.skip = skip; + } + + /** + * + * @return How many card the current player need to draw. + */ + public int getPlus() { + return plus; + } + + /** + * + * @param plus Set how many card the current player need to draw. + */ + public void setPlus(int plus) { + this.plus = plus; + } +} diff --git a/src/main/java/UseCase/GameBoard.java b/src/main/java/UseCase/LastCardManager.java similarity index 84% rename from src/main/java/UseCase/GameBoard.java rename to src/main/java/UseCase/LastCardManager.java index 251e86c..0e43a06 100644 --- a/src/main/java/UseCase/GameBoard.java +++ b/src/main/java/UseCase/LastCardManager.java @@ -9,19 +9,15 @@ * Gameboard stores playCount and controls current position, color, and lastCard played. * This will be embedded in the controller. */ -public class GameBoard { +public class LastCardManager { - private final int numberOfPlayers; private String color; - private int currentPlayer; private Card lastCard; private final Scanner keyBoard; private final ArrayList colors = new ArrayList(); - public GameBoard(int numberOfPlayers){ - this.numberOfPlayers = numberOfPlayers; + public LastCardManager(){ this.color = "black"; - this.currentPlayer = (int)(Math.random() * numberOfPlayers); this.lastCard = new Card(); this.keyBoard = new Scanner(System.in); colors.add("red"); colors.add("blue"); colors.add("green"); colors.add("yellow"); @@ -65,10 +61,6 @@ public String getRandColor(){ return colors.get((int)(Math.random() * colors.size())); } - public int getCurrentPlayer() { - return currentPlayer; - } - public Card getLastCard() { return lastCard; } diff --git a/src/main/java/UseCase/Status.java b/src/main/java/UseCase/Status.java deleted file mode 100644 index adec2b6..0000000 --- a/src/main/java/UseCase/Status.java +++ /dev/null @@ -1,102 +0,0 @@ -package UseCase; - -import Entity.Player; - -import java.util.Random; - -public class Status { - - private Player playerWins = null; - - // whether reverse - private boolean reverse = false; - - // winFlag is used to indicate whether a winner appears. - private boolean winFlag = false; - - // Randomly select a player to play the first card. - private final Random rand = new Random(); - private int currentPlayerIndex = -1; - - // whether the turn of player should be skipped - private boolean skip = false; - - //whether there are cards that needed to drawed for the player - private int plus = 0; - - private final int numberOfPlayers; - - public Status(int numberOfPlayers){ - this.numberOfPlayers = numberOfPlayers; - this.currentPlayerIndex = rand.nextInt(numberOfPlayers); - } - - public Player getPlayerWins() { - return playerWins; - } - - public void setPlayerWins(Player playerWins) { - this.playerWins = playerWins; - } - - public boolean isReverse() { - return reverse; - } - - public void setReverse(boolean reverse) { - this.reverse = reverse; - } - - public boolean isWinFlag() { - return winFlag; - } - - public void setWinFlag(boolean winFlag) { - this.winFlag = winFlag; - } - - public int getCurrentPlayerIndex() { - return currentPlayerIndex; - } - - public void setCurrentPlayerIndex(int currentPlayerIndex) { - this.currentPlayerIndex = currentPlayerIndex; - } - - /** - * Extracted from controller, which control position change after each turn. - * @param reverse whether reverse sequence or not - * @return next corresponding position - */ - public int moveToNextPlayer(boolean reverse) { - // Move to the next player - if (!reverse){ - currentPlayerIndex++; - if (currentPlayerIndex == numberOfPlayers) { - currentPlayerIndex = 0; - } - } else { - currentPlayerIndex--; - if (currentPlayerIndex == -1) { - currentPlayerIndex = numberOfPlayers - 1; - } - } - return currentPlayerIndex; - } - - public boolean isSkip() { - return skip; - } - - public void setSkip(boolean skip) { - this.skip = skip; - } - - public int getPlus() { - return plus; - } - - public void setPlus(int plus) { - this.plus = plus; - } -} diff --git a/src/test/java/Entity/CardTest.java b/src/test/java/Entity/CardTest.java index 9ae3ce9..710b6b3 100644 --- a/src/test/java/Entity/CardTest.java +++ b/src/test/java/Entity/CardTest.java @@ -20,12 +20,12 @@ public void testGetColor(){ @Test public void testGetID(){ assertEquals("25", c1.getId()); - assertEquals("nullid", c2.getId()); + assertEquals("null", c2.getId()); } @Test public void testToString(){ assertEquals("Id:25", c1.toString()); - assertEquals("Id:nullid", c2.toString()); + assertEquals("Id:null", c2.toString()); } } diff --git a/src/test/java/Entity/DeckTest.java b/src/test/java/Entity/DeckTest.java index 1551c12..299e855 100644 --- a/src/test/java/Entity/DeckTest.java +++ b/src/test/java/Entity/DeckTest.java @@ -17,33 +17,30 @@ public void testIsEmpty() { } -// @Test -// public void testNumOfCards() { -// Deck d1 = new Deck(); -// assertEquals(108, d1.numOfCards(d1.getUnusedCardDeck())); -// } + @Test + public void testNumOfCards() { + Deck d1 = new Deck(); + assertEquals(0, d1.numOfCards(d1.getUnusedCardDeck())); + } @Test public void testGetUsedCardDeck() { Deck d1 = new Deck(); - ArrayList a1 = new ArrayList<>(); - assertEquals(a1, d1.getUsedCardDeck()); + assertTrue(d1.getUsedCardDeck().isEmpty()); } @Test public void testSetUsedCardDeck() { Deck d1 = new Deck(); ArrayList a1 = new ArrayList<>(); - Deck d2 = new Deck(); d1.setUsedCardDeck(a1); - assertEquals(a1, d1.getUsedCardDeck()); + assertTrue(d1.getUsedCardDeck().isEmpty()); } @Test public void testGetUnusedCardDeck() { Deck d1 = new Deck(); - ArrayList a1 = d1.getUnusedCardDeck(); - assertEquals(a1, d1.getUnusedCardDeck()); + assertTrue(d1.getUnusedCardDeck().isEmpty()); // Need to implement ToCompare } @@ -52,7 +49,7 @@ public void testSetUnusedCardDeck() { Deck d1 = new Deck(); ArrayList a1 = new ArrayList<>(); d1.setUnusedCardDeck(a1); - assertEquals(a1, d1.getUnusedCardDeck()); + assertTrue(d1.getUnusedCardDeck().isEmpty()); } @Test @@ -67,6 +64,7 @@ public void testDrawCardFromUnusedDeck() { } Card c1 = d1.drawCardFromUnusedDeck(); assertFalse(d1.getUnusedCardDeck().contains(c1)); + //Need further changing. } @Test diff --git a/src/test/java/Entity/FunctionCardTest.java b/src/test/java/Entity/FunctionCardTest.java index af94943..6f6d87e 100644 --- a/src/test/java/Entity/FunctionCardTest.java +++ b/src/test/java/Entity/FunctionCardTest.java @@ -7,21 +7,24 @@ import static org.junit.jupiter.api.Assertions.*; public class FunctionCardTest { - Player p1 = new Player("player1", 1); - FunctionCard c1 = new FunctionCard("yellow", "switch", "id"); + private static FunctionCard c1 = new FunctionCard("yellow", "switch", "id"); + private static FunctionCard c2 = new FunctionCard(); @Test - public void TestGetColor() { + public void testGetColor() { assertEquals("yellow", c1.getColor()); + assertEquals("black", c2.getColor()); } @Test - public void TestgetFunction() { + public void testGetFunction() { assertEquals("switch", c1.getFunction()); + assertEquals("null", c2.getFunction()); } @Test - public void TesttoString() { + public void testToString() { assertEquals("yellow switch", c1.toString()); + assertEquals("black null", c2.toString()); } } diff --git a/src/test/java/Entity/NumberCardTest.java b/src/test/java/Entity/NumberCardTest.java index 8b0f481..a0b760e 100644 --- a/src/test/java/Entity/NumberCardTest.java +++ b/src/test/java/Entity/NumberCardTest.java @@ -6,24 +6,23 @@ import org.junit.jupiter.api.Test; public class NumberCardTest { - NumberCard c1 = new NumberCard("red", 7, "red7"); - NumberCard c2 = new NumberCard(); -// Card c1; -// Card c2; + private static NumberCard c1 = new NumberCard("red", 7, "red7"); + private static NumberCard c2 = new NumberCard(); @Test - public void TestGetColor() { + public void testGetColor() { assertEquals("red", c1.getColor()); assertEquals("black", c2.getColor()); } @Test - public void TestGetNumber(){ + public void testGetNumber(){ assertEquals(7, c1.getNumber()); assertEquals(-1, c2.getNumber()); } - public void TesttoString(){ + @Test + public void testToString(){ assertEquals("red7", c1.toString()); assertEquals("black-1", c2.toString()); } diff --git a/src/test/java/Entity/PlayerTest.java b/src/test/java/Entity/PlayerTest.java index 7ff77f6..9795a48 100644 --- a/src/test/java/Entity/PlayerTest.java +++ b/src/test/java/Entity/PlayerTest.java @@ -9,8 +9,11 @@ public class PlayerTest { + Player p1 = new Player("player1", 1); + Card c1 = new NumberCard("yellow", 6, "1"); + @Test - public void TestdrawCard() { + public void testDrawCard() { Player p1 = new Player("player1", 1); Card c1 = new NumberCard("yellow", 6, "1"); p1.drawCard(c1); @@ -18,63 +21,46 @@ public void TestdrawCard() { } @Test - public void TestplayCard() { + public void testPlayCard() { Player p1 = new Player("player1", 1); Card c1 = new NumberCard("yellow", 6, "1"); p1.drawCard(c1); assertEquals(c1, p1.playCard(c1)); + //assertEquals(new Card().getColor(), p1.playCard(c1).getColor()); + // Need to mute return message } @Test - public void TestgetCardNum() { + public void testGetCardNum() { Player p1 = new Player("player1", 1); Card c1 = new NumberCard("yellow", 6, "1"); assertEquals(0, p1.getCardNum()); p1.drawCard(c1); assertEquals(1, p1.getCardNum()); - p1.playCard(c1); - assertEquals(0, p1.getCardNum()); } @Test - public void TestgetHandCard() { + public void testGetHandCard() { Player p1 = new Player("player1", 1); assertEquals(0, p1.getHandCard().size()); assertTrue(p1.getHandCard().isEmpty()); } @Test - public void TestgetID() { + public void testGetID() { Player p1 = new Player("player1", 1); assertEquals("player1", p1.getId()); } @Test - public void TestgetPosition() { + public void testGetPosition() { Player p1 = new Player("player1", 1); assertEquals(1, p1.getPosition()); } @Test - public void TestIterator(){ - Player p1 = new Player("player1", 1); - ArrayList expected = new ArrayList<>(); - - Card c1 = new NumberCard("yellow", 6, "1"); p1.drawCard(c1); expected.add(c1); - Card c2 = new FunctionCard("black", "plustwo", "2"); p1.drawCard(c2); expected.add(c2); - Card c3 = new FunctionCard("red", "reverse", "3"); p1.drawCard(c3); expected.add(c3); + public void testTBD(){ - int counter = 0; - for (Card c: p1) { - assertSame(c, expected.get(counter)); - counter++; - } - } - - @Test - public void testToString(){ - Player p1 = new Player("player1", 1); - assertEquals("Player{id=player1}", p1.toString()); } }