aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam NAILI2018-01-14 16:44:18 +0100
committerAdam NAILI2018-01-14 16:44:18 +0100
commit183f064766a02448423f5338ed1f2e696be872f7 (patch)
tree9eb4bd418819cfee5cfcac38ec97fa1b08438a23 /src
parent532b0b39e4468baaeb5c79defd76eee447d58bc9 (diff)
parenta494bba689e1a95dd17287287c6394cb7a0cb7ef (diff)
downloadwallj-183f064766a02448423f5338ed1f2e696be872f7.tar.gz
Merge branch 'master' of https://github.com/pacien/upem-java-wallj
Diffstat (limited to 'src')
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/PathFinder.java9
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/TileVec2.java15
-rw-r--r--src/main/java/fr/umlv/java/wallj/model/Stage.java6
3 files changed, 23 insertions, 7 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/board/PathFinder.java b/src/main/java/fr/umlv/java/wallj/board/PathFinder.java
index 9c509f3..8dbab2d 100644
--- a/src/main/java/fr/umlv/java/wallj/board/PathFinder.java
+++ b/src/main/java/fr/umlv/java/wallj/board/PathFinder.java
@@ -12,11 +12,6 @@ import java.util.stream.Collectors;
12public class PathFinder { 12public class PathFinder {
13 13
14 private static final int LEAP_COST = 1; 14 private static final int LEAP_COST = 1;
15 private static final List<TileVec2> NEIGHBOR_OFFSETS = Arrays.asList(
16 TileVec2.of(0, -1),
17 TileVec2.of(-1, 0),
18 TileVec2.of(0, 1),
19 TileVec2.of(1, 0));
20 15
21 private static class Node<T> { 16 private static class Node<T> {
22 final T val; 17 final T val;
@@ -99,8 +94,8 @@ public class PathFinder {
99 .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); 94 .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
100 95
101 for (Node<TileVec2> node : map.values()) 96 for (Node<TileVec2> node : map.values())
102 NEIGHBOR_OFFSETS.stream() 97 node.val.neighbors().stream()
103 .map(offsetVector -> map.get(node.val.add(offsetVector))) 98 .map(map::get)
104 .filter(Objects::nonNull) 99 .filter(Objects::nonNull)
105 .forEach(neighbor -> node.neighbors.put(neighbor, LEAP_COST)); 100 .forEach(neighbor -> node.neighbors.put(neighbor, LEAP_COST));
106 101
diff --git a/src/main/java/fr/umlv/java/wallj/board/TileVec2.java b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java
index 4e8fa55..1d95690 100644
--- a/src/main/java/fr/umlv/java/wallj/board/TileVec2.java
+++ b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java
@@ -2,7 +2,10 @@ package fr.umlv.java.wallj.board;
2 2
3import org.jbox2d.common.Vec2; 3import org.jbox2d.common.Vec2;
4 4
5import java.util.Arrays;
6import java.util.List;
5import java.util.Objects; 7import java.util.Objects;
8import java.util.stream.Collectors;
6 9
7/** 10/**
8 * A typed immutable tile coordinate vector containing the coordinates of a Tile in a Board. 11 * A typed immutable tile coordinate vector containing the coordinates of a Tile in a Board.
@@ -12,6 +15,11 @@ import java.util.Objects;
12public final class TileVec2 { 15public final class TileVec2 {
13 16
14 public static final int TILE_DIM = 20; 17 public static final int TILE_DIM = 20;
18 private static final List<TileVec2> NEIGHBOR_OFFSETS = Arrays.asList(
19 of(0, -1),
20 of(-1, 0),
21 of(0, 1),
22 of(1, 0));
15 23
16 /** 24 /**
17 * @param col the column 25 * @param col the column
@@ -62,6 +70,13 @@ public final class TileVec2 {
62 return TileVec2.of(col + v.col, row + v.row); 70 return TileVec2.of(col + v.col, row + v.row);
63 } 71 }
64 72
73 /**
74 * @return a list of the surrounding direct neighbours of this tile
75 */
76 public List<TileVec2> neighbors() {
77 return NEIGHBOR_OFFSETS.stream().map(this::add).collect(Collectors.toList());
78 }
79
65 @Override 80 @Override
66 public boolean equals(Object o) { 81 public boolean equals(Object o) {
67 if (this == o) return true; 82 if (this == o) return true;
diff --git a/src/main/java/fr/umlv/java/wallj/model/Stage.java b/src/main/java/fr/umlv/java/wallj/model/Stage.java
index b66a7ca..4233326 100644
--- a/src/main/java/fr/umlv/java/wallj/model/Stage.java
+++ b/src/main/java/fr/umlv/java/wallj/model/Stage.java
@@ -31,6 +31,12 @@ public class Stage {
31 */ 31 */
32 public List<Event> update(Context context) { 32 public List<Event> update(Context context) {
33 //TODO 33 //TODO
34 return null;
35 }
36
37 public boolean isCleared() {
38 // TODO
39 return false;
34 } 40 }
35 41
36} 42}