aboutsummaryrefslogtreecommitdiff
path: root/Week4/src
diff options
context:
space:
mode:
authorCamil Staps2015-04-18 13:44:44 +0200
committerCamil Staps2015-04-18 13:44:44 +0200
commit6a44b074f0169a1b0f9e92347af929c5e471746e (patch)
treeae5663fe7c69881bf4ecfedbef99c2505f8ec964 /Week4/src
parentAdded copyright to docs (diff)
Reorganised projects
Diffstat (limited to 'Week4/src')
-rw-r--r--Week4/src/no.pngbin3662 -> 0 bytes
-rw-r--r--Week4/src/nw.pngbin3646 -> 0 bytes
-rw-r--r--Week4/src/nz.pngbin199 -> 0 bytes
-rw-r--r--Week4/src/nzow.pngbin214 -> 0 bytes
-rw-r--r--Week4/src/oo15loipe/AsciiArt.java51
-rw-r--r--Week4/src/oo15loipe/Fragment.java8
-rw-r--r--Week4/src/oo15loipe/InfoLoipe.java35
-rw-r--r--Week4/src/oo15loipe/Loipe.java226
-rw-r--r--Week4/src/oo15loipe/LoipePlaatje.java191
-rw-r--r--Week4/src/oo15loipe/Punt.java73
-rw-r--r--Week4/src/oo15loipe/TekenLoipe.java19
-rw-r--r--Week4/src/ow.pngbin3273 -> 0 bytes
-rw-r--r--Week4/src/week4/Week4.java36
-rw-r--r--Week4/src/zo.pngbin3662 -> 0 bytes
-rw-r--r--Week4/src/zw.pngbin3641 -> 0 bytes
15 files changed, 0 insertions, 639 deletions
diff --git a/Week4/src/no.png b/Week4/src/no.png
deleted file mode 100644
index daaec27..0000000
--- a/Week4/src/no.png
+++ /dev/null
Binary files differ
diff --git a/Week4/src/nw.png b/Week4/src/nw.png
deleted file mode 100644
index 2699df3..0000000
--- a/Week4/src/nw.png
+++ /dev/null
Binary files differ
diff --git a/Week4/src/nz.png b/Week4/src/nz.png
deleted file mode 100644
index c4eeb9c..0000000
--- a/Week4/src/nz.png
+++ /dev/null
Binary files differ
diff --git a/Week4/src/nzow.png b/Week4/src/nzow.png
deleted file mode 100644
index 96ab874..0000000
--- a/Week4/src/nzow.png
+++ /dev/null
Binary files differ
diff --git a/Week4/src/oo15loipe/AsciiArt.java b/Week4/src/oo15loipe/AsciiArt.java
deleted file mode 100644
index 4072d54..0000000
--- a/Week4/src/oo15loipe/AsciiArt.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package oo15loipe;
-
-/**
- * A class that draws the loipe as ascii-art.
- *
- * @author Thijs Heijligenberg, s4451414, Camil Staps, s4498062
- */
-public class AsciiArt implements TekenLoipe{
- private InfoLoipe L;
- private Punt man;
-
- /**
- * Create the instance based on a loipe
- *
- * @param s
- */
- public AsciiArt(InfoLoipe s){
- this.L = s;
- this.man = new Punt(null);
- }
-
- @Override
- public void setPosition(Punt p){
- this.man = p;
- }
-
- @Override
- public void teken(){
- for(int j = 0; j < L.getHeight(); j++){
- for(int i = 0; i < L.getWidth(); i++){
- Fragment f = L.getFragment(i,j);
- if(i == man.getX() && j == man.getY()){
- System.out.print('*');
- } else if (f == null) {
- System.out.print(' ');
- } else {
- switch (f){
- case KR: System.out.print('+'); break;
- case NZ: System.out.print('|'); break;
- case OW: System.out.print('-'); break;
- case NO: System.out.print('`'); break;
- case NW: System.out.print(','); break;
- case ZO: System.out.print(','); break;
- case ZW: System.out.print('.'); break;
- }
- }
- }
- System.out.print("\n");
- }
- }
-}
diff --git a/Week4/src/oo15loipe/Fragment.java b/Week4/src/oo15loipe/Fragment.java
deleted file mode 100644
index a4668da..0000000
--- a/Week4/src/oo15loipe/Fragment.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package oo15loipe;
-
-/**
- * enum to describe a fragment of path by its direction (or as a crossing)
- *
- * @author Thijs Heijligenberg, s4451414, Camil Staps, s4498062
- */
-public enum Fragment {NZ, OW, NO,NW, ZO, ZW, KR};
diff --git a/Week4/src/oo15loipe/InfoLoipe.java b/Week4/src/oo15loipe/InfoLoipe.java
deleted file mode 100644
index a1cf182..0000000
--- a/Week4/src/oo15loipe/InfoLoipe.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package oo15loipe;
-
-/**
- * Interface for a class describing a Loipe
- *
- * @author Camil Staps, s4498062, Thijs Heijligenberg, s4451414
- */
-public interface InfoLoipe {
-
- public int getWidth( ) ; // grootte in oost􀀀west r i cht ing
- public int getHeight( ) ; // grootte in noord􀀀zuid r i cht ing
-
- /**
- * Get the fragment at position (x, y)
- *
- * @param x
- * @param y
- * @return
- */
- public Fragment getFragment( int x, int y) ; // fragment van de loipe op po s i t i e (x , y)
-
- /**
- * Get the first position of the loipe
- *
- * @return
- */
- public Punt start( ) ; // Het startpunt op de kaart
-
- /**
- * Get the next position in the loipe
- * @return
- */
- public Punt stap( ) ; // het volgende punt op de route
-}
-
diff --git a/Week4/src/oo15loipe/Loipe.java b/Week4/src/oo15loipe/Loipe.java
deleted file mode 100644
index 9155988..0000000
--- a/Week4/src/oo15loipe/Loipe.java
+++ /dev/null
@@ -1,226 +0,0 @@
-package oo15loipe;
-
-/**
- * Loipe class
- *
- * @author Camil Staps, s4498062 // Thijs Heijligenberg, s4451414
- */
-public class Loipe implements InfoLoipe {
-
- /**
- * 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) {
- setLoipe(pad);
- }
-
- /**
- * Refresh everything based on a new path
- *
- * @param pad
- */
- public final void setLoipe(String pad) {
- setWidthAndHeight(pad);
- fillLoipe(pad);
-
- path_pointer = 0;
- }
-
- /**
- * Set the width and height of the loipe based on a path
- *
- * @param pad
- */
- private void setWidthAndHeight(String pad) {
- 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;
- }
- }
-
- height = maxY - minY + 1;
- width = maxX - minX + 1;
-
- start = new Punt(-minX, -minY);
- }
-
- /**
- * Fill the loipe with fragments based on a path.
- * Assumes the width, height and start attributes to be correct.
- *
- * @param pad
- */
- private void fillLoipe(String pad) {
- loipe = new Fragment[width + 1][height + 1];
- path = new Punt[pad.length()];
- Punt current_point = start;
- int 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;
- }
- 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;
- }
- }
- }
-
- 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;
- }
-
- /**
- * We chose to have the man go back to the start when he has finished the loipe.
- */
- @Override
- public Punt stap() {
- if (path_pointer >= path.length) {
- path_pointer = 0;
- }
- Punt result = path[path_pointer];
- path_pointer++;
- return result;
- }
-
-}
diff --git a/Week4/src/oo15loipe/LoipePlaatje.java b/Week4/src/oo15loipe/LoipePlaatje.java
deleted file mode 100644
index db70d28..0000000
--- a/Week4/src/oo15loipe/LoipePlaatje.java
+++ /dev/null
@@ -1,191 +0,0 @@
-package oo15loipe;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.net.URL;
-import javax.swing.ImageIcon;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-
-/**
- *
- * @author Pieter Koopman
- */
-public class LoipePlaatje extends JFrame implements TekenLoipe
-{
- /** Used for painting the tiles.
- * We assume that all tiles have same width and height.
- */
- private final int UNIT;
-
- /** Color for painting the background. */
- private static final Color SNOW = new Color(0xF0,0xF0,0xFF);
-
- /**
- * The icons for drawing
- */
- private final ImageIcon nz, ow, no, nw, zo, zw, nzow;
-
- private JPanel panel;
-
- /**
- * the loipe to be painted and a boolean indicating whether it is okay
- */
- private InfoLoipe loipe;
- private boolean loipeOK = true;
- /**
- * previous position for walking the loipe
- */
- private Punt previousPos = null;
-
- /**
- * Constructor. Fill all icons.
- */
- public LoipePlaatje(InfoLoipe s) {
- super("Loipe");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- nz = plaatje("nz");
- ow = plaatje("ow");
- no = plaatje("no");
- nw = plaatje("nw");
- zo = plaatje("zo");
- zw = plaatje("zw");
- nzow = plaatje("nzow");
- UNIT = nz.getIconWidth();
- setLoipe(s);
- if (loipeOK) {
- panel = new JPanel();
- add(panel);
- }
- }
-
- /**
- * Creates a LoipePlaatje object based on the track information in <code>Loipe</code>.
- * @param s this Loipe contains the 2D track information
- */
- public void setLoipe (InfoLoipe s) {
- loipe = s;
- checkLoipe();
- setBackground(SNOW);
- }
-
- /**
- * Checks validity of the input track description. Terminates normally
- * when the track is valid, prints a message otherwise.
- */
- private void checkLoipe() {
- if (loipe == null)
- {
- System.err.println("Illegale loipe: null pointer");
- loipeOK = false;
- }
- else if (loipe.getHeight() == 0)
- {
- System.err.println("Illegale loipe: height should be at least 1");
- loipeOK = false;
- }
- else if (loipe.getWidth() == 0)
- {
- System.err.println("Illegale loipe: width should be at least 1");
- loipeOK = false;
- }
- }
- /**
- * Gets the preferred size of this component.
- *
- * @return a dimension object indicating this component's preferred size.
- */
- @Override
- public Dimension getPreferredSize() {
- return new Dimension(loipe.getWidth() * UNIT, loipe.getHeight() * UNIT);
- }
-
- /**
- * try to read a picture with the given name
- * @param naam "name.png" is filename of picture
- * @return the picture
- * @throws IllegalArgumentexception if file is not found
- */
- private ImageIcon plaatje (String name) {
- name += ".png";
- URL resource = getClass().getClassLoader().getResource(name);
- if (resource != null) {
- return new ImageIcon (resource);
- } else {
- System.err.printf ("ERROR: Resource \"%s\" not found... aborting...\n", name);
- System.err.println("For NetBeans the file should be placed in the src folder.");
- throw new IllegalArgumentException ("Image " + name + " not found!");
- }
- }
-
- /**
- * Update graphics according to stored track.
- * @param g the graphics context to use for painting.
- */
- @Override
- public void paint(Graphics g) {
- super.paint(g);
- g = panel.getGraphics();
- for (int i = 0; i < loipe.getWidth(); i += 1) {
- for (int j = 0; j < loipe.getHeight(); j += 1) {
- tekenFragment(g, i, j);
- }
- }
- if (previousPos != null) {
- g.setColor(Color.RED);
- g.fillOval(previousPos.getX() * UNIT + UNIT / 4, previousPos.getY() * UNIT + UNIT / 4, UNIT / 2, UNIT / 2);
- }
- }
-
- /**
- * Draw the fragment from the loipe at the given position
- * @param g
- * @param x
- * @param y
- */
- private void tekenFragment(Graphics g, int x, int y) {
- Fragment f = loipe.getFragment(x, y);
- ImageIcon plaatje;
- if (f != null) {
- switch (f) {
- case NZ: plaatje = nz; break;
- case OW: plaatje = ow; break;
- case NO: plaatje = no; break;
- case NW: plaatje = nw; break;
- case ZO: plaatje = zo; break;
- case ZW: plaatje = zw; break;
- default: plaatje = nzow;
- }
- if (plaatje != null) {
- plaatje.paintIcon(this, g, x * UNIT, y * UNIT);
- }
- }
- }
- /**
- * The method to call in order to draw a window with the given track.
- * You are supposed to use this method once for each object.
- */
- @Override
- public void teken() {
- if (loipeOK) {
- setSize(loipe.getWidth() * UNIT, loipe.getHeight() * UNIT + UNIT / 2);
- setVisible(true); // make frame visible
- }
- else
- System.err.println("LoipePlaatje kan niet tekenen. Loipe is ongeldig of plaatjes niet gevonden");
- }
-
- @Override
- public void setPosition(Punt p) {
- Graphics g = panel.getGraphics();
- if (previousPos != null) {
- g.setColor(SNOW);
- g.fillRect(previousPos.getX() * UNIT, previousPos.getY() * UNIT, UNIT, UNIT);
- tekenFragment(g,previousPos.getX(), previousPos.getY());
- }
- g.setColor(Color.RED);
- g.fillOval(p.getX() * UNIT + UNIT / 4, p.getY() * UNIT + UNIT / 4, UNIT / 2, UNIT / 2);
- previousPos = p;
- }
-} \ No newline at end of file
diff --git a/Week4/src/oo15loipe/Punt.java b/Week4/src/oo15loipe/Punt.java
deleted file mode 100644
index 2c94f1f..0000000
--- a/Week4/src/oo15loipe/Punt.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package oo15loipe;
-
-/**
- * Een Punt in 2D
- * @author pieter koopman
- */
-
-public class Punt {
- private int x, y;
-
- /**
- * de gewone constructor
- * @param i: x
- * @param j; y
- */
- public Punt(int i, int j) {
- x = i;
- y = j;
- }
-
- /**
- * copy constructor
- * @param p
- */
- public Punt (Punt p) {
- if (p != null) {
- x = p.x;
- y = p.y;
- } else {
- x = y = 0;
- }
- }
-
- /**
- * getter voor x
- * @return x
- */
- public int getX (){
- return x;
- }
-
- /**
- * getter voor y
- * @return y
- */
- public int getY (){
- return y;
- }
-
- /**
- * equals methode vergelijkt x en y
- * @param o
- * @return
- */
- @Override
- public boolean equals(Object o) {
- if (o != null && o instanceof Punt) {
- Punt p = (Punt) o;
- return x == p.x && y == p.y;
- } else {
- return false;
- }
- }
-
- /**
- * Punt naar String conversie
- * @return Strin met waarde van x en y
- */
- @Override
- public String toString () {
- return "(" + x + "," + y + ")";
- }
-}
diff --git a/Week4/src/oo15loipe/TekenLoipe.java b/Week4/src/oo15loipe/TekenLoipe.java
deleted file mode 100644
index 8c9386f..0000000
--- a/Week4/src/oo15loipe/TekenLoipe.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package oo15loipe;
-
-/**
- * Interface for a class that can show a loipe on the screen
- *
- * @author Thijs Heijligenberg s4451414, Camil Staps, s4498062
- */
-public interface TekenLoipe {
- /**
- * Draw the loipe
- */
- public void teken() ; // teken de gegeven loipe
-
- /**
- * Set the current position of the skier
- * @param p
- */
- public void setPosition(Punt p) ; // teken de spor ter op de gegeven po s i t i e
-}
diff --git a/Week4/src/ow.png b/Week4/src/ow.png
deleted file mode 100644
index 8d35019..0000000
--- a/Week4/src/ow.png
+++ /dev/null
Binary files differ
diff --git a/Week4/src/week4/Week4.java b/Week4/src/week4/Week4.java
deleted file mode 100644
index e523a54..0000000
--- a/Week4/src/week4/Week4.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package week4;
-
-import java.util.Scanner;
-import oo15loipe.AsciiArt;
-import oo15loipe.Loipe;
-import oo15loipe.LoipePlaatje;
-
-/**
- * Solutions for assignment 4
- *
- * @author Thijs Heijligenberg, s4451414, Camil Staps, s4498062
- */
-public class Week4 {
-
- /**
- * Create a Loipe, draw it using LoipePlaatje and AsciiArt
- *
- * @param args the command line arguments (are ignored)
- */
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
-
- Loipe l = new Loipe("srssrsslsllsss");
-
- LoipePlaatje lp = new LoipePlaatje(l);
- lp.teken();
-
- AsciiArt aa = new AsciiArt(l);
- do {
- aa.setPosition(l.stap());
- aa.teken();
- } while (sc.nextLine() != null);
-
- }
-
-}
diff --git a/Week4/src/zo.png b/Week4/src/zo.png
deleted file mode 100644
index 1b578c0..0000000
--- a/Week4/src/zo.png
+++ /dev/null
Binary files differ
diff --git a/Week4/src/zw.png b/Week4/src/zw.png
deleted file mode 100644
index 702e57d..0000000
--- a/Week4/src/zw.png
+++ /dev/null
Binary files differ