diff --git a/source/core/src/main/com/csse3200/game/areas/GameController.java b/source/core/src/main/com/csse3200/game/areas/GameController.java index db446adb..4cac4493 100644 --- a/source/core/src/main/com/csse3200/game/areas/GameController.java +++ b/source/core/src/main/com/csse3200/game/areas/GameController.java @@ -109,17 +109,6 @@ public GameController(GameArea gameArea, LevelFactory levelFactory, Entity playe this(gameArea, levelFactory, player, false, new MapLoadConfig()); } - /** - * Initialise this Game Area to use the provided levelFactory without loading a saved state. - * - * @param levelFactory the provided levelFactory. - * @param shouldLoad if the game should be loaded. - * @param player the main player entity. - */ - public GameController(GameArea gameArea, LevelFactory levelFactory, Entity player, Boolean shouldLoad) { - this(gameArea, levelFactory, player, false, new MapLoadConfig()); - } - /** * Create the game area, including terrain, static entities (trees), and dynamic entities (player). */ diff --git a/source/core/src/main/com/csse3200/game/areas/MainGameLevelFactory.java b/source/core/src/main/com/csse3200/game/areas/MainGameLevelFactory.java index 39c7f071..f907686e 100644 --- a/source/core/src/main/com/csse3200/game/areas/MainGameLevelFactory.java +++ b/source/core/src/main/com/csse3200/game/areas/MainGameLevelFactory.java @@ -16,7 +16,6 @@ * This is the main game mode. */ public class MainGameLevelFactory implements LevelFactory { - private static final int DEFAULT_MAP_SIZE = 40; private static final Logger log = LoggerFactory.getLogger(MainGameLevelFactory.class); private int levelNum; private final Map rooms; @@ -71,9 +70,9 @@ private List createShopItemsList() { public Level create(int levelNumber) { String seed = "seed"; // default seed for junit tests + log.debug("Creating level of size {}", config.mapSize); if (!shouldLoad) { - map = new LevelMap(seed + levelNumber, DEFAULT_MAP_SIZE); - + map = new LevelMap(seed + levelNumber, config.mapSize); } else { // For loaded games, append the level number to the loaded seed map = new LevelMap(config.seed + config.currentLevel, config.mapSize); diff --git a/source/core/src/main/com/csse3200/game/entities/configs/MapLoadConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/MapLoadConfig.java index 34fb132a..895b8469 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/MapLoadConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/MapLoadConfig.java @@ -1,13 +1,34 @@ package com.csse3200.game.entities.configs; +import com.csse3200.game.options.GameOptions.Difficulty; + import java.util.ArrayList; import java.util.List; public class MapLoadConfig { - public List roomsCompleted; + public List roomsCompleted = new ArrayList<>(); public List shopRoomItems = new ArrayList<>(); - public String currentLevel; + public String currentLevel = "0"; public String currentRoom; - public String seed; - public int mapSize; + public String seed = "seed"; + public int mapSize = SIZE_ON_MEDIUM; + + private static final int SIZE_ON_MEDIUM = 20; + private static final int SIZE_FACTOR = 40; + private static final double MUL_FACTOR = 1.25; + + /** + * Set map size based on difficulty. Harder difficulty corresponds to larger map size. + * @param difficulty difficulty chosen by player. + * @return this instance + */ + public MapLoadConfig setSizeFromDifficulty(Difficulty difficulty) { + // 10 on easy, 20 on medium, 30 on hard + mapSize = (int) (SIZE_FACTOR * (MUL_FACTOR - difficulty.getMultiplier())); + if (mapSize <= 0) { + throw new IllegalStateException( + "Difficulty is too easy and caused an invalid map size"); + } + return this; + } } diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index 6728de1c..ccb45d72 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -46,6 +46,7 @@ public MainGameScreen(GdxGame game) { logger.debug("Initialising main game screen entities"); MapLoadConfig mapConfig = new MapLoadConfig(); + mapConfig.setSizeFromDifficulty(gameOptions.difficulty); mapConfig.currentLevel = "0"; LevelFactory levelFactory = new MainGameLevelFactory(false, mapConfig); if (gameOptions.difficulty == TEST) { diff --git a/source/core/src/test/com/csse3200/game/areas/Levels/MainGameLevelFactoryTest.java b/source/core/src/test/com/csse3200/game/areas/Levels/MainGameLevelFactoryTest.java index 04f8c87c..7dba27d2 100644 --- a/source/core/src/test/com/csse3200/game/areas/Levels/MainGameLevelFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/areas/Levels/MainGameLevelFactoryTest.java @@ -1,30 +1,31 @@ package com.csse3200.game.areas.Levels; -import com.badlogic.gdx.graphics.OrthographicCamera; import com.csse3200.game.areas.Level; import com.csse3200.game.areas.LevelFactory; import com.csse3200.game.areas.MainGameLevelFactory; import com.csse3200.game.components.CameraComponent; -import com.csse3200.game.files.FileLoader; +import com.csse3200.game.entities.configs.MapLoadConfig; +import com.csse3200.game.extensions.GameExtension; +import com.csse3200.game.options.GameOptions.Difficulty; import com.csse3200.game.rendering.RenderService; import com.csse3200.game.services.ResourceService; import com.csse3200.game.services.ServiceLocator; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -import java.util.*; +import static org.mockito.Mockito.when; +@ExtendWith(GameExtension.class) class MainGameLevelFactoryTest { private LevelFactory levelFactory; @@ -47,7 +48,7 @@ void setUp() { // Set up ResourceService (or mock it if necessary) ServiceLocator.registerResourceService(new ResourceService()); - levelFactory = new MainGameLevelFactory(false, null); + levelFactory = new MainGameLevelFactory(false, new MapLoadConfig()); } @AfterEach @@ -114,4 +115,21 @@ void testCreateMultipleLevels() { assertTrue(level1Rooms.size() > 1, "Level 1 should have multiple rooms"); assertTrue(level2Rooms.size() > 1, "Level 2 should have multiple rooms"); assertTrue(level3Rooms.size() > 1, "Level 3 should have multiple rooms"); -}} \ No newline at end of file +} + + @Test + void harderDifficultyGivesBiggerLevel() { + LevelFactory easyFactory = new MainGameLevelFactory( + false, new MapLoadConfig().setSizeFromDifficulty(Difficulty.EASY)); + LevelFactory mediumFactory = new MainGameLevelFactory( + false, new MapLoadConfig().setSizeFromDifficulty(Difficulty.MEDIUM)); + LevelFactory hardFactory = new MainGameLevelFactory( + false, new MapLoadConfig().setSizeFromDifficulty(Difficulty.HARD)); + assertTrue(easyFactory.create(0).getMap().getMapSize() + < mediumFactory.create(0).getMap().getMapSize(), + "Easy level should be smaller than medium"); + assertTrue(mediumFactory.create(0).getMap().getMapSize() + < hardFactory.create(0).getMap().getMapSize(), + "Medium level should be smaller than hard"); + } +} \ No newline at end of file