From b7f47a48e77203b3d1e83b0900a99e48319ec706 Mon Sep 17 00:00:00 2001 From: BedirhanMaden Date: Wed, 27 Dec 2023 12:52:46 +0300 Subject: [PATCH 1/5] handled specification for transmuteIngredient method --- domain/boards/IngredientBoard.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/domain/boards/IngredientBoard.java b/domain/boards/IngredientBoard.java index b27991b..18f437b 100644 --- a/domain/boards/IngredientBoard.java +++ b/domain/boards/IngredientBoard.java @@ -47,6 +47,15 @@ public IngredientCard popIngredient() { //Sells 1 ingredient card for 1 gold public void transmuteIngredient(IngredientCard ingredientCard) throws UserErrorException, RuntimeException { + /* Method: transmuteIngredient + * Requires: Ingredient card must be provided. Current player should have ingredientCard. + * Modifies: Player's inventory. + * Player's token + * Effects: Throws UserErrorException if the player does not own ingredientCard + * Transmute 1 ingredientCard to a gold. + * Reduces player action by 1. + */ + Player player = GameController.getCurrentPlayer(); PlayerInventory inv = player.getInventory(); PlayerToken token = player.getPlayerToken(); From b649843a90011c69f92ba19b84cd25aff94b6074 Mon Sep 17 00:00:00 2001 From: BedirhanMaden Date: Wed, 27 Dec 2023 13:28:45 +0300 Subject: [PATCH 2/5] Initialized transmuteIngredientTest class --- test/transmuteIngredientTest.java | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/transmuteIngredientTest.java diff --git a/test/transmuteIngredientTest.java b/test/transmuteIngredientTest.java new file mode 100644 index 0000000..725ce17 --- /dev/null +++ b/test/transmuteIngredientTest.java @@ -0,0 +1,57 @@ +package test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.junit.jupiter.api.Test; + +import domain.GameController; +import domain.boards.BoardController; +import domain.cards.IngredientCard; +import exception.UserErrorException; +import domain.player.*; + +/*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.*/ +public class transmuteIngredientTest { + @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)); + } + + +} From 45dff4f646819fc44ca0e57c204b61609f8552b6 Mon Sep 17 00:00:00 2001 From: larakucukdevlet Date: Tue, 2 Jan 2024 18:01:55 +0300 Subject: [PATCH 3/5] deleted transmuteTest --- test/transmuteIngredientTest.java | 57 ------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 test/transmuteIngredientTest.java diff --git a/test/transmuteIngredientTest.java b/test/transmuteIngredientTest.java deleted file mode 100644 index 725ce17..0000000 --- a/test/transmuteIngredientTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import org.junit.jupiter.api.Test; - -import domain.GameController; -import domain.boards.BoardController; -import domain.cards.IngredientCard; -import exception.UserErrorException; -import domain.player.*; - -/*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.*/ -public class transmuteIngredientTest { - @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)); - } - - -} From a0b139baa61c0dcb2a5bf26e7044fac2fdbdfbe9 Mon Sep 17 00:00:00 2001 From: larakucukdevlet Date: Thu, 4 Jan 2024 12:13:04 +0300 Subject: [PATCH 4/5] Initialized server side --- domain/Server.java | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 domain/Server.java diff --git a/domain/Server.java b/domain/Server.java new file mode 100644 index 0000000..981aa7b --- /dev/null +++ b/domain/Server.java @@ -0,0 +1,66 @@ +package domain; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.ServerSocket; +import java.net.Socket; + +public class Server extends Thread { + private ServerSocket serverSocket; + private int availablePort; + + public Server(int port) throws IOException { + serverSocket = new ServerSocket(port); + availablePort = port; + //serverSocket.setSoTimeout(10000); + } + + public int getAvailablePort() { + return availablePort; + } + + public static void main(String[] args) throws IOException { + Server server = new Server(findAvailablePort()); + System.out.println("Available port: " + server.getAvailablePort()); + // Start the server thread + server.start(); + } + + public static int findAvailablePort() { + int port = 0; + try (ServerSocket socket = new ServerSocket(0)) { + port = socket.getLocalPort(); + } catch (IOException e) { + e.printStackTrace(); // Handle the exception according to your needs + } + return port; + } + /* public int play() { + int result; + }*/ + public void run() { + while (true) { + try { + System.out.println("Waiting for players on port " + serverSocket.getLocalPort() + "..."); + Socket player1 = serverSocket.accept(); + System.out.println("Player 1 connected."); + Socket player2 = serverSocket.accept(); + System.out.println("Player 2 connected."); + + + BufferedReader fromPlayer1 = new BufferedReader(new InputStreamReader(player1.getInputStream())); + PrintWriter toPlayer1 = new PrintWriter(player1.getOutputStream(), true); + BufferedReader fromPlayer2 = new BufferedReader(new InputStreamReader(player2.getInputStream())); + PrintWriter toPlayer2 = new PrintWriter(player2.getOutputStream(), true); + + toPlayer1.println("You are Player 1."); + toPlayer2.println("You are Player 2."); + // Logic for handling client connections goes here + } catch (IOException e) { + e.printStackTrace(); // Handle the exception according to your needs + } + } + } +} From 22ef9f85d4126b102c45eaa560c083ac1169ce41 Mon Sep 17 00:00:00 2001 From: larakucukdevlet <79307181+larakucukdevlet@users.noreply.github.com> Date: Thu, 4 Jan 2024 12:23:11 +0300 Subject: [PATCH 5/5] Deleted Server.java --- domain/Server.java | 65 ---------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/domain/Server.java b/domain/Server.java index 981aa7b..8b13789 100644 --- a/domain/Server.java +++ b/domain/Server.java @@ -1,66 +1 @@ -package domain; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.net.ServerSocket; -import java.net.Socket; - -public class Server extends Thread { - private ServerSocket serverSocket; - private int availablePort; - - public Server(int port) throws IOException { - serverSocket = new ServerSocket(port); - availablePort = port; - //serverSocket.setSoTimeout(10000); - } - - public int getAvailablePort() { - return availablePort; - } - - public static void main(String[] args) throws IOException { - Server server = new Server(findAvailablePort()); - System.out.println("Available port: " + server.getAvailablePort()); - // Start the server thread - server.start(); - } - - public static int findAvailablePort() { - int port = 0; - try (ServerSocket socket = new ServerSocket(0)) { - port = socket.getLocalPort(); - } catch (IOException e) { - e.printStackTrace(); // Handle the exception according to your needs - } - return port; - } - /* public int play() { - int result; - }*/ - public void run() { - while (true) { - try { - System.out.println("Waiting for players on port " + serverSocket.getLocalPort() + "..."); - Socket player1 = serverSocket.accept(); - System.out.println("Player 1 connected."); - Socket player2 = serverSocket.accept(); - System.out.println("Player 2 connected."); - - - BufferedReader fromPlayer1 = new BufferedReader(new InputStreamReader(player1.getInputStream())); - PrintWriter toPlayer1 = new PrintWriter(player1.getOutputStream(), true); - BufferedReader fromPlayer2 = new BufferedReader(new InputStreamReader(player2.getInputStream())); - PrintWriter toPlayer2 = new PrintWriter(player2.getOutputStream(), true); - - toPlayer1.println("You are Player 1."); - toPlayer2.println("You are Player 2."); - // Logic for handling client connections goes here - } catch (IOException e) { - e.printStackTrace(); // Handle the exception according to your needs - } - } - } -}