diff --git a/.classpath b/.classpath
index f2e6b00..303d7b8 100644
--- a/.classpath
+++ b/.classpath
@@ -5,6 +5,7 @@
+
diff --git a/domain/GameController.java b/domain/GameController.java
index 029a373..889e63b 100644
--- a/domain/GameController.java
+++ b/domain/GameController.java
@@ -36,6 +36,9 @@ public static GameController getInstance() {
}
return instance;
}
+ public static void clearInstance() {
+ instance = null;
+ }
//This func initializes the game by calling creating a new instance of initliazegamehelper
@@ -48,10 +51,12 @@ public void initializeGame() {
initalizeGameHelper=new InitializeGameHelper();
}
else {
- System.out.println("Not able to initialize");
+ System.out.println("Not able to initialize, have " + activePlayers.size() + "players, need 2");
}
}
+
+
//This func changes rounds
public void changeRounds() {
diff --git a/domain/player/Player.java b/domain/player/Player.java
index 7c7a9dd..c5fbcb1 100644
--- a/domain/player/Player.java
+++ b/domain/player/Player.java
@@ -71,4 +71,10 @@ public boolean equals(Player p2) {
else return false;
}
+ @Override
+ public String toString() {
+
+ String str = playerName + playerToken;
+ return str;
+ }
}
diff --git a/domain/player/PlayerInventory.java b/domain/player/PlayerInventory.java
index d9dfb09..c8fb4aa 100644
--- a/domain/player/PlayerInventory.java
+++ b/domain/player/PlayerInventory.java
@@ -17,7 +17,7 @@ public class PlayerInventory {
final ArrayList playerPublicationCardList;
public PlayerInventory() {
-
+
playerRecipeList = new ArrayList();
playerPotionList = new ArrayList();
playerHypothesesList = new ArrayList();
@@ -25,7 +25,7 @@ public PlayerInventory() {
playerArtifactCardList = new ArrayList();
playerPublicationCardList = new ArrayList();
}
-
+
public ArrayList getPlayerRecipeList() {
return playerRecipeList;
}
@@ -58,49 +58,56 @@ public ArrayList getPlayerPublicationCardList() {
public void addPotion(Potion potion) {
this.playerPotionList.add(potion);
}
-
+
public void addRecipe(Recipe recipe) {
this.playerRecipeList.add(recipe);
}
-
+
public void addHypoteses(Hypotheses hyp) {
this.playerHypothesesList.add(hyp);
}
-
+
public void addAIngredientCard(IngredientCard ing) {
this.playerIngredientCardList.add(ing);
}
-
+
public void addArtifactCard(ArtifactCard art) {
this.playerArtifactCardList.add(art);
}
-
+
public void addPublicationCard(PublicationCard pub) {
this.playerPublicationCardList.add(pub);
}
-
+
public void removePotion(Potion potion) {
this.playerPotionList.remove(potion);
}
-
+
public void removeRecipe(Recipe recipe) {
this.playerRecipeList.remove(recipe);
}
-
+
public void removeHypoteses(Hypotheses hyp) {
this.playerHypothesesList.remove(hyp);
}
-
+
public void removeIngredientCard(IngredientCard ing) {
this.playerIngredientCardList.remove(ing);
}
-
+
public void removeArtifactCard(ArtifactCard art) {
this.playerArtifactCardList.remove(art);
}
-
+
public void removePublicationCard(PublicationCard pub) {
this.playerPublicationCardList.remove(pub);
}
-
+
+ @Override
+ public String toString() {
+
+ String str = "\nIngredient Cards: " + playerIngredientCardList + "\nArtifact Cards: " + playerArtifactCardList + "\nPotion List: " + playerPotionList + "\nRecipes: " + playerRecipeList ;
+ return str;
+ }
+
}
diff --git a/domain/player/PlayerToken.java b/domain/player/PlayerToken.java
index 574e427..c2ce5bf 100644
--- a/domain/player/PlayerToken.java
+++ b/domain/player/PlayerToken.java
@@ -18,39 +18,39 @@ public class PlayerToken {
int playerAction=3;
String playerAvatar; // the directory of the playeravatar is kept in this as a string.
PlayerInventory playerInventory;
-
-
+
+
public PlayerToken() {
-
+
this.playerInventory= new PlayerInventory();
}
-
-
+
+
public void addGold(int gold) {
this.gold=this.gold+gold;
-
+
}
public void subtractGold(int gold) {
this.gold=this.gold-gold;
-
+
}
public void addReputationPoint(int point) {
this.reputation=this.reputation+point;
-
+
}
public void subtractReputationPoint(int point) {
this.reputation=this.reputation-point;
-
+
}
-
+
public void addHealth() {
if(this.playerHealth<3) {
this.playerHealth++;
}
}
-
+
public void reduceHealth() {
if(this.playerHealth>0) {
this.playerHealth--;
@@ -60,56 +60,56 @@ public void reduceHealth() {
this.gold=0;
}
}
-
-
-
-
-
+
+
+
+
+
public void addPotion(Potion potion) {
playerInventory.playerPotionList.add(potion);
}
-
+
public void addRecipe(Recipe recipe) {
playerInventory.playerRecipeList.add(recipe);
}
-
+
public void addHypoteses(Hypotheses hyp) {
playerInventory.playerHypothesesList.add(hyp);
}
-
+
public void addAIngredientCard(IngredientCard ing) {
playerInventory.playerIngredientCardList.add(ing);
}
-
+
public void addArtifactCard(ArtifactCard art) {
playerInventory.playerArtifactCardList.add(art);
}
-
+
public void addPublicationCard(PublicationCard pub) {
playerInventory.playerPublicationCardList.add(pub);
}
-
+
public void removePotion(Potion potion) {
playerInventory.playerPotionList.remove(potion);
}
-
+
public void removeRecipe(Recipe recipe) {
playerInventory.playerRecipeList.remove(recipe);
}
-
+
public void removeHypoteses(Hypotheses hyp) {
playerInventory.playerHypothesesList.remove(hyp);
}
-
+
public void removeIngredientCard(IngredientCard ing) {
playerInventory.playerIngredientCardList.remove(ing);
}
-
+
public void removeArtifactCard(ArtifactCard art) {
playerInventory.playerArtifactCardList.remove(art);
}
-
+
public void removePublicationCard(PublicationCard pub) {
playerInventory.playerPublicationCardList.remove(pub);
}
@@ -173,26 +173,26 @@ public void setPlayerAvatar(String playerAvatar) {
*/
public void reducePlayerAction() throws RuntimeException{
if(this.playerAction<=0) {
-
-
+
+
throw new RuntimeException("Tried to reduce user actions when the user had no actions left");
-
+
}
this.playerAction -= 1;
-
+
//GameController.changeCurrentPlayer();
if(this.playerAction ==0) {
GameController.getInstance().changeCurrentPlayer();
}
-
-
+
+
if(GameController.getInstance().shouldChangeRound()) {
GameController.getInstance().changeRounds();
}
-
-
+
+
}
-
+
public PlayerInventory getPlayerInventory() {
return playerInventory;
}
@@ -201,8 +201,16 @@ public PlayerInventory getPlayerInventory() {
public void setPlayerInventory(PlayerInventory playerInventory) {
this.playerInventory = playerInventory;
}
-
-
-
-
+
+ @Override
+ public String toString() {
+
+ String str = "\nGold: " + gold + " Reputation: " + reputation + " Health: " + playerHealth + " Left Actions: " + playerAction;
+ str += playerInventory;
+ return str;
+ }
+
+
+
+
}
diff --git a/domain/potion/Molecule.java b/domain/potion/Molecule.java
index 65f6755..b07f593 100644
--- a/domain/potion/Molecule.java
+++ b/domain/potion/Molecule.java
@@ -3,14 +3,14 @@
import java.util.Objects;
public class Molecule {
-
+
int moleculeId;
Atom redAtom;
Atom greenAtom;
Atom blueAtom;
public Molecule(int moleculeId, Atom redAtom, Atom greenAtom, Atom blueAtom) {
-
+
this.moleculeId = moleculeId;
this.redAtom = redAtom;
this.greenAtom = greenAtom;
@@ -38,27 +38,27 @@ public boolean equals(Object obj) {
}
public void setAtom(Atom atom) {
-
+
if(atom.getAtomColor()==0) {
this.redAtom=atom;
}else if(atom.getAtomColor()==1) {
-
+
this.greenAtom=atom;
}else if(atom.getAtomColor()==2) {
-
+
this.blueAtom=atom;
}
}
-
+
public Atom getAtomByColor(int atomColorId) {
if(redAtom.getAtomColor() == atomColorId) {
return redAtom;
}
-
+
else if(greenAtom.getAtomColor() == atomColorId) {
return greenAtom;
}
-
+
else if(blueAtom.getAtomColor() == atomColorId) {
return blueAtom;
}
@@ -113,6 +113,27 @@ public Atom getBlueAtom() {
public void setBlueAtom(Atom blueAtom) {
this.blueAtom = blueAtom;
}
-
-
+
+ @Override
+ public String toString() {
+
+ Atom redAtom = this.getRedAtom();
+ String redAtomSize = (redAtom.getAtomSize() == 1? "Big" : "Small");
+ String redAtomSign = (redAtom.getAtomSign() == 0? "Negative" : "Positive");
+
+ Atom blueAtom = this.getBlueAtom();
+ String blueAtomSize = (blueAtom.getAtomSize() == 1? "Big" : "Small");
+ String blueAtomSign = (blueAtom.getAtomSign() == 0? "Negative" : "Positive");
+
+ Atom greenAtom = this.getGreenAtom();
+ String greenAtomSize = (greenAtom.getAtomSize() == 1? "Big" : "Small");
+ String greenAtomSign = (greenAtom.getAtomSign() == 0? "Negative" : "Positive");
+
+ String str = "Red: " + redAtomSize + " " + redAtomSign;
+ str += "\nBlue: " + blueAtomSize + " " + blueAtomSign;
+ str += "\nGreen: " + greenAtomSize + " " + greenAtomSign;
+
+ return str;
+ }
+
}
diff --git a/test/TestForageForIngredient.java b/test/TestForageForIngredient.java
new file mode 100644
index 0000000..3e81de4
--- /dev/null
+++ b/test/TestForageForIngredient.java
@@ -0,0 +1,93 @@
+package test;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import domain.GameController;
+import domain.boards.BoardController;
+import domain.boards.IngredientBoard;
+import domain.player.*;
+import exception.UserErrorException;
+
+public class TestForageForIngredient {
+
+ public TestForageForIngredient() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @BeforeEach
+ public void beforeEach() {
+ TestGameInitializer.initializeTestGame();
+ }
+
+ @Test
+ public void noActionsLeft() {
+ Player currentPlayer = GameController.getInstance().getCurrentPlayer();
+ currentPlayer.getPlayerToken().setPlayerAction(0);
+ Exception exception = assertThrows(UserErrorException.class, () -> BoardController.forageForIngredient());
+ assertEquals(exception.getMessage(), "The user has no more actions left!");
+ }
+
+ @Test
+ public void singleSuccess() {
+ Player currentPlayer = GameController.getInstance().getCurrentPlayer();
+ currentPlayer.getPlayerToken().setPlayerAction(3);
+ int initialSize = currentPlayer.getInventory().getPlayerIngredientCardList().size();
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ assertEquals(initialSize+1, currentPlayer.getInventory().getPlayerIngredientCardList().size());
+ }
+
+ @Test
+ public void multipleSuccess() {
+ Player currentPlayer = GameController.getInstance().getCurrentPlayer();
+ currentPlayer.getPlayerToken().setPlayerAction(3);
+ int initialSize = currentPlayer.getInventory().getPlayerIngredientCardList().size();
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ assertEquals(initialSize+3, currentPlayer.getInventory().getPlayerIngredientCardList().size());
+ }
+
+ @Test
+ public void singleSuccessNoActionsLeft() {
+ Player firstPlayer = GameController.getInstance().getCurrentPlayer();
+ firstPlayer.getPlayerToken().setPlayerAction(1);
+ int firstPlayerSize = firstPlayer.getInventory().getPlayerIngredientCardList().size();
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ //since we had no more actions left, other user must have been switched to
+ Player secondPlayer = GameController.getInstance().getCurrentPlayer();
+ int secondPlayerSize = secondPlayer.getInventory().getPlayerIngredientCardList().size();
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ assertNotEquals(GameController.getInstance().getCurrentPlayer(), firstPlayer);
+ assertEquals(GameController.getInstance().getCurrentPlayer(), secondPlayer);
+ assertNotEquals(secondPlayer, firstPlayer);
+
+ assertEquals(firstPlayerSize+1, firstPlayer.getInventory().getPlayerIngredientCardList().size());
+ assertEquals(secondPlayerSize+1, secondPlayer.getInventory().getPlayerIngredientCardList().size());
+ }
+
+ @Test
+ public void allSuccessNoActionsLeft() {
+ Player firstPlayer = GameController.getInstance().getCurrentPlayer();
+ assertEquals(3, firstPlayer.getPlayerToken().getPlayerAction());
+ int firstPlayerSize = firstPlayer.getInventory().getPlayerIngredientCardList().size();
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());//exhaust actions
+
+ //since we had no more actions left, other user must have been switched to
+ Player secondPlayer = GameController.getInstance().getCurrentPlayer();
+ int secondPlayerSize = secondPlayer.getInventory().getPlayerIngredientCardList().size();
+ assertDoesNotThrow(() -> BoardController.forageForIngredient());
+ assertNotEquals(GameController.getInstance().getCurrentPlayer(), firstPlayer);
+ assertEquals(GameController.getInstance().getCurrentPlayer(), secondPlayer);
+ assertNotEquals(secondPlayer, firstPlayer);
+
+ assertEquals(firstPlayerSize+3, firstPlayer.getInventory().getPlayerIngredientCardList().size());
+ assertEquals(secondPlayerSize+1, secondPlayer.getInventory().getPlayerIngredientCardList().size());
+ }
+}
\ No newline at end of file
diff --git a/test/TestGameInitializer.java b/test/TestGameInitializer.java
index cfd8396..b2ba4d5 100644
--- a/test/TestGameInitializer.java
+++ b/test/TestGameInitializer.java
@@ -10,6 +10,7 @@ public TestGameInitializer() {
}
public static void initializeTestGame() {
+ GameController.clearInstance();
LoginSignupController.getInstance().signup("user_1", "user_1");
LoginSignupController.getInstance().signup("user_2", "user_2");
diff --git a/test/TestMakeExperiment.java b/test/TestMakeExperiment.java
new file mode 100644
index 0000000..4e5baec
--- /dev/null
+++ b/test/TestMakeExperiment.java
@@ -0,0 +1,73 @@
+package test;
+
+import java.util.ArrayList;
+
+import domain.GameController;
+import domain.GameInventory;
+import domain.cards.IngredientCard;
+import domain.potion.Atom;
+import domain.potion.Molecule;
+import exception.UserErrorException;
+import userinterface.LoginSignupController;
+
+public class TestMakeExperiment {
+
+ GameController controller;
+ GameInventory inventory;
+ ArrayList ingredientCards;
+
+ public static void main(String[] args) {
+ //testExperiment();
+ //System.out.print(controller.getCurrentPlayer());
+ }
+
+ public void testExperiment() {
+
+ //Initialize game first
+ controller = GameController.getInstance();
+
+ LoginSignupController.getInstance().signup("TestUser1", "testuser");
+ LoginSignupController.getInstance().login("TestUser1", "testuser");
+
+ LoginSignupController.getInstance().signup("TestUser2", "testuser");
+ LoginSignupController.getInstance().login("TestUser2", "testuser");
+
+ controller.initializeGame();
+
+ //Then we can get inventory (after the game is initialized)
+ inventory = controller.getGameInventory();
+
+ //makeExperiment(IngredientCard ingredient1, IngredientCard ingredient2, Boolean testOnStu)
+ //throws UserErrorException, RuntimeException
+
+ //For testing purposes, added 100 actions to the current player
+ controller.getCurrentPlayer().getPlayerToken().setPlayerAction(100);
+
+ /*
+ * Things to test:
+ **** For all tests
+ **
+ **** Drink Potion Tests
+ ** Health Potion (Red +) -> playerHealth should increase by 1.
+ ** Speed Potion (Green +) -> playerAction should increase by 1.
+ ** Wisdom Potion (Blue +) -> playerReputation should increase by 1.
+ * (Since player's gonna use 1 action to test the potion, the action amount before and after...
+ * ...makeExperiment should remain the same.)
+ *
+ ** Poison Potion (Red -) -> playerHealth should reduce by 1.
+ ** Slow Potion (Green -) -> playerHealth should reduce by 1. playerAction should reduce by 1 (if any left).
+ ** Insanity Potion (Blue -) -> playerHealth should reduce by 1. playerReputation should reduce by 1.
+ *
+ ** Neutral Potion -> No effect.
+ */
+
+ //TODO In Potion class's testPotion() method, line 61
+ //if (!GameController.getInstance().getCurrentPlayer().getInventory().getPlayerArtifactCardList().contains(GameController.getInstance().getGameInventory().getArtCards().get(1)))
+ //is a very fragile code. It should check all items in ArrayList and check if (item instanceof Vaccine)
+ //when the order of the cards change, the function won't function
+ //TODO playerHealth is in both Player and PlayerToken classes. Choose one (I think Player class is a better answer)
+
+
+
+ }
+}
diff --git a/test/TestTransmuteIngredient.java b/test/TestTransmuteIngredient.java
new file mode 100644
index 0000000..4bbdad5
--- /dev/null
+++ b/test/TestTransmuteIngredient.java
@@ -0,0 +1,57 @@
+package test;
+
+/*import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;*/
+
+import domain.GameController;
+import domain.boards.BoardController;
+import domain.cards.IngredientCard;
+import domain.player.Player;
+import exception.UserErrorException;
+
+
+public class transmuteIngredientTest {
+ /*Test Cases:
+ Black-Box Test: Transmuting Ingredient Card owned by current player
+ Scenario: Providing an ingredient card owned by the player to transmute.
+ Expected result: The method successfully transmutes the ingredient card to 1 gold and reduces the player's action count.
+
+ Black-Box Test: Transmuting Non-Owned Ingredient Card
+ Scenario: Providing an ingredient card not owned by the player to transmute.
+ Expected result: The method throws a UserErrorException since the ingredient card is not owned by the player.
+
+ Glass-Box Test: Inventory Modification
+ Scenario: Checking the inventory modification.
+ Expected result: ingredient card is removed from the player's inventory after transmutation.
+
+ Glass-Box Test: Gold Addition
+ Scenario: checking the gold addition.
+ Expected result: The player's gold increased by 1 after transmutation.
+
+ Glass-Box Test: Player Action Reduction
+ Scenario: Checking the player action reduction.
+ Expected result: The player's action count decreases by 1 after transmutation.*/
+
+ //@Test
+ public void testTransmuteOwnedIngredient() throws UserErrorException {
+ // Test: Transmuting an owned ingredient card
+ GameController.getGameInventory().createAtom();
+ GameController.getGameInventory().createMolecule();
+ GameController.getGameInventory().createIngredientCard();
+
+ IngredientCard ownedCard=GameController.getGameInventory().getIngrCards().get(0);
+
+ Player currentPlayer = new Player(1, "aa", "bb");
+ currentPlayer.getInventory().addAIngredientCard(ownedCard);
+ currentPlayer.getPlayerToken().setPlayerAction(3);
+ currentPlayer.getPlayerToken().setGold(5);
+ BoardController.transmuteIngredient(ownedCard.getName());
+
+ // Assert
+ /*assertEquals(4, currentPlayer.getPlayerToken().getPlayerAction());
+ assertEquals(6, currentPlayer.getPlayerToken().getGold());
+ assertFalse(currentPlayer.getInventory().getPlayerIngredientCardList().contains(ownedCard));*/
+ }
+
+
+}
diff --git a/userinfo.json b/userinfo.json
index bf252d4..f435d8c 100644
--- a/userinfo.json
+++ b/userinfo.json
@@ -1 +1 @@
-[{"password":"a","username":"a"}]
\ No newline at end of file
+[{"password":"user_2","username":"user_2"},{"password":"user_1","username":"user_1"}]