all tests done
This commit is contained in:
parent
fd6992b0d1
commit
d9b9ea79a8
@ -295,4 +295,8 @@ public class InteractionCell extends Cell {
|
||||
}
|
||||
|
||||
public SoundManager getSoundManager() { return soundManager; }
|
||||
|
||||
public Dialog getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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("<"));
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
BLOCK 120
|
||||
MOVETO 277
|
||||
EVENT 334
|
||||
TRIGGER 147
|
||||
@ -1,5 +1,9 @@
|
||||
<tileset> A2_Ground.png 512 384 32
|
||||
<tileset> D_OutDoor.png 512 512 32
|
||||
<cellmap> BLOCK 120
|
||||
<cellmap> MOVETO 277
|
||||
<cellmap> EVENT 334
|
||||
<cellmap> 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
|
||||
|
||||
@ -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
|
||||
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
|
||||
@ -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
|
||||
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
|
||||
@ -4,4 +4,5 @@
|
||||
<0> boss
|
||||
<0> treasure
|
||||
<1> glade
|
||||
<999> m1
|
||||
<999> m6
|
||||
15
src/main/resources/save/savedGame/events-DESKTOP-TL25DTN.txt
Normal file
15
src/main/resources/save/savedGame/events-DESKTOP-TL25DTN.txt
Normal file
@ -0,0 +1,15 @@
|
||||
<map>
|
||||
<mapName>m1</mapName>
|
||||
<events>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>m6</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>11</x>
|
||||
<y>11</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
@ -0,0 +1,15 @@
|
||||
<map>
|
||||
<mapName>m1</mapName>
|
||||
<events>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>m6</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>11</x>
|
||||
<y>11</y>
|
||||
<active>false</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
@ -0,0 +1,6 @@
|
||||
<location>
|
||||
<map>m1</map>
|
||||
<x>3</x>
|
||||
<y>7</y>
|
||||
<direction>2</direction>
|
||||
</location>
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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<Arguments> 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());
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user