aboutsummaryrefslogtreecommitdiff
path: root/Week4/src/oo15loipe/Loipe.java
diff options
context:
space:
mode:
authorCamil Staps2015-02-26 17:45:59 +0100
committerCamil Staps2015-02-26 17:45:59 +0100
commit4c555281988424a83b004c06a3f85e60d1c9fc6e (patch)
treefeefe8cba9ae8ebdc3ae063ea7757a06d1cd4e18 /Week4/src/oo15loipe/Loipe.java
parentx (diff)
Finished week 4
Diffstat (limited to 'Week4/src/oo15loipe/Loipe.java')
-rw-r--r--Week4/src/oo15loipe/Loipe.java63
1 files changed, 47 insertions, 16 deletions
diff --git a/Week4/src/oo15loipe/Loipe.java b/Week4/src/oo15loipe/Loipe.java
index 308ac8b..ff034c0 100644
--- a/Week4/src/oo15loipe/Loipe.java
+++ b/Week4/src/oo15loipe/Loipe.java
@@ -1,27 +1,42 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
package oo15loipe;
/**
+ * Loipe class
+ *
* @author Camil Staps, s4498062 // Thijs Heijligenberg, s4451414
*/
public class Loipe implements InfoLoipe {
- private final static int DIRECTION_EAST = 0,
- DIRECTION_SOUTH = 1,
- DIRECTION_WEST = 2,
- DIRECTION_NORTH = 3;
+ /**
+ * Class constants for direction (for readability)
+ */
+ private final static int
+ DIRECTION_EAST = 0,
+ DIRECTION_SOUTH = 1,
+ DIRECTION_WEST = 2,
+ DIRECTION_NORTH = 3;
+ /**
+ * The height and width of the loipe
+ */
private int height = 0, width = 0;
+ /**
+ * Start point
+ * The path in coordinates
+ * The current position
+ * The map as 2D array of Fragments
+ */
private Punt start;
private Punt[] path;
private int path_pointer = 0;
private Fragment[][] loipe;
+ /**
+ * Construct the loipe based on a path
+ *
+ * @param pad
+ */
public Loipe (String pad) {
// First calculate width and height
@@ -74,20 +89,20 @@ public class Loipe implements InfoLoipe {
System.out.println(maxY);
System.out.println(minY);
- height = maxY - minY;
- width = maxX - minX;
+ height = maxY - minY + 1;
+ width = maxX - minX + 1;
start = new Punt(-minX, -minY);
// Now fill the Loipe
- loipe = new Fragment[width][height];
+ loipe = new Fragment[width + 1][height + 1];
path = new Punt[pad.length()];
- current_point = new Punt(-minX, -minY);
+ current_point = start;
direction = DIRECTION_NORTH;
for (int i = 0; i < pad.length(); i++) {
path[i] = current_point;
- if (loipe[current_point.getX()][current_point.getY()] == null) {
+ if (loipe[current_point.getX()][current_point.getY()] != null) {
loipe[current_point.getX()][current_point.getY()] = Fragment.KR;
} else {
switch (pad.charAt(i)) {
@@ -106,6 +121,17 @@ public class Loipe implements InfoLoipe {
case DIRECTION_WEST: loipe[current_point.getX()][current_point.getY()] = Fragment.ZO; break;
case DIRECTION_NORTH: loipe[current_point.getX()][current_point.getY()] = Fragment.ZW; break;
}
+ break;
+ case 's':
+ switch (direction) {
+ case DIRECTION_EAST:
+ case DIRECTION_WEST:
+ loipe[current_point.getX()][current_point.getY()] = Fragment.OW;
+ break;
+ case DIRECTION_SOUTH:
+ case DIRECTION_NORTH:
+ loipe[current_point.getX()][current_point.getY()] = Fragment.NZ;
+ }
}
}
@@ -159,7 +185,7 @@ public class Loipe implements InfoLoipe {
public Fragment getFragment(int x, int y) {
return loipe[x][y];
}
-
+
@Override
public Punt start() {
return start;
@@ -167,7 +193,12 @@ public class Loipe implements InfoLoipe {
@Override
public Punt stap() {
- return path[path_pointer++];
+ if (path_pointer >= path.length) {
+ path_pointer = 0;
+ }
+ Punt result = path[path_pointer];
+ path_pointer++;
+ return result;
}
}