Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulty changes map size #470

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions source/core/src/main/com/csse3200/game/areas/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Comment on lines -112 to -122
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was unused

/**
* Create the game area, including terrain, static entities (trees), and dynamic entities (player).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Room> rooms;
Expand Down Expand Up @@ -71,9 +70,9 @@ private List<String> 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);
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey this implementation is not good it violates the way configs work and methods should be ion main game screen please do not change anything in config, contact me for more questions. I will have to close this .

Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
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<String> roomsCompleted;
public List<String> roomsCompleted = new ArrayList<>();
public List<String> 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 = 40;

/**
* 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) {
// 30 on easy, 40 on medium, 50 on hard
mapSize = (int) (SIZE_ON_MEDIUM * (1.75 - difficulty.getMultiplier()));
if (mapSize <= 0) {
throw new IllegalStateException(
"Difficulty is too easy and caused a negative-sized map");
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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");
}}
}

@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");
}
}
Loading