diff --git a/gameOfProd.iml b/gameOfProd.iml
index e1c1adc..e16d728 100644
--- a/gameOfProd.iml
+++ b/gameOfProd.iml
@@ -19,5 +19,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 7bf1359..4689245 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,5 +25,18 @@
RELEASE
test
+
+ org.powermock
+ powermock-module-junit4
+ 2.0.6
+ test
+
+
+
+ org.powermock
+ powermock-api-mockito2
+ 2.0.6
+ test
+
\ No newline at end of file
diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java
index dfa346f..630b152 100644
--- a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java
+++ b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java
@@ -33,6 +33,11 @@ public class Npc extends Person {
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) {
PathFinder pathFinder = new PathFinder(getMap());
for (Direction direction: pathFinder.getWayWithCollision(getX(), getY(), endX, endY)){
@@ -97,13 +102,15 @@ public class Npc extends Person {
@Override
public void paint(Graphics2D g) {
- BufferedImage image = null;
- try {
- image = ImageIO.read(new File("src/main/resources/characters/" + imageNpc)).getSubimage(width * direction, 0, width, height);
- g.drawImage(image, getX() * getSize() + (getSize() / 5) + offsetX,
- getY() * getSize() - (getSize() * 3/5) + offsetY, getSize() * widthCoef/5, getSize() * heightCoef/2, null);
- } catch (IOException e) {
- e.printStackTrace();
+ if (name != null) {
+ BufferedImage image = null;
+ try {
+ image = ImageIO.read(new File("src/main/resources/characters/" + imageNpc)).getSubimage(width * direction, 0, width, height);
+ g.drawImage(image, getX() * getSize() + (getSize() / 5) + offsetX,
+ getY() * getSize() - (getSize() * 3 / 5) + offsetY, getSize() * widthCoef / 5, getSize() * heightCoef / 2, null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/src/main/resources/maps/999/m6-cellmap.txt b/src/main/resources/maps/999/m6-cellmap.txt
deleted file mode 100644
index 562ec79..0000000
--- a/src/main/resources/maps/999/m6-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/m6-tileset.txt b/src/main/resources/maps/999/m6-tileset.txt
index 6e57bdd..d6917cb 100644
--- a/src/main/resources/maps/999/m6-tileset.txt
+++ b/src/main/resources/maps/999/m6-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 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
diff --git a/src/main/resources/maps/999/m6.txt b/src/main/resources/maps/999/m6.txt
index 316673e..c8fca8e 100644
--- a/src/main/resources/maps/999/m6.txt
+++ b/src/main/resources/maps/999/m6.txt
@@ -1,5 +1,5 @@
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
diff --git a/src/main/resources/save/newGame/maps.txt b/src/main/resources/save/newGame/maps.txt
index 65664ad..f147ff0 100644
--- a/src/main/resources/save/newGame/maps.txt
+++ b/src/main/resources/save/newGame/maps.txt
@@ -3,4 +3,5 @@
<0> office
<0> boss
<0> treasure
-<1> glade
\ No newline at end of file
+<1> glade
+<999> m6
\ No newline at end of file
diff --git a/src/test/java/ruscz/game/gameOfProd/Scripts/PathFinderTest.java b/src/test/java/ruscz/game/gameOfProd/Scripts/PathFinderTest.java
index 40f6088..a6ca281 100644
--- a/src/test/java/ruscz/game/gameOfProd/Scripts/PathFinderTest.java
+++ b/src/test/java/ruscz/game/gameOfProd/Scripts/PathFinderTest.java
@@ -1,8 +1,10 @@
package ruscz.game.gameOfProd.Scripts;
+import org.junit.jupiter.api.Assertions;
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.Npc;
import ruscz.game.gameOfProd.Map.Map;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
@@ -13,34 +15,57 @@ public class PathFinderTest {
public static Stream argumentsStream(){
return Stream.of(
- Arguments.of(1,1,1,1)
-// Arguments.of(),
-// Arguments.of(),
-// Arguments.of(),
-// Arguments.of()
+ Arguments.of(1,1,8,8, true),
+ Arguments.of(4, 7, 6, 1, true),
+ Arguments.of(13, 1, 17, 9, true),
+ Arguments.of(21, 1, 22, 9, true),
+ 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
@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
WindowOfFreeMove freeMove;
+ Map testMap;
+ Npc testNpc;
//Act
freeMove = new WindowOfFreeMove(new JFrame());
freeMove.setVisible(false);
WindowOfFreeMove.setCHAPTER("999");
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
-
-
-
-
+ if (isPossible) {
+ Assertions.assertEquals(endX, testNpc.getX());
+ Assertions.assertEquals(endY, testNpc.getY());
+ }
+ else {
+ Assertions.assertEquals(startX, testNpc.getX());
+ Assertions.assertEquals(startY, testNpc.getY());
+ }
}