pathfinder test
This commit is contained in:
parent
7c959b93c7
commit
292f446d10
@ -19,5 +19,18 @@
|
|||||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.7.0-M1" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.7.0-M1" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0-M1" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0-M1" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0-M1" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0-M1" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-module-junit4:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-module-junit4-common:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-reflect:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.9.10" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.9.10" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-core:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.javassist:javassist:3.27.0-GA" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-api-mockito2:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-api-support:2.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.28.2" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
13
pom.xml
13
pom.xml
@ -25,5 +25,18 @@
|
|||||||
<version>RELEASE</version>
|
<version>RELEASE</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-module-junit4</artifactId>
|
||||||
|
<version>2.0.6</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-api-mockito2</artifactId>
|
||||||
|
<version>2.0.6</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -33,6 +33,11 @@ public class Npc extends Person {
|
|||||||
loadNpc();
|
loadNpc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Npc(int x, int y, Map map, MapManager mapManager) {
|
||||||
|
super(x, y, map);
|
||||||
|
this.mapManager = mapManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void move(int endX, int endY) {
|
public void move(int endX, int endY) {
|
||||||
PathFinder pathFinder = new PathFinder(getMap());
|
PathFinder pathFinder = new PathFinder(getMap());
|
||||||
for (Direction direction: pathFinder.getWayWithCollision(getX(), getY(), endX, endY)){
|
for (Direction direction: pathFinder.getWayWithCollision(getX(), getY(), endX, endY)){
|
||||||
@ -97,6 +102,7 @@ public class Npc extends Person {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics2D g) {
|
public void paint(Graphics2D g) {
|
||||||
|
if (name != null) {
|
||||||
BufferedImage image = null;
|
BufferedImage image = null;
|
||||||
try {
|
try {
|
||||||
image = ImageIO.read(new File("src/main/resources/characters/" + imageNpc)).getSubimage(width * direction, 0, width, height);
|
image = ImageIO.read(new File("src/main/resources/characters/" + imageNpc)).getSubimage(width * direction, 0, width, height);
|
||||||
@ -106,6 +112,7 @@ public class Npc extends Person {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setDirection(int direction) {
|
public void setDirection(int direction) {
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
BLOCK 120
|
|
||||||
MOVETO 277
|
|
||||||
EVENT 334
|
|
||||||
TRIGGER 147
|
|
||||||
@ -1,5 +1,9 @@
|
|||||||
<tileset> A2_Ground.png 512 384 32
|
<tileset> A2_Ground.png 512 384 32
|
||||||
<tileset> D_OutDoor.png 512 512 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
36 36
|
36 36
|
||||||
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK MOVETO,6,3,m1 BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
|
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK SPAWN BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
|
||||||
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
|
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
|
||||||
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
|
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
|
||||||
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
|
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
|
||||||
|
|||||||
@ -4,3 +4,4 @@
|
|||||||
<0> boss
|
<0> boss
|
||||||
<0> treasure
|
<0> treasure
|
||||||
<1> glade
|
<1> glade
|
||||||
|
<999> m6
|
||||||
@ -1,8 +1,10 @@
|
|||||||
package ruscz.game.gameOfProd.Scripts;
|
package ruscz.game.gameOfProd.Scripts;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import ruscz.game.gameOfProd.Cells.Npc;
|
||||||
import ruscz.game.gameOfProd.Map.Map;
|
import ruscz.game.gameOfProd.Map.Map;
|
||||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
@ -13,34 +15,57 @@ public class PathFinderTest {
|
|||||||
|
|
||||||
public static Stream<Arguments> argumentsStream(){
|
public static Stream<Arguments> argumentsStream(){
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.of(1,1,1,1)
|
Arguments.of(1,1,8,8, true),
|
||||||
// Arguments.of(),
|
Arguments.of(4, 7, 6, 1, true),
|
||||||
// Arguments.of(),
|
Arguments.of(13, 1, 17, 9, true),
|
||||||
// Arguments.of(),
|
Arguments.of(21, 1, 22, 9, true),
|
||||||
// Arguments.of()
|
Arguments.of(26, 5, 33, 5, true),
|
||||||
|
Arguments.of(28, 3, 32, 7, true),
|
||||||
|
Arguments.of(29, 3, 29, 7, true),
|
||||||
|
Arguments.of(3, 17, 6, 17, true),
|
||||||
|
Arguments.of(3, 15, 5, 20, true),
|
||||||
|
Arguments.of(7, 17, 4, 18, true),
|
||||||
|
Arguments.of(13, 15, 22, 22, false),
|
||||||
|
Arguments.of(14, 20, 20, 16, false),
|
||||||
|
Arguments.of(26, 13, 30, 22, true),
|
||||||
|
Arguments.of(26, 13, 35, 20, true),
|
||||||
|
Arguments.of(1, 26, 9, 34, true),
|
||||||
|
Arguments.of(1, 26, 8, 26, true),
|
||||||
|
Arguments.of(22, 34, 17, 31, true),
|
||||||
|
Arguments.of(17, 31, 13, 34, true),
|
||||||
|
Arguments.of(27, 26, 33, 34, true),
|
||||||
|
Arguments.of(33, 34, 31, 32, true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("argumentsStream")
|
@MethodSource("argumentsStream")
|
||||||
public void getWayWithCollision_usingMap6ForTestOfPathFinding_rightPositionOfNpc(int startX, int startY, int endX, int endY) {
|
public void getWayWithCollision_usingMap6ForTestOfPathFinding_rightPositionOfNpc(int startX, int startY, int endX, int endY, boolean isPossible) {
|
||||||
//Arrange
|
//Arrange
|
||||||
WindowOfFreeMove freeMove;
|
WindowOfFreeMove freeMove;
|
||||||
|
Map testMap;
|
||||||
|
Npc testNpc;
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
freeMove = new WindowOfFreeMove(new JFrame());
|
freeMove = new WindowOfFreeMove(new JFrame());
|
||||||
freeMove.setVisible(false);
|
freeMove.setVisible(false);
|
||||||
WindowOfFreeMove.setCHAPTER("999");
|
WindowOfFreeMove.setCHAPTER("999");
|
||||||
freeMove.start(true);
|
freeMove.start(true);
|
||||||
freeMove.setMapManager(Map.findMapByName("m6",freeMove));
|
testMap = Map.findMapByName("m6",freeMove);
|
||||||
|
freeMove.setMapManager(testMap);
|
||||||
|
testNpc = new Npc(startX, startY, testMap, freeMove.getMapManager());
|
||||||
|
testNpc.move(endX, endY);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
|
if (isPossible) {
|
||||||
|
Assertions.assertEquals(endX, testNpc.getX());
|
||||||
|
Assertions.assertEquals(endY, testNpc.getY());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Assertions.assertEquals(startX, testNpc.getX());
|
||||||
|
Assertions.assertEquals(startY, testNpc.getY());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user