diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index 2d2e7c5..7da9815 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -295,4 +295,8 @@ public class InteractionCell extends Cell { } public SoundManager getSoundManager() { return soundManager; } + + public Dialog getDialog() { + return dialog; + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java index acb45a2..b59f5ef 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java @@ -127,7 +127,7 @@ public class Person extends Cell { } break; } - if (directionMove != WindowOfFreeMove.KEY_EVENT) { + if (directionMove != WindowOfFreeMove.KEY_EVENT && !isInEvent) { if (directionMove != 0 && !map.isBusyCell(x, y, true) && !map.isInteractionCell(x, y) && !map.isClosedDoor(x, y) && !map.isChest(x, y)) { directionMoveLast = directionMove; isMoving = true; @@ -182,17 +182,6 @@ public class Person extends Cell { return map.isActiveChest(coords[0], coords[1]); } - public void stopPerson(){ - directionMove = 0; - directionMoveLast = 0; - distanceOfAnimation = 0; - isMoving = false; - } - - public boolean isInPerson(int x, int y) { - return this.getX() == x && this.getY() == y; - } - @Override public void paint(Graphics2D g) { super.paint(g); @@ -306,4 +295,8 @@ public class Person extends Cell { public int getDirectionSight() { return directionSight; } + + public static boolean isInEvent() { + return isInEvent; + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java b/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java index 1f92af4..570ca94 100644 --- a/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java +++ b/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java @@ -138,5 +138,9 @@ public class Dialog { public SoundManager getSoundManager() { return soundManager; } public void setVoiceover(boolean voiceover) { this.voiceover = voiceover; } + + public boolean isTimerIsRunning() { + return timerIsRunning; + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Game.java b/src/main/java/ruscz/game/gameOfProd/Game.java index a036209..32a0347 100644 --- a/src/main/java/ruscz/game/gameOfProd/Game.java +++ b/src/main/java/ruscz/game/gameOfProd/Game.java @@ -1,6 +1,5 @@ package ruscz.game.gameOfProd; -import ruscz.game.gameOfProd.LevelEditor.LevelEditor; import ruscz.game.gameOfProd.LevelEditor.TilesetOverview; import ruscz.game.gameOfProd.Windows.WindowOfBattle; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; @@ -41,10 +40,10 @@ public class Game extends JFrame { battle = new WindowOfBattle(this); //tohle spustí na začátku menu - add(menu); +// add(menu); //tohle spustí na začátku hru -// add(freeMove); + add(freeMove); // freeMove.start(true); //tohle spustí na začátku bitvu diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java b/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java index 4629638..8d039cd 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java @@ -21,9 +21,9 @@ public class ImageCell { private int[][] mapBackground; private int[][] mapForeground; - public void readMapFile() { - mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH][WindowOfFreeMove.CANVAS_HEIGHT]; - mapForeground = new int[WindowOfFreeMove.CANVAS_WIDTH][WindowOfFreeMove.CANVAS_HEIGHT]; + public void readMapFile(int width, int height) { + mapBackground = new int[width][height]; + mapForeground = new int[width][height]; } public void readMapFile(String name) { diff --git a/src/main/java/ruscz/game/gameOfProd/LevelEditor/LevelEditor.java b/src/main/java/ruscz/game/gameOfProd/LevelEditor/LevelEditor.java index f025fdc..05b11ae 100644 --- a/src/main/java/ruscz/game/gameOfProd/LevelEditor/LevelEditor.java +++ b/src/main/java/ruscz/game/gameOfProd/LevelEditor/LevelEditor.java @@ -132,7 +132,7 @@ public class LevelEditor extends JFrame { } int[] size = {width, height}; map.setCanvasSize(size); - map.getImageCell().readMapFile(); + map.getImageCell().readMapFile(width, height); startMapEditor(); } diff --git a/src/main/java/ruscz/game/gameOfProd/Save/LoadManager.java b/src/main/java/ruscz/game/gameOfProd/Save/LoadManager.java index e8f262e..5875da0 100644 --- a/src/main/java/ruscz/game/gameOfProd/Save/LoadManager.java +++ b/src/main/java/ruscz/game/gameOfProd/Save/LoadManager.java @@ -36,7 +36,6 @@ public class LoadManager { loadPerson(); loadEvents(); loadInventory(); - loadVillage(); } public void clearSave() { @@ -45,8 +44,6 @@ public class LoadManager { writer.write(""); writer = new FileWriter("src/main/resources/save/savedGame/events.txt"); writer.write(""); - writer = new FileWriter("src/main/resources/save/savedGame/village.txt"); - writer.write(""); writer = new FileWriter("src/main/resources/save/savedGame/inventory.txt"); writer.write(""); writer.close(); @@ -178,17 +175,6 @@ public class LoadManager { } - private void loadVillage() { - try { - File villageFile = new File("src/main/resources/save/savedGame/village.txt"); - Scanner scanner = new Scanner(villageFile); - scanner.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - //TODO: loadVillage - } - private String getValue(String line) { return line.substring(line.indexOf(">") + 1, line.lastIndexOf("<")); } diff --git a/src/main/java/ruscz/game/gameOfProd/Save/SaveManager.java b/src/main/java/ruscz/game/gameOfProd/Save/SaveManager.java index a3e4970..98d012c 100644 --- a/src/main/java/ruscz/game/gameOfProd/Save/SaveManager.java +++ b/src/main/java/ruscz/game/gameOfProd/Save/SaveManager.java @@ -23,7 +23,6 @@ public class SaveManager { savePerson(); saveEvents(); saveInventory(); - saveVillage(); } private void savePerson() { @@ -102,15 +101,4 @@ public class SaveManager { e.printStackTrace(); } } - - private void saveVillage() { - try { - FileWriter writer = new FileWriter("src/main/resources/save/savedGame/village.txt"); - String village = "TODO: Village"; - writer.write(village); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index ae4f4c2..b886640 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -74,6 +74,10 @@ public class WindowOfFreeMove extends JLayeredPane { WindowOfFreeMove.canPersonMove = canPersonMove; } + public static boolean canPersonMove() { + return canPersonMove; + } + public void setMapManager(Map mapManager) { this.mapManager.setMap(mapManager); } @@ -212,7 +216,7 @@ public class WindowOfFreeMove extends JLayeredPane { public class Canvas extends JPanel { @Override public void paint(Graphics g) { - if (isReadyToPaint) { + if (isReadyToPaint && mapManager != null) { super.paint(g); Graphics2D g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, diff --git a/src/main/resources/maps/999/m1-cellmap.txt b/src/main/resources/maps/999/m1-cellmap.txt deleted file mode 100644 index 562ec79..0000000 --- a/src/main/resources/maps/999/m1-cellmap.txt +++ /dev/null @@ -1,4 +0,0 @@ -BLOCK 120 -MOVETO 277 -EVENT 334 -TRIGGER 147 \ No newline at end of file diff --git a/src/main/resources/maps/999/m1-tileset.txt b/src/main/resources/maps/999/m1-tileset.txt index f2397a7..6c17b8f 100644 --- a/src/main/resources/maps/999/m1-tileset.txt +++ b/src/main/resources/maps/999/m1-tileset.txt @@ -1,5 +1,9 @@ A2_Ground.png 512 384 32 D_OutDoor.png 512 512 32 + BLOCK 120 + MOVETO 277 + EVENT 334 + TRIGGER 147 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 82 94 1 1 82 94 1 1 diff --git a/src/main/resources/maps/999/m6.txt b/src/main/resources/maps/999/m6.txt index 3e9f63e..5f3a6eb 100644 --- a/src/main/resources/maps/999/m6.txt +++ b/src/main/resources/maps/999/m6.txt @@ -34,4 +34,4 @@ BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EM BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY BLOCK BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY BLOCK -BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK \ No newline at end of file +BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK MOVETO,6,1,m1 BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK \ No newline at end of file diff --git a/src/main/resources/maps/custom/test.txt b/src/main/resources/maps/custom/test.txt index 3e9f63e..5f3a6eb 100644 --- a/src/main/resources/maps/custom/test.txt +++ b/src/main/resources/maps/custom/test.txt @@ -34,4 +34,4 @@ BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EM BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY BLOCK BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY BLOCK -BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK \ No newline at end of file +BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK MOVETO,6,1,m1 BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK \ No newline at end of file diff --git a/src/main/resources/save/newGame/maps.txt b/src/main/resources/save/newGame/maps.txt index f147ff0..91d0103 100644 --- a/src/main/resources/save/newGame/maps.txt +++ b/src/main/resources/save/newGame/maps.txt @@ -4,4 +4,5 @@ <0> boss <0> treasure <1> glade +<999> m1 <999> m6 \ No newline at end of file diff --git a/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN.txt b/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN.txt new file mode 100644 index 0000000..3f5c206 --- /dev/null +++ b/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN.txt @@ -0,0 +1,15 @@ + + m1 + + + + + m6 + + + 11 + 11 + true + + + diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index e69de29..86e28da 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -0,0 +1,15 @@ + + m1 + + + + + m6 + + + 11 + 11 + false + + + diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index e69de29..43cfc91 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -0,0 +1,6 @@ + + m1 + 3 + 7 + 2 + \ No newline at end of file diff --git a/src/main/resources/save/savedGame/village.txt b/src/main/resources/save/savedGame/village.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/java/ruscz/game/gameOfProd/Map/MapTest.java b/src/test/java/ruscz/game/gameOfProd/Map/MapTest.java index 5cd0d71..1127966 100644 --- a/src/test/java/ruscz/game/gameOfProd/Map/MapTest.java +++ b/src/test/java/ruscz/game/gameOfProd/Map/MapTest.java @@ -21,7 +21,7 @@ public class MapTest { @Test public void loadMapFromFile_parseMapFileToMapArray_mapArrayParsedCorrectly() { //Arrange - Map testMap; + Map testMap, testMap2; TypeOfCell[][] mapArray; WindowOfFreeMove window; @@ -91,9 +91,6 @@ public class MapTest { line[j].toUpperCase().contains("CHEST")) { mapArray[j][i] = TypeOfCell.EVENT; } - else if (line[j].toUpperCase().contains("MOVETO")) { - mapArray[j][i] = TypeOfCell.MOVETO; - } else if (line[j].equals("SPAWN")) { mapArray[j][i] = TypeOfCell.SPAWNPOINT; } diff --git a/src/test/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMoveTest.java b/src/test/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMoveTest.java new file mode 100644 index 0000000..33e0c2e --- /dev/null +++ b/src/test/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMoveTest.java @@ -0,0 +1,308 @@ +package ruscz.game.gameOfProd.Windows; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import ruscz.game.gameOfProd.Cells.Person; +import ruscz.game.gameOfProd.Cells.TriggerCell; +import ruscz.game.gameOfProd.Game; +import ruscz.game.gameOfProd.Map.Map; +import ruscz.game.gameOfProd.Save.SaveManager; + +import javax.swing.*; +import java.util.stream.Stream; + +import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.sleep; + +public class WindowOfFreeMoveTest { + + public static final int KEY_LEFT = 37; + public static final int KEY_UP = 38; + public static final int KEY_RIGHT = 39; + public static final int KEY_DOWN = 40; + public static final int KEY_EVENT = 69; + + private Timer timer; + private Game game; + private WindowOfFreeMove freeMove; + private Map testMap; + private Person person; + + @BeforeEach + public void setUp() { + game = new Game(); + freeMove = new WindowOfFreeMove(game); + game.add(freeMove); + WindowOfFreeMove.setCHAPTER("999"); + freeMove.start(true); + testMap = Map.findMapByName("m6",freeMove); + freeMove.setMapManager(testMap); + freeMove.getMapManager().setMap(testMap); + person = freeMove.getMapManager().getActualMap().getPerson(); + } + + @AfterEach + public void cleanUp() { + game.dispose(); + } + + public static Stream argumentsStream() { + return Stream.of( + Arguments.of(new int[]{KEY_UP}, 0, -1), + Arguments.of(new int[]{KEY_DOWN}, 0, 1), + Arguments.of(new int[]{KEY_LEFT}, -1, 0), + Arguments.of(new int[]{KEY_RIGHT}, 1, 0), + Arguments.of(new int[]{KEY_RIGHT, KEY_UP}, 1, 0), + Arguments.of(new int[]{KEY_RIGHT, KEY_RIGHT, KEY_LEFT, KEY_DOWN, KEY_LEFT, KEY_DOWN}, 0, 1), + Arguments.of(new int[]{KEY_UP, KEY_UP, KEY_RIGHT, KEY_LEFT, KEY_RIGHT, KEY_RIGHT, KEY_UP}, 0, -3), + Arguments.of(new int[]{KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_UP, KEY_RIGHT, KEY_RIGHT}, 2, 0), + Arguments.of(new int[]{KEY_LEFT, KEY_LEFT, KEY_LEFT, KEY_LEFT}, -4, 0), + Arguments.of(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, 0, 0) + ); + } + + @ParameterizedTest + @MethodSource("argumentsStream") + public void move_moveCharacterOnMap_CharacterChangesPositionWithCollisionDetection(int[] directions, int xPath, int yPath) { + //Arrage + //is in setUp() + + //Act + final int[] i = {0}; + timer = new Timer(10, actionEvent -> { + if (!person.getIsMoving()) { + if (i[0] == directions.length) { + stopTimer(); + } + else { + person.setDirectionMove(directions[i[0]]); + i[0]++; + } + } + }); + timer.start(); + + while(timer.isRunning()) { + continue; + } + + //Assert + Assertions.assertEquals(testMap.getSpawnPoint()[0] + xPath, person.getX()); + Assertions.assertEquals(testMap.getSpawnPoint()[1] + yPath, person.getY()); + } + + private void stopTimer() { + timer.stop(); + } + + @Test + public void moveToMap_CharacterMovesToDifferentMap_CharacterIsOnCorrectMap() { + //Arrange + int[] directions = {KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN}; + + //Act + final int[] i = {0}; + timer = new Timer(10, actionEvent -> { + if (!person.getIsMoving()) { + if (i[0] == directions.length) { + stopTimer(); + } + else { + person.setDirectionMove(directions[i[0]]); + i[0]++; + } + } + }); + timer.start(); + + while(timer.isRunning() || person.getIsMoving()) { + continue; + } + + sleep(50); + + //Assert + Assertions.assertEquals("m1", freeMove.getMapManager().getActualMap().getName()); + + //Act + final boolean[] flag = {false}; + timer = new Timer(10, actionEvent -> { + if (!freeMove.getMapManager().getActualMap().getPerson().getIsMoving() && WindowOfFreeMove.canPersonMove()) { + if (!flag[0]) { + freeMove.getMapManager().getActualMap().getPerson().setDirectionMove(KEY_DOWN); + flag[0] = true; + } + else { + stopTimer(); + } + } + }); + timer.start(); + + while(timer.isRunning() || freeMove.getMapManager().getActualMap().getPerson().getIsMoving()) { + continue; + } + + //Assert + Assertions.assertEquals("m6", freeMove.getMapManager().getActualMap().getName()); + } + + @Test + public void startEvent_CharacterEntersEventThenGoesThroughEventThenExitsEvent_CorrectCharacterResponses() { + //Arrange + int[] directions = {KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP}; + + //Act + final int[] i = {0}; + timer = new Timer(10, actionEvent -> { + if (!person.getIsMoving()) { + if (i[0] == directions.length) { + stopTimer(); + } + else { + person.setDirectionMove(directions[i[0]]); + i[0]++; + } + } + }); + timer.start(); + + while(timer.isRunning() || person.getIsMoving()) { + continue; + } + + sleep(50); + TriggerCell triggerCell = testMap.findTriggerByXY(person.getX(), person.getY()); + + //Assert + Assertions.assertTrue(person.isInEvent()); + Assertions.assertFalse(person.getIsMoving()); + Assertions.assertFalse(triggerCell == null); + + //Act + person.setDirectionMove(KEY_LEFT); + + //Assert + Assertions.assertTrue(person.isInEvent()); + Assertions.assertEquals(triggerCell.getX(), person.getX()); + Assertions.assertEquals(triggerCell.getY(), person.getY()); + + //Act + timer = new Timer(100, actionEvent -> { + if (!person.isInEvent()) { + stopTimer(); + } + else { + if (!triggerCell.getDialog().getTimerIsRunning()) { + person.setDirectionMove(KEY_EVENT); + } + } + }); + timer.start(); + + while(timer.isRunning() || person.isInEvent()) { + continue; + } + + final boolean[] flag = {false}; + timer = new Timer(10, actionEvent -> { + if (!person.getIsMoving()) { + if (!flag[0]) { + person.setDirectionMove(KEY_LEFT); + flag[0] = true; + } + else { + stopTimer(); + } + } + }); + timer.start(); + + while(timer.isRunning() || person.getIsMoving()) { + continue; + } + + //Assert + Assertions.assertEquals(triggerCell.getX() - 1, person.getX()); + Assertions.assertEquals(triggerCell.getY(), person.getY()); + } + + @Test + public void saveGame_CharacterInteractsWithTriggerCellThenMovesToDifferentMapThenGameIsSaved_CorrectlySavedProgress() { + //Assert + SaveManager saveManager; + + //Act + startEvent_CharacterEntersEventThenGoesThroughEventThenExitsEvent_CorrectCharacterResponses(); + + int[] directions = {KEY_RIGHT, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN}; + + final int[] i = {0}; + timer = new Timer(10, actionEvent -> { + if (!person.getIsMoving()) { + if (i[0] == directions.length) { + stopTimer(); + } + else { + person.setDirectionMove(directions[i[0]]); + i[0]++; + } + } + }); + timer.start(); + + while(timer.isRunning() || person.getIsMoving()) { + continue; + } + + moveToMap_CharacterMovesToDifferentMap_CharacterIsOnCorrectMap(); + + final boolean[] flag = {false}; + timer = new Timer(10, actionEvent -> { + if (!freeMove.getMapManager().getActualMap().getPerson().getIsMoving() && WindowOfFreeMove.canPersonMove()) { + if (!flag[0]) { + freeMove.getMapManager().getActualMap().getPerson().setDirectionMove(KEY_DOWN); + flag[0] = true; + } + else { + stopTimer(); + } + } + }); + timer.start(); + + while(timer.isRunning() || freeMove.getMapManager().getActualMap().getPerson().getIsMoving()) { + continue; + } + + //Assert + Assertions.assertEquals("m1", freeMove.getMapManager().getActualMap().getName()); + + //Act + person = freeMove.getMapManager().getActualMap().getPerson(); + int[] personCoords = new int[]{person.getX(), person.getY(), person.getDirectionSight()}; + boolean triggerIsActive = testMap.findTriggerByXY(11, 11).getActive(); + saveManager = new SaveManager(freeMove.getMapManager()); + saveManager.saveGame(); + game.dispose(); + + game = new Game(); + freeMove = new WindowOfFreeMove(game); + game.add(freeMove); + WindowOfFreeMove.setCHAPTER("999"); + freeMove.setCanvasSize(new int[]{50, 50}); + freeMove.start(false); + + sleep(1000); + + //Assert + Assertions.assertEquals(personCoords[0], freeMove.getMapManager().getActualMap().getPerson().getX()); + Assertions.assertEquals(personCoords[1], freeMove.getMapManager().getActualMap().getPerson().getY()); + Assertions.assertEquals(personCoords[2], freeMove.getMapManager().getActualMap().getPerson().getDirectionSight()); + Assertions.assertEquals(triggerIsActive, Map.findMapByName("m6", freeMove).findTriggerByXY(11, 11).getActive()); + } +}