<%= gameState.getCurrentText() %>
+ + + + \ No newline at end of file diff --git a/Yaroslav/src/main/webapp/index.jsp b/Yaroslav/src/main/webapp/index.jsp new file mode 100644 index 0000000..dfe5d39 --- /dev/null +++ b/Yaroslav/src/main/webapp/index.jsp @@ -0,0 +1,15 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + +Player Name: <%= player.getName() %>
+Games Played: <%= player.getGamesPlayed() %>
+Games Won: <%= player.getGamesWon() %>
+ + + + \ No newline at end of file diff --git a/Yaroslav/src/test/java/com/game/model/GameStateTest.java b/Yaroslav/src/test/java/com/game/model/GameStateTest.java new file mode 100644 index 0000000..5d97349 --- /dev/null +++ b/Yaroslav/src/test/java/com/game/model/GameStateTest.java @@ -0,0 +1,57 @@ +package com.game.model; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class GameStateTest { + private GameState gameState; + + @BeforeEach + void setUp() { + gameState = new GameState(); + } + + @Test + void testInitialState() { + assertEquals("You stand at a fork in the road. Where do you go? (left/right)", gameState.getCurrentText()); + assertFalse(gameState.isGameOver(), "Game should not be over at the start"); + } + + @Test + void testProcessChoice_ValidPath_Left() { + gameState.processChoice("left"); + assertEquals("You found a chest. Open it? (yes/no)", gameState.getCurrentText()); + assertFalse(gameState.isGameOver()); + } + + @Test + void testProcessChoice_ValidPath_Right() { + gameState.processChoice("right"); + assertEquals("You met a wolf. Run away? (yes/no)", gameState.getCurrentText()); + assertFalse(gameState.isGameOver()); + } + + @Test + void testProcessChoice_Ending_Open() { + gameState.processChoice("left"); + gameState.processChoice("yes"); // Opens the chest + assertEquals("You found a treasure! (end)", gameState.getCurrentText()); + assertTrue(gameState.isGameOver(), "Game should be over after finding the treasure"); + } + + @Test + void testProcessChoice_Ending_Run() { + gameState.processChoice("right"); + gameState.processChoice("yes"); // Runs away from wolf + assertEquals("You escaped safely. (end)", gameState.getCurrentText()); + assertTrue(gameState.isGameOver(), "Game should be over after escaping"); + } + + @Test + void testProcessChoice_InvalidInput() { + gameState.processChoice("unknown"); + assertEquals("You stand at a fork in the road. Where do you go? (left/right)", gameState.getCurrentText()); + assertFalse(gameState.isGameOver(), "Game should not be over after an invalid input"); + } +} \ No newline at end of file diff --git a/Yaroslav/src/test/java/com/game/model/StoryTest.java b/Yaroslav/src/test/java/com/game/model/StoryTest.java new file mode 100644 index 0000000..4513f66 --- /dev/null +++ b/Yaroslav/src/test/java/com/game/model/StoryTest.java @@ -0,0 +1,57 @@ +package com.game.model; + + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Map; + +class StoryTest { + private Story story; + + @BeforeEach + void setUp() { + story = new Story(); + } + + @Test + void testGetScene_ValidScene() { + Story.Scene scene = story.getScene("start"); + assertNotNull(scene, "Scene should not be null"); + assertEquals("You stand at a fork in the road. Where do you go? (left/right)", scene.getText()); + assertEquals(Map.of("left", "left_path", "right", "right_path"), scene.getChoices()); + } + + @Test + void testGetScene_InvalidScene() { + Story.Scene scene = story.getScene("invalid_key"); + assertNotNull(scene, "Scene should not be null"); + assertEquals("Error: Unknown scene", scene.getText()); + assertTrue(scene.getChoices().isEmpty(), "Unknown scene should have no choices"); + } + + @Test + void testIsEndScene_True() { + assertTrue(story.isEndScene("open"), "Scene 'open' should be an end scene"); + assertTrue(story.isEndScene("ignore"), "Scene 'ignore' should be an end scene"); + assertTrue(story.isEndScene("run"), "Scene 'run' should be an end scene"); + assertTrue(story.isEndScene("fight"), "Scene 'fight' should be an end scene"); + } + + @Test + void testIsEndScene_False() { + assertFalse(story.isEndScene("start"), "Scene 'start' should not be an end scene"); + assertFalse(story.isEndScene("left_path"), "Scene 'left_path' should not be an end scene"); + assertFalse(story.isEndScene("right_path"), "Scene 'right_path' should not be an end scene"); + } + + @Test + void testSceneChoices() { + Story.Scene scene = story.getScene("left_path"); + assertEquals(Map.of("yes", "open", "no", "ignore"), scene.getChoices()); + + scene = story.getScene("right_path"); + assertEquals(Map.of("yes", "run", "no", "fight"), scene.getChoices()); + } +} \ No newline at end of file