aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Week4/src/no.pngbin0 -> 3662 bytes
-rw-r--r--Week4/src/nw.pngbin0 -> 3646 bytes
-rw-r--r--Week4/src/nz.pngbin0 -> 199 bytes
-rw-r--r--Week4/src/nzow.pngbin0 -> 214 bytes
-rw-r--r--Week4/src/oo15loipe/AsciiArt.java2
-rw-r--r--Week4/src/oo15loipe/InfoLoipe.java2
-rw-r--r--Week4/src/oo15loipe/Loipe.java173
-rw-r--r--Week4/src/oo15loipe/LoipePlaatje.java6
-rw-r--r--Week4/src/oo15loipe/Punt.java4
-rw-r--r--Week4/src/ow.pngbin0 -> 3273 bytes
-rw-r--r--Week4/src/week4/Week4.java6
-rw-r--r--Week4/src/zo.pngbin0 -> 3662 bytes
-rw-r--r--Week4/src/zw.pngbin0 -> 3641 bytes
14 files changed, 185 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..14b2b65
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/Week4/nbproject/private/
+/Week4/build/ \ No newline at end of file
diff --git a/Week4/src/no.png b/Week4/src/no.png
new file mode 100644
index 0000000..daaec27
--- /dev/null
+++ b/Week4/src/no.png
Binary files differ
diff --git a/Week4/src/nw.png b/Week4/src/nw.png
new file mode 100644
index 0000000..2699df3
--- /dev/null
+++ b/Week4/src/nw.png
Binary files differ
diff --git a/Week4/src/nz.png b/Week4/src/nz.png
new file mode 100644
index 0000000..c4eeb9c
--- /dev/null
+++ b/Week4/src/nz.png
Binary files differ
diff --git a/Week4/src/nzow.png b/Week4/src/nzow.png
new file mode 100644
index 0000000..96ab874
--- /dev/null
+++ b/Week4/src/nzow.png
Binary files differ
diff --git a/Week4/src/oo15loipe/AsciiArt.java b/Week4/src/oo15loipe/AsciiArt.java
index 07c73c1..3ee3367 100644
--- a/Week4/src/oo15loipe/AsciiArt.java
+++ b/Week4/src/oo15loipe/AsciiArt.java
@@ -28,7 +28,7 @@ public class AsciiArt implements TekenLoipe{
@Override
public void teken(){
for(int i = 0; i < L.getWidth(); i++){
- for(int j = 0; j < L.getHeigth(); j++){
+ for(int j = 0; j < L.getHeight(); j++){
if(i == man.getX() && j == man.getY()){
System.out.print('*');
break;
diff --git a/Week4/src/oo15loipe/InfoLoipe.java b/Week4/src/oo15loipe/InfoLoipe.java
index 9ff318d..1796418 100644
--- a/Week4/src/oo15loipe/InfoLoipe.java
+++ b/Week4/src/oo15loipe/InfoLoipe.java
@@ -11,7 +11,7 @@ package oo15loipe;
*/
public interface InfoLoipe {
public int getWidth( ) ; // grootte in oost􀀀west r i cht ing
- public int getHeigth( ) ; // grootte in noord􀀀zuid r i cht ing
+ public int getHeight( ) ; // grootte in noord􀀀zuid r i cht ing
public Fragment getFragment( int x, int y) ; // fragment van de loipe op po s i t i e (x , y)
public Punt start( ) ; // Het startpunt op de kaart
public Punt stap( ) ; // het volgende punt op de route
diff --git a/Week4/src/oo15loipe/Loipe.java b/Week4/src/oo15loipe/Loipe.java
new file mode 100644
index 0000000..308ac8b
--- /dev/null
+++ b/Week4/src/oo15loipe/Loipe.java
@@ -0,0 +1,173 @@
+/*
+ * 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;
+
+/**
+ * @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;
+
+ private int height = 0, width = 0;
+
+ private Punt start;
+ private Punt[] path;
+ private int path_pointer = 0;
+ private Fragment[][] loipe;
+
+ public Loipe (String pad) {
+
+ // First calculate width and height
+ int direction = DIRECTION_NORTH;
+
+ int maxX = 0, maxY = 0, minX = 0, minY = 0;
+ Punt current_point = new Punt(0,0);
+
+ for (int i = 0; i < pad.length(); i++) {
+ if (current_point.getX() < minX)
+ minX = current_point.getX();
+ if (current_point.getX() > maxX)
+ maxX = current_point.getX();
+ if (current_point.getY() < minY)
+ minY = current_point.getY();
+ if (current_point.getY() > maxY)
+ maxY = current_point.getY();
+
+ switch (pad.charAt(i)) {
+ case 'r':
+ switch (direction) {
+ case DIRECTION_EAST: direction = DIRECTION_SOUTH; break;
+ case DIRECTION_SOUTH: direction = DIRECTION_WEST; break;
+ case DIRECTION_WEST: direction = DIRECTION_NORTH; break;
+ case DIRECTION_NORTH: direction = DIRECTION_EAST; break;
+ }
+ break;
+ case 'l':
+ switch (direction) {
+ case DIRECTION_EAST: direction = DIRECTION_NORTH; break;
+ case DIRECTION_SOUTH: direction = DIRECTION_EAST; break;
+ case DIRECTION_WEST: direction = DIRECTION_SOUTH; break;
+ case DIRECTION_NORTH: direction = DIRECTION_WEST; break;
+ }
+ }
+
+ switch (direction) {
+ case DIRECTION_EAST: current_point = new Punt(current_point.getX() + 1, current_point.getY()); break;
+ case DIRECTION_SOUTH: current_point = new Punt(current_point.getX(), current_point.getY() + 1); break;
+ case DIRECTION_WEST: current_point = new Punt(current_point.getX() - 1, current_point.getY()); break;
+ case DIRECTION_NORTH: current_point = new Punt(current_point.getX(), current_point.getY() - 1); break;
+ }
+
+ System.out.println(pad.charAt(i) + ":" + direction);
+ }
+
+ System.out.println();
+ System.out.println(maxX);
+ System.out.println(minX);
+ System.out.println(maxY);
+ System.out.println(minY);
+
+ height = maxY - minY;
+ width = maxX - minX;
+ start = new Punt(-minX, -minY);
+
+ // Now fill the Loipe
+ loipe = new Fragment[width][height];
+ path = new Punt[pad.length()];
+ current_point = new Punt(-minX, -minY);
+ direction = DIRECTION_NORTH;
+
+ for (int i = 0; i < pad.length(); i++) {
+ path[i] = current_point;
+
+ if (loipe[current_point.getX()][current_point.getY()] == null) {
+ loipe[current_point.getX()][current_point.getY()] = Fragment.KR;
+ } else {
+ switch (pad.charAt(i)) {
+ case 'r':
+ switch (direction) {
+ case DIRECTION_EAST: loipe[current_point.getX()][current_point.getY()] = Fragment.ZW; break;
+ case DIRECTION_SOUTH: loipe[current_point.getX()][current_point.getY()] = Fragment.NW; break;
+ case DIRECTION_WEST: loipe[current_point.getX()][current_point.getY()] = Fragment.NO; break;
+ case DIRECTION_NORTH: loipe[current_point.getX()][current_point.getY()] = Fragment.ZO; break;
+ }
+ break;
+ case 'l':
+ switch (direction) {
+ case DIRECTION_EAST: loipe[current_point.getX()][current_point.getY()] = Fragment.NW; break;
+ case DIRECTION_SOUTH: loipe[current_point.getX()][current_point.getY()] = Fragment.NO; break;
+ 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;
+ }
+ }
+ }
+
+ switch (pad.charAt(i)) {
+ case 'r':
+ switch (direction) {
+ case DIRECTION_EAST: direction = DIRECTION_SOUTH; break;
+ case DIRECTION_SOUTH: direction = DIRECTION_WEST; break;
+ case DIRECTION_WEST: direction = DIRECTION_NORTH; break;
+ case DIRECTION_NORTH: direction = DIRECTION_EAST; break;
+ }
+ break;
+ case 'l':
+ switch (direction) {
+ case DIRECTION_EAST: direction = DIRECTION_NORTH; break;
+ case DIRECTION_SOUTH: direction = DIRECTION_EAST; break;
+ case DIRECTION_WEST: direction = DIRECTION_SOUTH; break;
+ case DIRECTION_NORTH: direction = DIRECTION_WEST; break;
+ }
+ }
+
+ switch (direction) {
+ case DIRECTION_EAST: current_point = new Punt(current_point.getX() + 1, current_point.getY()); break;
+ case DIRECTION_SOUTH: current_point = new Punt(current_point.getX(), current_point.getY() + 1); break;
+ case DIRECTION_WEST: current_point = new Punt(current_point.getX() - 1, current_point.getY()); break;
+ case DIRECTION_NORTH: current_point = new Punt(current_point.getX(), current_point.getY() - 1); break;
+ }
+ }
+ }
+
+ @Override
+ public int getHeight() {
+ return height;
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ for (Punt p : path) {
+ sb.append(p).append(" -> ");
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public Fragment getFragment(int x, int y) {
+ return loipe[x][y];
+ }
+
+ @Override
+ public Punt start() {
+ return start;
+ }
+
+ @Override
+ public Punt stap() {
+ return path[path_pointer++];
+ }
+
+}
diff --git a/Week4/src/oo15loipe/LoipePlaatje.java b/Week4/src/oo15loipe/LoipePlaatje.java
index 3166309..db70d28 100644
--- a/Week4/src/oo15loipe/LoipePlaatje.java
+++ b/Week4/src/oo15loipe/LoipePlaatje.java
@@ -37,13 +37,13 @@ public class LoipePlaatje extends JFrame implements TekenLoipe
/**
* previous position for walking the loipe
*/
- private Point previousPos = null;
+ private Punt previousPos = null;
/**
* Constructor. Fill all icons.
*/
public LoipePlaatje(InfoLoipe s) {
- super("Kaart");
+ super("Loipe");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
nz = plaatje("nz");
ow = plaatje("ow");
@@ -177,7 +177,7 @@ public class LoipePlaatje extends JFrame implements TekenLoipe
}
@Override
- public void setPosition(Point p) {
+ public void setPosition(Punt p) {
Graphics g = panel.getGraphics();
if (previousPos != null) {
g.setColor(SNOW);
diff --git a/Week4/src/oo15loipe/Punt.java b/Week4/src/oo15loipe/Punt.java
index 1939c45..2c94f1f 100644
--- a/Week4/src/oo15loipe/Punt.java
+++ b/Week4/src/oo15loipe/Punt.java
@@ -70,8 +70,4 @@ public class Punt {
public String toString () {
return "(" + x + "," + y + ")";
}
-
- public Punt add(Punt plus) {
- return new Punt(x + plus.getX(), y + plus.getY());
- }
}
diff --git a/Week4/src/ow.png b/Week4/src/ow.png
new file mode 100644
index 0000000..8d35019
--- /dev/null
+++ b/Week4/src/ow.png
Binary files differ
diff --git a/Week4/src/week4/Week4.java b/Week4/src/week4/Week4.java
index 9dadd91..039eddb 100644
--- a/Week4/src/week4/Week4.java
+++ b/Week4/src/week4/Week4.java
@@ -5,6 +5,8 @@
*/
package week4;
+import oo15loipe.Loipe;
+
/**
*
* @author cstaps
@@ -15,7 +17,9 @@ public class Week4 {
* @param args the command line arguments
*/
public static void main(String[] args) {
- // TODO code application logic here
+ Loipe l = new Loipe("ssrrsllrs");
+ System.out.println(l.getWidth() + " x " + l.getHeight());
+ System.out.println(l);
}
}
diff --git a/Week4/src/zo.png b/Week4/src/zo.png
new file mode 100644
index 0000000..1b578c0
--- /dev/null
+++ b/Week4/src/zo.png
Binary files differ
diff --git a/Week4/src/zw.png b/Week4/src/zw.png
new file mode 100644
index 0000000..702e57d
--- /dev/null
+++ b/Week4/src/zw.png
Binary files differ