diff --git a/source/core/src/main/com/csse3200/game/GdxGame.java b/source/core/src/main/com/csse3200/game/GdxGame.java index 0ea9b530f..01966f2b7 100644 --- a/source/core/src/main/com/csse3200/game/GdxGame.java +++ b/source/core/src/main/com/csse3200/game/GdxGame.java @@ -64,41 +64,29 @@ public void dispose() { * @return new screen */ private Screen newScreen(ScreenType screenType) { - switch (screenType) { - case MAIN_MENU: - return new MainMenuScreen(this); - case MAIN_GAME: - return new MainGameScreen(this); - case SETTINGS: - return new SettingsScreen(this); - case STORY_SCREEN: - return new StoryScreen(this); - case LEVEL_SELECT: - return new LevelSelectScreen(this); - case LOSING_SCREEN: - return new LosingScreen(this); - case TURRET_SELECTION: - return new TurretSelectionScreen(this); - case HELP_SCREEN: - return new GameDescriptionHelpScreen(this); - case HELP_MOBS_SCREEN: - return new MobsDescriptionHelpScreen(this); - case HELP_TOWER_SCREEN: - return new TowerDescriptionHelpScreen(this); - case HELP_BOSS_SCREEN: - return new BossDescriptionHelpScreen(this); - case HOW_TO_PLAY: - return new HowToPlay(this); - case LOAD_SCREEN: - return new LoadingScreen(this); - default: - return null; - } + return switch (screenType) { + case Next_Screen -> new NextLevelScreen(this); + case Win_Screen -> new WinningScreen(this); + case MAIN_MENU -> new MainMenuScreen(this); + case MAIN_GAME -> new MainGameScreen(this); + case SETTINGS -> new SettingsScreen(this); + case STORY_SCREEN -> new StoryScreen(this); + case LEVEL_SELECT -> new LevelSelectScreen(this); + case LOSING_SCREEN -> new LosingScreen(this); + case TURRET_SELECTION -> new TurretSelectionScreen(this); + case HELP_SCREEN -> new GameDescriptionHelpScreen(this); + case HELP_MOBS_SCREEN -> new MobsDescriptionHelpScreen(this); + case HELP_TOWER_SCREEN -> new TowerDescriptionHelpScreen(this); + case HELP_BOSS_SCREEN -> new BossDescriptionHelpScreen(this); + case HOW_TO_PLAY -> new HowToPlay(this); + case LOAD_SCREEN -> new LoadingScreen(this); + default -> null; + }; } public enum ScreenType { MAIN_MENU, MAIN_GAME, SETTINGS, STORY_SCREEN, LEVEL_SELECT, TURRET_SELECTION, LOSING_SCREEN, HELP_SCREEN, LOAD_SCREEN, - HELP_MOBS_SCREEN, HELP_TOWER_SCREEN, HELP_BOSS_SCREEN, HOW_TO_PLAY + HELP_MOBS_SCREEN, HELP_TOWER_SCREEN, HELP_BOSS_SCREEN, Win_Screen, Next_Screen, HOW_TO_PLAY } /** diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGameActions.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGameActions.java index 970c44fd6..4af3ae552 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGameActions.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/MainGameActions.java @@ -21,7 +21,19 @@ public MainGameActions(GdxGame game) { public void create() { entity.getEvents().addListener("exit", this::onExit); entity.getEvents().addListener("lose", this::onLose); - //entity.getEvents().addListener("win", this::onWin); + entity.getEvents().addListener("win", this::WinningScreen); + entity.getEvents().addListener("Next Level", this::NextLevel); + } + + private void NextLevel() { + logger.info("Next level"); + game.setScreen(GdxGame.ScreenType.Next_Screen); + + } + + private void WinningScreen() { + logger.info("Uer Won the game"); + game.setScreen(GdxGame.ScreenType.Win_Screen); } /** 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 d7de9a289..a7c2d21e4 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -32,7 +32,6 @@ import com.csse3200.game.components.maingame.MainGameExitDisplay; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * The game screen containing the main game. * @@ -219,6 +218,7 @@ public void render(float delta) { ServiceLocator.getWaveService().getDisplay().updateMobCount(); renderer.render(); + // Check if the game has ended // Check if the game has ended if (ServiceLocator.getGameEndService().hasGameEnded()) { ui.getEvents().trigger("lose"); @@ -226,11 +226,18 @@ public void render(float delta) { // Check if all waves are completed and the level has been completed if (ServiceLocator.getWaveService().isLevelCompleted()) { - logger.info("Main game level completed detected, go to win screen"); - ui.getEvents().trigger("lose"); // needs to change to: ui.getEvents().trigger("win"); - // Add something in to unlock the next planet/level? + if (selectedLevel == 2) { // Lava level + // If it's the lava level, go to the "win" screen + ui.getEvents().trigger("win"); + logger.info("Main game level completed detected, go to win screen"); + } else { + // For other levels, go to the "NextLevelScreen" + game.setScreen(GdxGame.ScreenType.Next_Screen); + logger.info("game level completed detected, go to NextLevelScreen"); + } + } } - } + // Add something in to unlock the next planet/level? @Override public void resize(int width, int height) { @@ -304,7 +311,6 @@ private void createUI() { .addComponent(ServiceLocator.getWaveService().getDisplay()) .addComponent(new MainGameExitDisplay()) .addComponent(new MainGameLoseDisplay()) - //.addComponent(new MainGameWinDisplay()) <- needs to be uncommented when team 3 have implemented the ui .addComponent(new MainGamePauseDisplay(this.game)) .addComponent(new Terminal()) .addComponent(inputComponent) diff --git a/source/core/src/main/com/csse3200/game/screens/NextLevelScreen.java b/source/core/src/main/com/csse3200/game/screens/NextLevelScreen.java index f5f6be7fa..e59493b8c 100644 --- a/source/core/src/main/com/csse3200/game/screens/NextLevelScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/NextLevelScreen.java @@ -23,13 +23,13 @@ public class NextLevelScreen extends ScreenAdapter { public NextLevelScreen(GdxGame game) { batch = new SpriteBatch(); - backgroundTexture = new Texture("next_level_background.png"); // Replace with the path to your background image + backgroundTexture = new Texture("planets/background.png"); // Replace with the path to your background image font = new BitmapFont(); stage = new Stage(new ScreenViewport()); Gdx.input.setInputProcessor(stage); - Skin skin = new Skin(Gdx.files.internal("configs/text.json")); // Replace with the path to your UI skin JSON + Skin skin = new Skin(Gdx.files.internal("images/ui/buttons/glass.json")); // Replace with the path to your UI skin JSON TextButton nextLevelButton = new TextButton("Next Level", skin); nextLevelButton.addListener(new ClickListener() { @Override diff --git a/source/core/src/main/com/csse3200/game/screens/WinningScreen.java b/source/core/src/main/com/csse3200/game/screens/WinningScreen.java index 3dee5c9ac..2668682e2 100644 --- a/source/core/src/main/com/csse3200/game/screens/WinningScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/WinningScreen.java @@ -25,11 +25,11 @@ public class WinningScreen extends ScreenAdapter { private Texture backgroundTexture; private Sprite backgroundSprite; - private static final String BACKGROUND_TEXTURE = "winning_background.png"; // Set the path to your winning background image + private static final String BACKGROUND_TEXTURE = "planets/background.png"; // Set the path to your winning background image private static final String WIN_TEXT = """ Congratulations! You won! """; - private static final String[] winSounds = {"win_sound.ogg"}; // Set the path to your winning sound + // private static final String[] winSounds = {"win_sound.ogg"}; // Set the path to your winning sound private final BitmapFont font; private Stage stage; private final ResourceService resourceService; @@ -39,10 +39,11 @@ public WinningScreen(GdxGame game) { font = new BitmapFont(); resourceService = new ResourceService(); ServiceLocator.registerResourceService(resourceService); - resourceService.loadSounds(winSounds); + // resourceService.loadSounds(winSounds); resourceService.loadAll(); } + @Override public void show() { batch = new SpriteBatch(); @@ -53,7 +54,7 @@ public void show() { stage = new Stage(new ScreenViewport()); Gdx.input.setInputProcessor(stage); - Skin skin = new Skin(Gdx.files.internal("configs/text.json")); + Skin skin = new Skin(Gdx.files.internal("images/ui/buttons/glass.json")); TextButton exitButton = new TextButton("Exit Game", skin); exitButton.addListener(new ClickListener(){ public void clicked(InputEvent event, float x, float y) { @@ -84,7 +85,7 @@ public void clicked(InputEvent event, float x, float y) { stage.addActor(table); // Play win sound - resourceService.getAsset(winSounds[0], Sound.class).play(0.3f); + // resourceService.getAsset(winSounds[0], Sound.class).play(0.3f); } @Override