From 2328494c4f01d0d0e8a023c86c73522370006d6d Mon Sep 17 00:00:00 2001 From: musilto9 Date: Sun, 7 Jun 2020 15:27:09 +0200 Subject: [PATCH] test --- .../ruscz/game/gameOfProd/Battle/Battle.java | 25 +++++++++++-- .../gameOfProd/Cells/InteractionCell.java | 6 +++- .../game/gameOfProd/Sounds/MusicManager.java | 23 ++++++------ .../gameOfProd/Windows/WindowOfBattle.java | 35 ++++++++++++++++--- .../resources/battles/storageroombattle.txt | 6 ++-- .../cutscene-storageroombattle-lose.txt | 10 ++++++ .../cutscene-storageroombattle-win.txt | 10 ++++++ src/main/resources/save/savedGame/events.txt | 6 ++-- .../resources/save/savedGame/inventory.txt | 6 ---- src/main/resources/save/savedGame/person.txt | 8 ++--- 10 files changed, 100 insertions(+), 35 deletions(-) create mode 100644 src/main/resources/dialogs/cutscenes/cutscene-storageroombattle-lose.txt create mode 100644 src/main/resources/dialogs/cutscenes/cutscene-storageroombattle-win.txt diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java index 7351bd8..76b81ac 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java @@ -1,6 +1,9 @@ package ruscz.game.gameOfProd.Battle; +import ruscz.game.gameOfProd.Cells.InteractionCell; +import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Windows.WindowOfBattle; +import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import javax.swing.*; import java.awt.*; @@ -96,11 +99,27 @@ public class Battle { } private void endBattle(boolean b) { - //TODO Return to Map timer.stop(); timerStopped = true; - if (b) windowOfBattle.writeToOutput("Win!"); - else windowOfBattle.writeToOutput("Lose!"); + windowOfBattle.setVisible(false); + WindowOfFreeMove windowOfFreeMove = windowOfBattle.getGame().getFreeMove(); + windowOfBattle.getMenuOfActions().getAttack().removeActionListener(windowOfBattle.getMenuOfActions().getAttack().getActionListeners()[0]); + windowOfBattle.getMenuOfActions().getConsole().removeActionListener(windowOfBattle.getMenuOfActions().getConsole().getActionListeners()[0]); + windowOfBattle.getMenuOfActions().getEscape().removeActionListener(windowOfBattle.getMenuOfActions().getEscape().getActionListeners()[0]); + windowOfBattle.getMenuOfActions().getInventory().removeActionListener(windowOfBattle.getMenuOfActions().getInventory().getActionListeners()[0]); + InteractionCell ic; + if (b) ic = new InteractionCell(-1, -1, windowOfBattle.getWinCutscene(), + new Dialog(windowOfFreeMove.getDialogBar()), windowOfFreeMove.getMapManager().getActualMap(), windowOfFreeMove, true); + else ic = new InteractionCell(-1, -1, windowOfBattle.getLoseCutscene(), + new Dialog(windowOfFreeMove.getDialogBar()), windowOfFreeMove.getMapManager().getActualMap(), windowOfFreeMove, true); + ic.startEvent(); + windowOfFreeMove.getForegroundPanel().setColorForeground(0, 0, 0, 255); + windowOfFreeMove.setVisible(true); + windowOfFreeMove.requestFocus(); + windowOfBattle.getGame().remove(windowOfBattle); + windowOfBattle.getMusicManager().stopMusic(); +// SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager(); +// saveManager.saveGame(); } private void returnControlToPlayer(){ diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index acb862b..05bae83 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -338,7 +338,7 @@ public class InteractionCell extends Cell { Npc npc = new Npc(Integer.parseInt(position[0]), Integer.parseInt(position[1]), data[3], Map.findMapByName(position[2], window), window.getMapManager()); Map.findMapByName(position[2], window).setNpcs(npc); } - else if (data[2].contains("move")) { + else if (data[2].contains("move") && !data[2].equals("remove")) { Npc npc = window.getMapManager().getActualMap().findNpcByName(data[3]); if (data[2].equals("movetoplayer")) { npc.move(window.getMapManager().getActualMap().getPerson().getX(), window.getMapManager().getActualMap().getPerson().getY()); @@ -347,6 +347,10 @@ public class InteractionCell extends Cell { npc.move(Integer.parseInt(data[4]), Integer.parseInt(data[5])); } } + else if (data[2].equals("remove")) { + Npc npc = window.getMapManager().getActualMap().findNpcByName(data[3]); + window.getMapManager().getActualMap().getNpcs().remove(npc); + } } else if (data[1].equals("")) window.getMapManager().getActualMap().getNpcs().clear(); else if (data[1].equals("")) window.loadNextChapter(); diff --git a/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java b/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java index f04b3c6..67d4b37 100644 --- a/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java +++ b/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java @@ -24,24 +24,23 @@ public class MusicManager { AudioInputStream audioIn; try { audioIn = AudioSystem.getAudioInputStream(new File("src/main/resources/music/" + musicName)); - clip = AudioSystem.getClip(); - if (clip != null) { - clip.open(audioIn); - } - if (clip != null) { - gainControl = - (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); - gainControl.setValue(volume); - clip.loop(1000); - clip.start(); - } + clip = AudioSystem.getClip(); + if (clip != null) { + clip.open(audioIn); + } + if (clip != null) { + gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); + gainControl.setValue(volume); + clip.loop(1000); + clip.start(); + } } catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) { e.printStackTrace(); } } public void stopMusic() { - timerOut.stop(); + if (timerOut != null) timerOut.stop(); clip.stop(); volume = -40.0f; } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java index edf42e9..c94965b 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java @@ -67,6 +67,10 @@ public class WindowOfBattle extends JPanel { private MusicManager musicManager; + private String winCutscene; + private String loseCutscene; + private String name; + public Battle getBattle() { return battle; } @@ -108,15 +112,16 @@ public class WindowOfBattle extends JPanel { } } }); + + setCursor(Cursor.getDefaultCursor()); } public void startBattle(String name) { -// SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager(); -// saveManager.saveGame(); - LinkedList heroes = new LinkedList<>(); LinkedList enemies = new LinkedList<>(); + this.name = name; + try { File battleFile = new File("src/main/resources/battles/" + name + ".txt"); Scanner scanner = new Scanner(battleFile); @@ -141,12 +146,17 @@ public class WindowOfBattle extends JPanel { if (data[1].equals("flicker")) canvas.flicker(Integer.parseInt(data[2])); else canvas.addImage(data[1]); } + else if (data[0].equals("")) { + winCutscene = data[1]; + } + else if (data[0].equals("")) { + loseCutscene = data[1]; + } } } catch (FileNotFoundException e) { e.printStackTrace(); } - MusicManager musicManager = new MusicManager("Fight_Music.wav", -15.0f); battle = new Battle(heroes, enemies, this); isReadyToPaint = true; @@ -186,6 +196,23 @@ public class WindowOfBattle extends JPanel { return game; } + public MusicManager getMusicManager() { + return musicManager; + } + + public String getWinCutscene() { + return winCutscene; + } + + public String getLoseCutscene() { + return loseCutscene; + } + + @Override + public String getName() { + return name; + } + class Canvas extends JPanel { private LinkedList images; private BufferedImage image; diff --git a/src/main/resources/battles/storageroombattle.txt b/src/main/resources/battles/storageroombattle.txt index 085d4e4..1ca86d2 100644 --- a/src/main/resources/battles/storageroombattle.txt +++ b/src/main/resources/battles/storageroombattle.txt @@ -1,6 +1,8 @@ 100 10 Mark 1 10 1 main-battle - 100 10 Karen 10 1 monster-battle hover + 1 1 Karen 1 1 monster-battle hover Fight_Music.wav -10.0f battle1 battle2 - flicker 500 \ No newline at end of file + flicker 500 + cutscene-storageroombattle-win + cutscene-storageroombattle-lose \ No newline at end of file diff --git a/src/main/resources/dialogs/cutscenes/cutscene-storageroombattle-lose.txt b/src/main/resources/dialogs/cutscenes/cutscene-storageroombattle-lose.txt new file mode 100644 index 0000000..0d4ae8c --- /dev/null +++ b/src/main/resources/dialogs/cutscenes/cutscene-storageroombattle-lose.txt @@ -0,0 +1,10 @@ +<1> remove monster +<1> start +<1> 6 1 false +<1> fade 255 0 1 +<3> null +<3> image main-face.png +<3> Huh,-what-a-weird-encounter. +<5> null +<5> true +<5> \ No newline at end of file diff --git a/src/main/resources/dialogs/cutscenes/cutscene-storageroombattle-win.txt b/src/main/resources/dialogs/cutscenes/cutscene-storageroombattle-win.txt new file mode 100644 index 0000000..096c11a --- /dev/null +++ b/src/main/resources/dialogs/cutscenes/cutscene-storageroombattle-win.txt @@ -0,0 +1,10 @@ +<1> remove monster +<1> start +<1> 6 1 false +<1> fade 255 0 1 +<3> null +<3> image main-face.png +<3> Huh,-what-a-weird-encounter. +<5> null +<5> true +<5> diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index 3c83611..b09722c 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -14,7 +14,7 @@ 6 4 - false + true 14 @@ -24,7 +24,7 @@ 1 2 - false + true 15 @@ -74,7 +74,7 @@ 6 2 - true + false diff --git a/src/main/resources/save/savedGame/inventory.txt b/src/main/resources/save/savedGame/inventory.txt index 02de760..e69de29 100644 --- a/src/main/resources/save/savedGame/inventory.txt +++ b/src/main/resources/save/savedGame/inventory.txt @@ -1,6 +0,0 @@ - - cup-o'-coffee - 1 - 295 - heal - diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index ec0fcae..dc0552b 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -1,6 +1,6 @@ - storageroom - 6 - 2 - 0 + office + 2 + 11 + 2 \ No newline at end of file