diff --git a/.classpath b/.classpath
new file mode 100644
index 00000000..fa8f52ed
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/design_patterns/horses/Class Diagram.pdf b/src/design_patterns/horses/Class Diagram.pdf
new file mode 100644
index 00000000..a6d5e670
Binary files /dev/null and b/src/design_patterns/horses/Class Diagram.pdf differ
diff --git a/src/design_patterns/horses/EarlySprinter.java b/src/design_patterns/horses/EarlySprinter.java
new file mode 100644
index 00000000..45123d51
--- /dev/null
+++ b/src/design_patterns/horses/EarlySprinter.java
@@ -0,0 +1,35 @@
+package design_patterns.horses;
+
+
+public class EarlySprinter extends Horse{
+
+ public double speed;
+ public double reducedSpeed;
+
+ public EarlySprinter(String n, double s) {
+ name = n;
+ speed = s;
+ reducedSpeed = s*.75;
+ }
+
+ @Override
+ public void run() {
+ if (position < 10) {
+ if (position >= 2) {
+ speed = reducedSpeed;
+ }
+
+ position = position + speed*timeIncr;
+ }else {
+ finished = true;
+ }
+ }
+
+ public void display() {
+ if (!finished) {
+ System.out.println(name + " has run " + position + " miles.");
+ }else {
+ System.out.println(name + " has finished.");
+ }
+ }
+}
diff --git a/src/design_patterns/horses/Horse.java b/src/design_patterns/horses/Horse.java
new file mode 100644
index 00000000..35fd62d0
--- /dev/null
+++ b/src/design_patterns/horses/Horse.java
@@ -0,0 +1,21 @@
+package design_patterns.horses;
+
+public class Horse {
+
+ public String name;
+ public double timeIncr = .04;
+ public double position = 0;
+ public boolean finished = false;
+ public double speed;
+ public double reducedSpeed = 0;
+
+ public Horse(){
+ }
+
+ public void run(){
+ }
+
+ public void display() {
+ }
+
+}
diff --git a/src/design_patterns/horses/Main.java b/src/design_patterns/horses/Main.java
new file mode 100644
index 00000000..ebc1bde5
--- /dev/null
+++ b/src/design_patterns/horses/Main.java
@@ -0,0 +1,15 @@
+package design_patterns.horses;
+
+public class Main {
+
+ public static void main(String[] args) throws InterruptedException {
+ Race race1 = new Race();
+ race1.enrollHorse("Joe", 43, "steady");
+ race1.enrollHorse("Kendall", 46, "slow");
+ race1.enrollHorse("Fisher", 45, "early");
+ race1.enrollHorse("Sharley", 42, "slow");
+ race1.enrollHorse("Julius", 41, "steady");
+ race1.startRace();
+ }
+
+}
diff --git a/src/design_patterns/horses/Race.java b/src/design_patterns/horses/Race.java
new file mode 100644
index 00000000..8f8ea4ca
--- /dev/null
+++ b/src/design_patterns/horses/Race.java
@@ -0,0 +1,46 @@
+package design_patterns.horses;
+
+public class Race {
+ public Horse[] arr = new Horse[5];
+ public int horseNum = 0;
+
+ public void enrollHorse(String n, double s, String t) {
+
+ if(t == "steady") {
+ arr[horseNum] = new SteadyRunner(n, s);
+ }else if (t == "slow") {
+ arr[horseNum] = new SlowStarter(n, s);
+ }else {
+ arr[horseNum] = new EarlySprinter(n, s);
+ }
+ horseNum++;
+
+ }
+
+ public Race(){
+ }
+
+ public void startRace() throws InterruptedException{
+ while (!arr[0].finished && !arr[1].finished && !arr[2].finished && !arr[3].finished && !arr[4].finished) {
+ for (int i = 0; i < 5; i++) {
+ arr[i].run();
+ }
+ for (int i = 0; i < 5; i++) {
+ arr[i].display();
+ }
+ if (arr[0].finished) {
+ System.out.println(arr[0].name + " HAS WON!");
+ }else if(arr[1].finished) {
+ System.out.println(arr[1].name + " HAS WON!");
+ }else if(arr[2].finished) {
+ System.out.println(arr[2].name + " HAS WON!");
+ }else if(arr[3].finished) {
+ System.out.println(arr[3].name + " HAS WON!");
+ }else if(arr[4].finished) {
+ System.out.println(arr[4].name + " HAS WON!");
+ }
+ Thread.sleep(500);
+ }
+ }
+
+}
diff --git a/src/design_patterns/horses/RaceTest2.java b/src/design_patterns/horses/RaceTest2.java
new file mode 100644
index 00000000..9521817c
--- /dev/null
+++ b/src/design_patterns/horses/RaceTest2.java
@@ -0,0 +1,14 @@
+package design_patterns.horses;
+import org.junit.Test;
+
+public class RaceTest2 {
+ @Test
+ public void test() throws InterruptedException {
+ Horse test1 = new SteadyRunner(null, 0);
+ test1.run();
+ Horse test2 = new SlowStarter(null, 0);
+ test2.run();
+ Horse test3 = new EarlySprinter(null, 0);
+ test3.run();
+ }
+}
\ No newline at end of file
diff --git a/src/design_patterns/horses/RaceTest3.java b/src/design_patterns/horses/RaceTest3.java
new file mode 100644
index 00000000..c9e2e991
--- /dev/null
+++ b/src/design_patterns/horses/RaceTest3.java
@@ -0,0 +1,14 @@
+package design_patterns.horses;
+import org.junit.Test;
+
+public class RaceTest3 {
+ @Test
+ public void test() throws InterruptedException {
+ Horse test1 = new SteadyRunner(null, 0);
+ test1.display();
+ Horse test2 = new SlowStarter(null, 0);
+ test2.display();
+ Horse test3 = new EarlySprinter(null, 0);
+ test3.display();
+ }
+}
\ No newline at end of file
diff --git a/src/design_patterns/horses/ReaceTest.java b/src/design_patterns/horses/ReaceTest.java
new file mode 100644
index 00000000..80a8d0c5
--- /dev/null
+++ b/src/design_patterns/horses/ReaceTest.java
@@ -0,0 +1,15 @@
+package design_patterns.horses;
+
+import org.junit.Test;
+
+public class ReaceTest {
+ @Test
+ public void test() throws InterruptedException {
+ Race race1 = new Race();
+ race1.enrollHorse("Jimmy", 43, "steady");
+ race1.enrollHorse("Klien", 46, "slow");
+ race1.enrollHorse("Dabo", 45, "early");
+ race1.enrollHorse("Sheen", 42, "slow");
+ race1.enrollHorse("Biscuit", 41, "steady");
+ }
+}
diff --git a/src/design_patterns/horses/Reflection b/src/design_patterns/horses/Reflection
new file mode 100644
index 00000000..8a609083
--- /dev/null
+++ b/src/design_patterns/horses/Reflection
@@ -0,0 +1,17 @@
+Elijah Hager
+9/9/2018
+
+ Horse Race
+
+ I used a Race class sort of as a base/main class in my project. This included a
+enrollHorse method which allowed me to enroll 5 horses in the race and choose their strategy.
+This was done with a array of the Horse objects. Then in a startRace method, the respective runs
+and displays were running until one of them was finished in which cased it outputted the winner.
+So, in the Horse class, all the universal variables for the horse were initialized, things
+like position, name, speed etc. these would later be altered in their own strategy classes.
+All the strategy classes were created as extensions from the Horse class. This was done so
+they could alter and use the variables associated with the horse such as speed. In each strategy
+the horses speed is updated when it should be, and the horse’s position is incremented based off
+the updated speed, this is done until the horse passes 10 miles. I tinkered with what the type
+of the strategies for hours figuring out ways to make them able to alter the horse’s values but
+still be changeable outside the constructor, and this was the best solution I could come up with.
diff --git a/src/design_patterns/horses/SlowStarter.java b/src/design_patterns/horses/SlowStarter.java
new file mode 100644
index 00000000..51d03c12
--- /dev/null
+++ b/src/design_patterns/horses/SlowStarter.java
@@ -0,0 +1,44 @@
+package design_patterns.horses;
+
+
+
+public class SlowStarter extends Horse{
+
+ public double speed;
+ public double nonReducedSpeed;
+ public double reducedSpeed;
+ public double reducedSpeed_2;
+
+ public SlowStarter(String n, double s) {
+ name = n;
+ nonReducedSpeed = s;
+ reducedSpeed = s*.90;
+ reducedSpeed_2 = s*.75;
+ }
+
+ @Override
+ public void run() {
+ if (position < 10) {
+ if (position <= 6) {
+ speed = reducedSpeed_2;
+ }else if (position > 6 && position < 9) {
+ speed = reducedSpeed;
+ }else {
+ speed = nonReducedSpeed;
+ }
+
+ position = position + speed*timeIncr;
+ }else {
+ finished = true;
+ }
+ }
+
+ public void display() {
+ if (!finished) {
+ System.out.println(name + " has run " + position + " miles.");
+ }else {
+ System.out.println(name + " has finished.");
+ }
+
+ }
+}
diff --git a/src/design_patterns/horses/SteadyRunner.java b/src/design_patterns/horses/SteadyRunner.java
new file mode 100644
index 00000000..5360f139
--- /dev/null
+++ b/src/design_patterns/horses/SteadyRunner.java
@@ -0,0 +1,29 @@
+package design_patterns.horses;
+
+public class SteadyRunner extends Horse{
+
+ public double speed;
+
+ public SteadyRunner(String n, double s) {
+ name = n;
+ speed = s*.8;
+ }
+
+ @Override
+ public void run() {
+ if (position < 10) {
+ position = position + speed*timeIncr;
+ }else {
+ finished = true;
+ }
+ }
+
+ public void display() {
+ if (!finished) {
+ System.out.println(name + " has run " + position + " miles.");
+ }else {
+ System.out.println(name + " has finished.");
+ }
+ }
+
+}
diff --git a/src/design_patterns/horses/package-info.java b/src/design_patterns/horses/package-info.java
new file mode 100644
index 00000000..4103e527
--- /dev/null
+++ b/src/design_patterns/horses/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author elija
+ *
+ */
+package design_patterns.horses;
\ No newline at end of file
diff --git a/src/edu/nd/sarec/railwaycrossing/Railway Reflection.docx b/src/edu/nd/sarec/railwaycrossing/Railway Reflection.docx
new file mode 100644
index 00000000..ec8d557e
Binary files /dev/null and b/src/edu/nd/sarec/railwaycrossing/Railway Reflection.docx differ
diff --git a/src/edu/nd/sarec/railwaycrossing/Railway UML.pdf b/src/edu/nd/sarec/railwaycrossing/Railway UML.pdf
new file mode 100644
index 00000000..7f57c86e
Binary files /dev/null and b/src/edu/nd/sarec/railwaycrossing/Railway UML.pdf differ
diff --git a/src/edu/nd/sarec/railwaycrossing/Simulation.java b/src/edu/nd/sarec/railwaycrossing/Simulation.java
index 0bf1deff..fdabc46e 100644
--- a/src/edu/nd/sarec/railwaycrossing/Simulation.java
+++ b/src/edu/nd/sarec/railwaycrossing/Simulation.java
@@ -9,6 +9,7 @@
import edu.nd.sarec.railwaycrossing.model.infrastructure.gate.CrossingGate;
import edu.nd.sarec.railwaycrossing.model.vehicles.Car;
import edu.nd.sarec.railwaycrossing.model.vehicles.Train;
+import edu.nd.sarec.railwaycrossing.model.vehicles.Train2;
import edu.nd.sarec.railwaycrossing.view.MapDisplay;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
@@ -42,12 +43,16 @@ public void start(Stage stage) throws Exception {
// Train
RailwayTracks track = mapBuilder.getTrack("Royal");
+ RailwayTracks track2 = mapBuilder.getTrack("Magenta");
Train train = new Train(track.getEndX()+100,track.getEndY()-25);
+ Train2 train2 = new Train2(track2.getStartX()-100,track2.getStartY()-25);
root.getChildren().add(train.getImageView());
+ root.getChildren().add(train2.getImageView());
- for(CrossingGate gate: mapBuilder.getAllGates())
- train.addObserver(gate);
-
+ train.addObserver(mapBuilder.getGate("Gate1"));
+ train.addObserver(mapBuilder.getGate("Gate2"));
+ train2.addObserver(mapBuilder.getGate("Gate3"));
+ train2.addObserver(mapBuilder.getGate("Gate4"));
// Sets up a repetitive loop i.e., in handle that runs the actual simulation
new AnimationTimer(){
@@ -56,14 +61,17 @@ public void handle(long now) {
createCar();
train.move();
+ train2.move();
for(CrossingGate gate: mapBuilder.getAllGates())
gate.operateGate();
if (train.offScreen())
train.reset();
-
- clearCars();
+ if (train2.offScreen())
+ train2.reset();
+
+ clearCars();
}
}.start();
}
diff --git a/src/edu/nd/sarec/railwaycrossing/model/infrastructure/MapBuilder.java b/src/edu/nd/sarec/railwaycrossing/model/infrastructure/MapBuilder.java
index 267ae8e1..016c2c3a 100644
--- a/src/edu/nd/sarec/railwaycrossing/model/infrastructure/MapBuilder.java
+++ b/src/edu/nd/sarec/railwaycrossing/model/infrastructure/MapBuilder.java
@@ -30,21 +30,26 @@ public MapBuilder(){
private void buildRoads(){
roads.put("Western Highway",new Road(new Point(800,0),new Point (800,1000),Direction.SOUTH,true,false));
roads.put("Skyway",new Road(new Point(400,0),new Point (400,1000),Direction.SOUTH,true,false));
- roads.put("EastWest",new Road(new Point(415,800),new Point (785,800),Direction.EAST,true,true));
+ roads.put("EastWest",new Road(new Point(415,630),new Point (785,630),Direction.EAST,true,true));
}
private void buildCrossingGates(){
- gates.put("Gate1", new CrossingGate(780,480, "Gate1"));
- gates.put("Gate2", new CrossingGate(380,480, "Gate2"));
+ gates.put("Gate1", new CrossingGate(780,340, "Gate1"));
+ gates.put("Gate2", new CrossingGate(380,340, "Gate2"));
+ gates.put("Gate3", new CrossingGate(780,540, "Gate3"));
+ gates.put("Gate4", new CrossingGate(380,540, "Gate4"));
}
private void buildTracks(){
- tracks.put("Royal", new RailwayTracks(new Point(0,500),new Point(1200,500)));
+ tracks.put("Royal", new RailwayTracks(new Point(0,360),new Point(1200,360)));
+ tracks.put("Magenta", new RailwayTracks(new Point(0,560),new Point(1200,560)));
}
private void assignGatesToRoads(){
roads.get("Western Highway").assignGate(gates.get("Gate1"));
roads.get("Skyway").assignGate(gates.get("Gate2"));
+ roads.get("Western Highway").assignGate(gates.get("Gate3"));
+ roads.get("Skyway").assignGate(gates.get("Gate4"));
}
private void buildCarFactories(){
@@ -56,6 +61,10 @@ public Collection getAllGates(){
return gates.values();
}
+ public CrossingGate getGate(String gate){
+ return gates.get(gate);
+ }
+
public Collection getTracks(){
return tracks.values();
}
@@ -64,7 +73,11 @@ public Collection getRoads(){
return roads.values();
}
+ public Road getRoad(String road){
+ return roads.get(road);
+ }
+
public RailwayTracks getTrack(String name){
- return tracks.get("Royal");
+ return tracks.get(name);
}
}
diff --git a/src/edu/nd/sarec/railwaycrossing/model/infrastructure/gate/CrossingGate.java b/src/edu/nd/sarec/railwaycrossing/model/infrastructure/gate/CrossingGate.java
index 1314ffcf..397e636b 100644
--- a/src/edu/nd/sarec/railwaycrossing/model/infrastructure/gate/CrossingGate.java
+++ b/src/edu/nd/sarec/railwaycrossing/model/infrastructure/gate/CrossingGate.java
@@ -4,6 +4,7 @@
import java.util.Observer;
import edu.nd.sarec.railwaycrossing.model.vehicles.Train;
+import edu.nd.sarec.railwaycrossing.model.vehicles.Train2;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
@@ -22,6 +23,8 @@ public class CrossingGate extends Observable implements Observer{
private int movingY;
private int triggerPoint;
private int exitPoint;
+ private int triggerPoint2;
+ private int exitPoint2;
private IGateState gateClosed;
private IGateState gateOpen;
@@ -42,6 +45,8 @@ public CrossingGate(int xPosition, int yPosition, String crossingGate){
movingY = anchorY-60;
triggerPoint = anchorX+250;
exitPoint = anchorX-250;
+ exitPoint2 = anchorX+250;
+ triggerPoint2 = anchorX-250;
// Gate elements
line = new Line(anchorX, anchorY,movingX,movingY);
@@ -61,6 +66,10 @@ public Line getGateLine(){
return line;
}
+ public int getAnchorY() {
+ return anchorY;
+ }
+
public void operateGate(){
currentGateState.operate();
}
@@ -124,6 +133,14 @@ public void update(Observable o, Object arg) {
else if(train.getVehicleX() < triggerPoint){
currentGateState.approachStation();
}
- }
+ }
+ if (o instanceof Train2){
+ Train2 train2 = (Train2)o;
+ if (train2.getVehicleX() > exitPoint2)
+ currentGateState.leaveStation();
+ else if(train2.getVehicleX() > triggerPoint2){
+ currentGateState.approachStation();
+ }
+ }
}
}
diff --git a/src/edu/nd/sarec/railwaycrossing/model/vehicles/Car.java b/src/edu/nd/sarec/railwaycrossing/model/vehicles/Car.java
index 3f3073cb..632a5f45 100644
--- a/src/edu/nd/sarec/railwaycrossing/model/vehicles/Car.java
+++ b/src/edu/nd/sarec/railwaycrossing/model/vehicles/Car.java
@@ -19,8 +19,12 @@ public class Car extends Observable implements IVehicle, Observer{
private double currentY = 0;
private double originalY = 0;
private boolean gateDown = false;
+ private boolean gate2Down = false;
private double leadCarY = -1; // Current Y position of car directly infront of this one
private double speed = 0.5;
+ private boolean canMove = true;
+ private boolean canTurn = false;
+ private boolean turn = false;
/**
* Constructor
@@ -52,23 +56,55 @@ public double getVehicleY(){
return currentY;
}
- public void move(){
- boolean canMove = true;
+ public void move(){
+ canMove = true;
+ canTurn = false;
- // First case. Car is at the front of the stopping line.
- if (gateDown && getVehicleY() < 430 && getVehicleY()> 390)
+ // First check if car is able to turn onto east road
+ if (turn && getVehicleY() > 615 && getVehicleY() < 645 ) {
+ canMove = false;
+ canTurn = true;
+ }
+ // Car has switched to other road and now has to straighten out again
+ if (turn && getVehicleY() > 615 && getVehicleY() < 645 && getVehicleX() > 370 && getVehicleX() < 390 ) {
+ canMove = true;
+ canTurn = false;
+ }
+ // Car is at the front of the stopping line.
+ if (gateDown && getVehicleY() < 290 && getVehicleY() > 250)
+ canMove = false;
+
+ if (gate2Down && getVehicleY() < 490 && getVehicleY() > 450)
canMove = false;
// Second case. Car is too close too other car.
if (leadCarY != -1 && getDistanceToLeadCar() < 50)
canMove = false;
+ // First gate is open but second gate is closed and there isnt enough space to not get caught on track
+ // *****Professor said it is okay I made a second pair of gates operate on the second train*************
+ if (leadCarY > 360 && leadCarY < 410 && gate2Down && getVehicleY() < 320 && getVehicleY()> 250) {
+ canMove = false;
+ }
if (canMove){
currentY+=speed;
ivCar.setY(currentY);
- setChanged();
- notifyObservers();
}
+
+ if (canTurn){
+ currentX-=speed;
+ ivCar.setX(currentX);
+ }
+ setChanged();
+ notifyObservers();
+ }
+
+ public void setTurn(boolean turn) {
+ this.turn = turn;
+ }
+
+ public boolean getTurn() {
+ return turn;
}
public void setSpeed(double speed){
@@ -79,6 +115,10 @@ public void setGateDownFlag(boolean gateDown){
this.gateDown = gateDown;
}
+ public void setGate2DownFlag(boolean gateDown){
+ this.gate2Down = gateDown;
+ }
+
public boolean offScreen(){
if (currentY > 1020)
return true;
@@ -101,18 +141,28 @@ public void removeLeadCar(){
@Override
public void update(Observable o, Object arg1) {
if (o instanceof Car){
- leadCarY = (((Car)o).getVehicleY());
+ if(((Car)o).getTurn() && ((Car)o).getVehicleY() > 615)
+ leadCarY = -1;
+ else
+ leadCarY = (((Car)o).getVehicleY());
+
if (leadCarY > 1020)
leadCarY = -1;
}
if (o instanceof CrossingGate){
CrossingGate gate = (CrossingGate)o;
- if(gate.getTrafficCommand()=="STOP")
- gateDown = true;
- else
- gateDown = false;
-
+ if(gate.getAnchorY() < 360) {
+ if(gate.getTrafficCommand()=="STOP")
+ gateDown = true;
+ else
+ gateDown = false;
+ }else {
+ if(gate.getTrafficCommand()=="STOP")
+ gate2Down = true;
+ else
+ gate2Down = false;
+ }
}
}
}
diff --git a/src/edu/nd/sarec/railwaycrossing/model/vehicles/CarFactory.java b/src/edu/nd/sarec/railwaycrossing/model/vehicles/CarFactory.java
index 1eae29ed..9d788d27 100644
--- a/src/edu/nd/sarec/railwaycrossing/model/vehicles/CarFactory.java
+++ b/src/edu/nd/sarec/railwaycrossing/model/vehicles/CarFactory.java
@@ -33,9 +33,12 @@ public CarFactory(Direction direction, Point location, Collection
// Most code here is to create random speeds
public Car buildCar(){
if (previousCar == null || location.y < previousCar.getVehicleY()-100){
- Car car = new Car(location.x,location.y);
+ Car car = new Car(location.x,location.y);
double speedVariable = (Math.random() * 10)/10;
- car.setSpeed((2-speedVariable)*1.5);
+ car.setSpeed((2-speedVariable)*1.3);
+
+ if ((int)(Math.random()*100) < 40 && location.x > 700) // controls how often a random car is chosen to turn down the eat road
+ car.setTurn(true);
// All cars created by this factory must be aware of crossing gates in the road
for(CrossingGate gate: gates){
@@ -54,7 +57,8 @@ public Car buildCar(){
} else
return null;
}
-
+
+
// We will get a concurrency error if we try to delete cars whilst iterating through the array list
// so we perform this in two stages.
// 1. Loop through the list and identify which cars are off the screen. Add them to 'toDelete' array.
diff --git a/src/edu/nd/sarec/railwaycrossing/model/vehicles/Train.java b/src/edu/nd/sarec/railwaycrossing/model/vehicles/Train.java
index 9265466d..b517e8c0 100644
--- a/src/edu/nd/sarec/railwaycrossing/model/vehicles/Train.java
+++ b/src/edu/nd/sarec/railwaycrossing/model/vehicles/Train.java
@@ -28,7 +28,7 @@ public Train(int x, int y){
imgView.setX(currentX);
imgView.setY(currentY);
}
-
+
public double getVehicleX(){
return currentX;
}
@@ -48,7 +48,7 @@ public boolean offScreen(){
if (currentX < -200)
return true;
else
- return false;
+ return false;
}
public void reset(){
diff --git a/src/edu/nd/sarec/railwaycrossing/model/vehicles/Train2.java b/src/edu/nd/sarec/railwaycrossing/model/vehicles/Train2.java
new file mode 100644
index 00000000..6529bde5
--- /dev/null
+++ b/src/edu/nd/sarec/railwaycrossing/model/vehicles/Train2.java
@@ -0,0 +1,62 @@
+package edu.nd.sarec.railwaycrossing.model.vehicles;
+
+import java.util.Observable;
+
+import javafx.scene.Node;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+/**
+ * Represents the train entity object
+ * @author jane
+ *
+ */
+public class Train2 extends Observable implements IVehicle{
+ private double currentX = 0;
+ private double currentY = 0;
+ private double originalX = 0;
+ private Image img;
+ private ImageView imgView;
+ private int trainLength = 35;
+
+ public Train2(int x, int y){
+ this.currentX = x;
+ this.currentY = y;
+ originalX = x;
+ img = new Image("images\\Train2.PNG",120,trainLength,false,false);
+ imgView = new ImageView(img);
+ imgView.setX(currentX);
+ imgView.setY(currentY);
+ }
+
+ public double getVehicleX(){
+ return currentX;
+ }
+
+ public double getVehicleY(){
+ return currentY;
+ }
+
+ public void move(){
+ currentX+=3;
+ imgView.setX(currentX);
+ setChanged();
+ notifyObservers();
+ }
+
+ public boolean offScreen(){
+ if (currentX > 1750)
+ return true;
+ else
+ return false;
+ }
+
+ public void reset(){
+ currentX = originalX;
+ }
+
+ //@Override
+ public Node getImageView() {
+ return imgView;
+ }
+}
\ No newline at end of file
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/BlueDoor.java b/src/edu/nd/se2018/homework/ChipsChallenge/BlueDoor.java
new file mode 100644
index 00000000..c7562306
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/BlueDoor.java
@@ -0,0 +1,50 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import java.awt.Point;
+
+import javafx.scene.Node;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+public class BlueDoor implements Door{
+ Image doorImage;
+ ImageView doorImageView;
+ Point location = new Point();
+ String color;
+
+ public BlueDoor(int x, int y, int scalingFactor) {
+ location.x = x;
+ location.y = y;
+ color = "Blue";
+ Image doorImage = new Image("images\\blueKeyWall.png",scalingFactor, scalingFactor, false, true);
+ doorImageView = new ImageView(doorImage);
+ doorImageView.setX(x*scalingFactor);
+ doorImageView.setY(y*scalingFactor);
+ }
+
+ @Override
+ public Node getImageView() {
+ return doorImageView;
+ }
+
+ @Override
+ public int getDoorX() {
+ return location.x;
+ }
+
+ @Override
+ public int getDoorY() {
+ return location.y;
+ }
+
+ @Override
+ public void delete() {
+
+ }
+
+ @Override
+ public String getColor() {
+ return color;
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/BlueKey.java b/src/edu/nd/se2018/homework/ChipsChallenge/BlueKey.java
new file mode 100644
index 00000000..d3d7c38c
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/BlueKey.java
@@ -0,0 +1,51 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import java.awt.Point;
+
+import javafx.scene.Node;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+public class BlueKey implements Key {
+ Image keyImage;
+ ImageView keyImageView;
+ Point location = new Point();
+ String color;
+
+ public BlueKey(int x, int y, int scalingFactor) {
+ location.x = x;
+ location.y = y;
+ color = "Blue";
+ Image keyImage = new Image("images\\blueKey.png",scalingFactor, scalingFactor, false, true);
+ keyImageView = new ImageView(keyImage);
+ keyImageView.setX(x*scalingFactor);
+ keyImageView.setY(y*scalingFactor);
+ }
+
+ @Override
+ public Node getImageView() {
+ return keyImageView;
+ }
+
+ @Override
+ public int getKeyX() {
+ return location.x;
+ }
+
+ @Override
+ public int getKeyY() {
+ return location.y;
+ }
+
+ @Override
+ public String getColor() {
+ return color;
+ }
+
+ @Override
+ public void delete() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/Chip.java b/src/edu/nd/se2018/homework/ChipsChallenge/Chip.java
new file mode 100644
index 00000000..442e2008
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/Chip.java
@@ -0,0 +1,114 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+import java.awt.Point;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Observable;
+
+
+import edu.nd.se2018.homework.ChipsChallenge.ChipsMap;
+
+public class Chip extends Observable{
+ Point location = new Point();
+ ChipsMap map;
+ List chipsKeys = new LinkedList();
+ int chipLives;
+ int startX;
+ int startY;
+
+ public Chip(ChipsMap chipMap, int x, int y){
+ map = chipMap;
+ location.x = x;
+ location.y = y;
+ startX = x;
+ startY = y;
+ chipLives = 3;
+ }
+
+ public Point getChipLocation() {
+ return location;
+ }
+
+ public void setChipLocation(int x, int y) {
+ startX = x;
+ startY = y;
+ location.x = x;
+ location.y = y;
+ }
+
+ public void killChip() {
+ chipLives -= 1;
+ resetChip();
+ }
+
+ public void resetChip() {
+ location.x = startX;
+ location.y = startY;
+ }
+
+ public int getChipLives() {
+ return chipLives;
+ }
+
+ public void clearPockets() {
+ for (int i = chipsKeys.size()-1; i >= 0; i--)
+ chipsKeys.remove(i);
+ }
+ public boolean unlockDoor(Door door) {
+ ArrayList toDelete = new ArrayList();
+ boolean unlocked = false;
+
+ for(Key key: chipsKeys) {
+ if(key.getColor() == door.getColor()) {
+ unlocked = true;
+ toDelete.add(key);
+ }
+ }
+
+ for(Key key: toDelete) {
+ chipsKeys.remove(key);
+ }
+
+ return unlocked;
+ }
+
+ public void grabKey(Key key) {
+ chipsKeys.add(key);
+ }
+
+ public void useKey(Key key) {
+ chipsKeys.remove(key);
+ }
+
+ public void goEast() {
+ if(location.x < 24 && map.chipsGrid[location.x +1][location.y] < 1) {
+ location.x += 1;
+ }
+ setChanged();
+ notifyObservers();
+ }
+
+ public void goWest() {
+ if(location.x > 0 && map.chipsGrid[location.x -1][location.y] < 1) {
+ location.x -= 1;
+ }
+ setChanged();
+ notifyObservers();
+ }
+
+ public void goNorth() {
+ if(location.y > 0 && map.chipsGrid[location.x][location.y-1] < 1) {
+ location.y -= 1;
+ }
+ setChanged();
+ notifyObservers();
+ }
+
+ public void goSouth() {
+ if(location.y < 24 && map.chipsGrid[location.x][location.y +1] < 1) {
+ location.y += 1;
+ }
+ setChanged();
+ notifyObservers();
+ }
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge Description.docx b/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge Description.docx
new file mode 100644
index 00000000..bd7782bb
Binary files /dev/null and b/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge Description.docx differ
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge Patterns.pdf b/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge Patterns.pdf
new file mode 100644
index 00000000..d4e6c4c3
Binary files /dev/null and b/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge Patterns.pdf differ
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge UML Final.pdf b/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge UML Final.pdf
new file mode 100644
index 00000000..caae4dc7
Binary files /dev/null and b/src/edu/nd/se2018/homework/ChipsChallenge/Chips Challenge UML Final.pdf differ
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallengeExplorer.java b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallengeExplorer.java
new file mode 100644
index 00000000..169a9887
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallengeExplorer.java
@@ -0,0 +1,326 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import javafx.animation.AnimationTimer;
+import javafx.application.Application;
+import javafx.event.EventHandler;
+import javafx.scene.Scene;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.input.KeyEvent;
+import javafx.scene.layout.AnchorPane;
+import javafx.scene.layout.Pane;
+import javafx.stage.Stage;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+
+public class ChipsChallengeExplorer extends Application{
+
+ Pane root;
+ final int dimensions = 25;
+ final int wallCount = 10;
+ final int scalingFactor = 26;
+ public int pause = 0;
+ boolean exitGame = false;
+ Image chipImage;
+ ImageView chipImageView;
+ ChipsMap chipsMap;
+ Scene scene;
+ Chip chip;
+ List blocks;
+ List keys;
+ List doors;
+ List monsters;
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ @Override
+ public void start(Stage mapStage) throws Exception {
+ chipsMap = new ChipsMap();
+
+ root = new AnchorPane();
+ chipsMap.drawMap(root.getChildren(), scalingFactor);
+ chipsMap.placeWalls(root.getChildren(), scalingFactor);
+ chipsMap.placeHazards(root.getChildren(), scalingFactor);
+ chip = new Chip(chipsMap, 12, 18);
+
+ keys = new LinkedList();
+ keys.add(new BlueKey(2,12,scalingFactor));
+
+ doors = new LinkedList();
+ doors.add(new BlueDoor(18,12,scalingFactor));
+
+ blocks = new LinkedList();
+ blocks.add(new MoveableBlock(chipsMap, 2, 2));
+ blocks.add(new MoveableBlock(chipsMap, 22, 2));
+
+ monsters = new LinkedList();
+ monsters.add(new Monster(chipsMap,"Left",5,16,scalingFactor));
+ monsters.add(new Monster(chipsMap,"Right",0,15,scalingFactor));
+
+ // register observers of the ship
+ for(Monster monster: monsters)
+ chip.addObserver(monster);
+ // Load images on map
+ loadImages();
+
+ for (Door door: doors)
+ chipsMap.setDoor(door);
+
+ for (MoveableBlock block: blocks)
+ block.setImageView();
+ // set scene
+ scene = new Scene(root,650,650);
+ mapStage.setTitle("Chips Challenge");
+ mapStage.setScene(scene);
+ mapStage.show();
+
+
+ new AnimationTimer(){
+
+ @Override
+ public void handle(long now) {
+ //Monster Movement
+ if(pause > 50) {
+ pause = 0;
+ }
+
+ if(pause == 0) {
+ for(Monster monster: monsters) {
+ monster.canMove();
+ monster.move();
+ monster.setImageView();
+ if(chip.getChipLocation().x == monster.getX() && chip.getChipLocation().y == monster.getY()) {
+ chip.killChip();
+ chipImageView.setX(chip.getChipLocation().x*scalingFactor);
+ chipImageView.setY(chip.getChipLocation().y*scalingFactor);
+ chipsMap.killLife(root.getChildren());
+ }
+ }
+ }
+
+ pause+=1;
+ // Chip lives
+ if (chip.getChipLives() == 0 || exitGame) {
+ mapStage.close();
+ }
+
+ // Go To level 2
+ if (chipsMap.chipsGrid[chip.getChipLocation().x][chip.getChipLocation().y] == -1) {
+ nextLevel();
+ }
+ // End of level 2
+ if (chipsMap.chipsGrid[chip.getChipLocation().x][chip.getChipLocation().y] == -2) {
+ mapStage.close();
+ }
+
+ }
+ }.start();
+
+ startPlaying();
+ }
+
+ private void startPlaying() {
+
+ scene.setOnKeyPressed(new EventHandler(){
+
+ @Override
+ public void handle(KeyEvent ke) {
+ switch(ke.getCode()){
+ case RIGHT:
+ chip.goEast();
+ for(MoveableBlock block: blocks) {
+ if(block.getBlockLocation().x == chip.getChipLocation().x && block.getBlockLocation().y == chip.getChipLocation().y) {
+ block.goEast();
+ }
+ }
+ chipImage = new Image("images\\chipRight.png",scalingFactor, scalingFactor, false, true);
+ chipImageView.setImage(chipImage);
+ break;
+ case LEFT:
+ chip.goWest();
+ for(MoveableBlock block: blocks) {
+ if(block.getBlockLocation().x == chip.getChipLocation().x && block.getBlockLocation().y == chip.getChipLocation().y) {
+ block.goWest();
+ }
+ }
+ chipImage = new Image("images\\chipLeft.png",scalingFactor, scalingFactor, false, true);
+ chipImageView.setImage(chipImage);
+ break;
+ case UP:
+ chip.goNorth();
+ for(MoveableBlock block: blocks) {
+ if(block.getBlockLocation().y == chip.getChipLocation().y && block.getBlockLocation().x == chip.getChipLocation().x) {
+ block.goNorth();
+ }
+ }
+ chipImage = new Image("images\\chipBack.png",scalingFactor, scalingFactor, false, true);
+ chipImageView.setImage(chipImage);
+ break;
+ case DOWN:
+ chip.goSouth();
+ for(MoveableBlock block: blocks) {
+ if(block.getBlockLocation().y == chip.getChipLocation().y && block.getBlockLocation().x == chip.getChipLocation().x) {
+ block.goSouth();
+ }
+ }
+ chipImage = new Image("images\\chipFront.png",scalingFactor, scalingFactor, false, true);
+ chipImageView.setImage(chipImage);
+ break;
+ case ESCAPE:
+ exitGame = true;
+ break;
+ case TAB:
+ //skip first level for testing
+ nextLevel();
+ break;
+ default:
+ break;
+ }
+ /////////// Handle Blocks ////////////
+ ArrayList blockDelete = new ArrayList();
+ for(MoveableBlock block: blocks) {
+ if(chipsMap.chipsGrid[block.getBlockLocation().x][block.getBlockLocation().y] == 2) {
+ blockDelete.add(block);
+ }
+ block.setImageView();
+ }
+ // Remove Moveable Blocks
+ for (MoveableBlock block: blockDelete) {
+ chipsMap.setToGround(root.getChildren(), scalingFactor, block.getBlockLocation().x, block.getBlockLocation().y);
+ blocks.remove(block);
+ refreshBlockImages();
+ refreshChipImage();
+ }
+ //////////// Handle Keys /////////////
+ ArrayList keyDelete = new ArrayList();
+ for(Key key: keys) {
+ if((key.getKeyX() - chip.getChipLocation().x) == 0 && (key.getKeyY() - chip.getChipLocation().y) == 0) {
+ chip.grabKey(key);
+ keyDelete.add(key);
+ }
+ }
+
+ for(Key key: keyDelete) {
+ chipsMap.setToGround(root.getChildren(), scalingFactor, key.getKeyX(), key.getKeyY());
+ keys.remove(key);
+ refreshChipImage();
+ }
+ /////////////// Handle Doors ///////////////
+ ArrayList doorDelete = new ArrayList();
+ for(Door door: doors) {
+ if( Math.abs(door.getDoorX() - chip.getChipLocation().x) < 2 && Math.abs(door.getDoorY() - chip.getChipLocation().y) < 2) {
+ if(chip.unlockDoor(door)) {
+ doorDelete.add(door);
+ }
+ }
+ }
+
+ for(Door door: doorDelete) {
+ chipsMap.setToGround(root.getChildren(), scalingFactor, door.getDoorX(), door.getDoorY());
+ root.getChildren().remove(door.getImageView());
+ doors.remove(door);
+ refreshBlockImages();
+ refreshChipImage();
+ }
+ // Update chip position
+ chipImageView.setX(chip.getChipLocation().x*scalingFactor);
+ chipImageView.setY(chip.getChipLocation().y*scalingFactor);
+ }
+ });
+
+ }
+
+ private void refreshChipImage() {
+ root.getChildren().remove(chipImageView);
+ chipImageView = new ImageView(chipImage);
+ chipImageView.setX(chip.getChipLocation().x*scalingFactor);
+ chipImageView.setY(chip.getChipLocation().y*scalingFactor);
+ root.getChildren().add(chipImageView);
+ }
+
+ private void refreshBlockImages() {
+ for (MoveableBlock block: blocks)
+ root.getChildren().remove(block.getImageView());
+
+ for (MoveableBlock block: blocks)
+ root.getChildren().add(block.getImageView());
+ }
+
+ private void nextLevel() {
+ // Delete all imageviews from root
+ root.getChildren().clear();
+ // delete all item arrays
+ for(int i = monsters.size()-1; i >= 0; i--)
+ monsters.remove(i);
+ for (int i = doors.size()-1; i >= 0; i--)
+ doors.remove(i);
+ for (int i = blocks.size()-1; i >= 0; i--)
+ blocks.remove(i);
+ for (int i = keys.size()-1; i >= 0; i--)
+ keys.remove(i);
+ // call drawmap2, drawWalls2, etc on chipmap
+ chipsMap.drawMap2(root.getChildren());
+ chipsMap.placeWalls2(root.getChildren());
+ chipsMap.placeHazards2(root.getChildren());
+ // create all new items
+ keys.add(new RedKey(24,16,scalingFactor));
+ keys.add(new BlueKey(1,15,scalingFactor));
+
+ doors.add(new RedDoor(20,1,scalingFactor));
+ doors.add(new BlueDoor(6,1,scalingFactor));
+
+ blocks.add(new MoveableBlock(chipsMap, 19, 5));
+ blocks.add(new MoveableBlock(chipsMap, 14, 11));
+ blocks.add(new MoveableBlock(chipsMap, 16, 19));
+
+ monsters.add(new Monster(chipsMap,"Left",24,1,scalingFactor));
+ monsters.add(new Monster(chipsMap,"Left",24,7,scalingFactor));
+ monsters.add(new Monster(chipsMap,"Left",12,10,scalingFactor));
+ monsters.add(new Monster(chipsMap,"Right",0,19,scalingFactor));
+ monsters.add(new Monster(chipsMap,"Left",5,18,scalingFactor));
+ monsters.add(new Monster(chipsMap,"Right",2,17,scalingFactor));
+ monsters.add(new Monster(chipsMap,"Right",7,15,scalingFactor));
+
+ // register observers of the ship
+ for(Monster monster: monsters)
+ chip.addObserver(monster);
+
+ for (Door door: doors)
+ chipsMap.setDoor(door);
+
+ for (MoveableBlock block: blocks)
+ block.setImageView();
+ //set chips location and clear his pockets
+ chip.clearPockets();
+ chip.setChipLocation(23, 24);
+ // call loadImages()
+ loadImages();
+ }
+
+ private void loadImages(){
+
+ Image chipImage = new Image("images\\chipFront.png",scalingFactor, scalingFactor, false, true);
+ chipImageView = new ImageView(chipImage);
+ chipImageView.setX(chip.getChipLocation().x*scalingFactor);
+ chipImageView.setY(chip.getChipLocation().y*scalingFactor);
+
+ root.getChildren().add(chipImageView);
+
+ for (MoveableBlock block: blocks)
+ root.getChildren().add(block.getImageView());
+
+ for (Key key: keys)
+ root.getChildren().add(key.getImageView());
+
+ for (Door door: doors)
+ root.getChildren().add(door.getImageView());
+
+ for (Monster monster: monsters)
+ root.getChildren().add(monster.getImageView());
+ }
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_1.JPG b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_1.JPG
new file mode 100644
index 00000000..6aa8e50b
Binary files /dev/null and b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_1.JPG differ
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_2.JPG b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_2.JPG
new file mode 100644
index 00000000..73319027
Binary files /dev/null and b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_2.JPG differ
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_UML.pdf b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_UML.pdf
new file mode 100644
index 00000000..3722e953
Binary files /dev/null and b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsChallenge_UML.pdf differ
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/ChipsMap.java b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsMap.java
new file mode 100644
index 00000000..2e2c033b
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/ChipsMap.java
@@ -0,0 +1,299 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javafx.collections.ObservableList;
+import javafx.scene.Node;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+public class ChipsMap {
+
+ int[][] chipsGrid = new int[25][25];
+ final int dimensions = 25;
+ Image wall;
+ Image lava;
+ ImageView lavaImageView;
+ ImageView wallImageView;
+ Image ground;
+ Image heart;
+ Image portal;
+ ImageView portalImageView;
+ ImageView groundImageView;
+ int scale;
+
+ List lives = new LinkedList();
+
+ public void drawMap(ObservableList root, int scale) {
+ this.scale = scale;
+ ground = new Image("images\\BlankTile.png",scale, scale, false, true);
+ lava = new Image("images\\lava_tile.png",scale, scale, false, true);
+ wall = new Image("images\\wall.png",scale, scale, false, true);
+ for(int x = 0; x < dimensions; x++) {
+ for(int y = 0; y < dimensions; y++) {
+ groundImageView = new ImageView(ground);
+ groundImageView.setX(x*scale);
+ groundImageView.setY(y*scale);
+ root.add(groundImageView);
+ chipsGrid[x][y] = 0;
+ }
+ }
+ //Heart images in top left corner
+ heart = new Image("images\\Heart.png",scale, scale, false, true);
+ ImageView heart1 = new ImageView(heart);
+ ImageView heart2 = new ImageView(heart);
+ ImageView heart3 = new ImageView(heart);
+ lives.add(heart1);
+ lives.add(heart2);
+ lives.add(heart3);
+ int x = 0;
+ int y = 0;
+ for (ImageView life: lives) {
+ life.setX(x*scale);
+ life.setY(y*scale);
+ root.add(life);
+ x += 1;
+ }
+
+ // Portal image
+ portal = new Image("images\\portal.png",scale, scale, false, true);
+ portalImageView = new ImageView(portal);
+ portalImageView.setX(12*scale);
+ portalImageView.setY(1*scale);
+ root.add(portalImageView);
+ chipsGrid[12][1] = -1;
+ }
+ //// SECOND MAP
+ public void drawMap2(ObservableList root) {
+ Image ground = new Image("images\\BlankTile.png",scale, scale, false, true);
+ for(int x = 0; x < dimensions; x++) {
+ for(int y = 0; y < dimensions; y++) {
+ groundImageView = new ImageView(ground);
+ groundImageView.setX(x*scale);
+ groundImageView.setY(y*scale);
+ root.add(groundImageView);
+ chipsGrid[x][y] = 0;
+ }
+ }
+ //Heart images in top left corner
+ int x = 0;
+ int y = 24;
+ for (ImageView life: lives) {
+ life.setX(x*scale);
+ life.setY(y*scale);
+ root.add(life);
+ x += 1;
+ }
+
+ // Portal image
+ portalImageView = new ImageView(portal);
+ portalImageView.setX(1*scale);
+ portalImageView.setY(1*scale);
+ root.add(portalImageView);
+ chipsGrid[1][1] = -2;
+ }
+
+
+ public void killLife(ObservableList root) {
+ root.remove(lives.get(lives.size()-1));
+ lives.remove(lives.size()-1);
+ }
+ public void setToGround(ObservableList root, int scale, int x, int y) {
+ Image ground = new Image("images\\BlankTile.png",scale, scale, false, true);
+ groundImageView = new ImageView(ground);
+ groundImageView.setX(x*scale);
+ groundImageView.setY(y*scale);
+ root.add(groundImageView);
+ chipsGrid[x][y] = 0;
+ }
+
+ public void setGrid(int x, int y, int val) {
+ chipsGrid[x][y] = val;
+ }
+
+ public void setDoor(Door door) {
+ setGrid(door.getDoorX(),door.getDoorY(), 1);
+ }
+
+ public void placeHazards(ObservableList root, int scale) {
+ int row1 = 4;
+ int row2 = 5;
+
+ for(int i = 7; i < 18; i++) {
+ chipsGrid[i][row1] = 2;
+ chipsGrid[i][row2] = 2;
+ //lava = new Image("images\\lava_tile.png",scale, scale, false, true);
+ lavaImageView = new ImageView(lava);
+ lavaImageView.setX(i*scale);
+ lavaImageView.setY(row1*scale);
+ root.add(lavaImageView);
+ lavaImageView = new ImageView(lava);
+ lavaImageView.setX(i*scale);
+ lavaImageView.setY(row2*scale);
+ root.add(lavaImageView);
+ }
+ }
+
+ public void placeHazards2(ObservableList root) {
+ //Horizontal lava
+ int row = 3;
+ for(int i = 0; i < 4; i++) {
+ chipsGrid[i][row] = 2;
+ lavaImageView = new ImageView(lava);
+ lavaImageView.setX(i*scale);
+ lavaImageView.setY(row*scale);
+ root.add(lavaImageView);
+ }
+
+ row = 6;
+ for(int i = 14; i < 20; i++) {
+ chipsGrid[i][row] = 2;
+ lavaImageView = new ImageView(lava);
+ lavaImageView.setX(i*scale);
+ lavaImageView.setY(row*scale);
+ root.add(lavaImageView);
+ }
+
+ row = 12;
+ for(int i = 14; i < 20; i++) {
+ chipsGrid[i][row] = 2;
+ lavaImageView = new ImageView(lava);
+ lavaImageView.setX(i*scale);
+ lavaImageView.setY(row*scale);
+ root.add(lavaImageView);
+ }
+
+ // Hard coding in 10 lava blocks placed in weird order
+ chipsGrid[24][12] = 2;
+ chipsGrid[21][13] = 2;
+ chipsGrid[22][14] = 2;
+ chipsGrid[23][14] = 2;
+ chipsGrid[21][16] = 2;
+ chipsGrid[23][16] = 2;
+ chipsGrid[24][17] = 2;
+ chipsGrid[22][18] = 2;
+ chipsGrid[23][19] = 2;
+ chipsGrid[21][20] = 2;
+ for (int x = 21; x < 25; x++) {
+ for(int y = 12; y < 21; y++) {
+ if (chipsGrid[x][y] == 2) {
+ lavaImageView = new ImageView(lava);
+ lavaImageView.setX(x*scale);
+ lavaImageView.setY(y*scale);
+ root.add(lavaImageView);
+ }
+ }
+ }
+
+ // Vertical lava strips
+ int col = 3;
+ for(int i = 0; i < 4; i++) {
+ chipsGrid[col][i] = 2;
+ lavaImageView = new ImageView(lava);
+ lavaImageView.setX(col*scale);
+ lavaImageView.setY(i*scale);
+ root.add(lavaImageView);
+ }
+
+ }
+
+ public void placeWalls(ObservableList root, int scale) {
+ int vert1 = 6;
+ int vert2 = 18;
+ int horz1 = 10;
+ int horz2 = 15;
+ // Vertical walls
+ for(int j = 0; j <= 24; j++) {
+ if (j < 6 || (j > 9 && j < 19) || j > 20) {
+ chipsGrid[vert1][j] = 1;
+ wallImageView = new ImageView(wall);
+ wallImageView.setX(vert1*scale);
+ wallImageView.setY(j*scale);
+ root.add(wallImageView);
+ // Second column of walls
+ if (j != 12) {
+ chipsGrid[vert2][j] = 1;
+ wallImageView = new ImageView(wall);
+ wallImageView.setX(vert2*scale);
+ wallImageView.setY(j*scale);
+ root.add(wallImageView);
+ }
+ }
+ }
+ // horizontal walls
+ for(int i = 0; i <= 24; i++) {
+ if (i < 7 || i > 17) {
+ chipsGrid[i][horz1] = 1;
+ wallImageView = new ImageView(wall);
+ wallImageView.setX(i*scale);
+ wallImageView.setY(horz1*scale);
+ root.add(wallImageView);
+ }
+ // second row
+ if (i < 18 && i > 6) {
+ chipsGrid[i][horz2] = 1;
+ wallImageView = new ImageView(wall);
+ wallImageView.setX(i*scale);
+ wallImageView.setY(horz2*scale);
+ root.add(wallImageView);
+ }
+ }
+
+ }
+
+ public void placeWalls2(ObservableList root) {
+ int col1 = 20;
+ int col2 = 13;
+ int col3 = 6;
+ int row1 = 13;
+ // Vertical walls
+ for(int j = 0; j < 25; j++) {
+ if (j != 1) {
+ chipsGrid[col1][j] = 1;
+ wallImageView = new ImageView(wall);
+ wallImageView.setX(col1*scale);
+ wallImageView.setY(j*scale);
+ root.add(wallImageView);
+ }
+ }
+ for(int j = 0; j < 22; j++) {
+ chipsGrid[col2][j] = 1;
+ wallImageView = new ImageView(wall);
+ wallImageView.setX(col2*scale);
+ wallImageView.setY(j*scale);
+ root.add(wallImageView);
+ }
+ for(int j = 0; j < 23; j++) {
+ if (j != 1) {
+ chipsGrid[col3][j] = 1;
+ wallImageView = new ImageView(wall);
+ wallImageView.setX(col3*scale);
+ wallImageView.setY(j*scale);
+ root.add(wallImageView);
+ }
+ }
+ // horizontal walls
+ for(int i = 0; i < 6; i++) {
+ chipsGrid[i][row1] = 1;
+ wallImageView = new ImageView(wall);
+ wallImageView.setX(i*scale);
+ wallImageView.setY(row1*scale);
+ root.add(wallImageView);
+ }
+
+ }
+
+ public void resetMap(ObservableList root) {
+ for(int x = 0; x < dimensions; x++) {
+ for(int y = 0; y < dimensions; y++) {
+ groundImageView = new ImageView(ground);
+ groundImageView.setX(x*scale);
+ groundImageView.setY(y*scale);
+ root.add(groundImageView);
+ chipsGrid[x][y] = 0;
+ }
+ }
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/Door.java b/src/edu/nd/se2018/homework/ChipsChallenge/Door.java
new file mode 100644
index 00000000..35945c8a
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/Door.java
@@ -0,0 +1,11 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import javafx.scene.Node;
+
+public interface Door {
+ public Node getImageView();
+ public int getDoorX();
+ public int getDoorY();
+ public String getColor();
+ public void delete();
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/First Deliverable b/src/edu/nd/se2018/homework/ChipsChallenge/First Deliverable
new file mode 100644
index 00000000..d003fecb
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/First Deliverable
@@ -0,0 +1,4 @@
+I have created the 25x25 map and placed chip in it. He can move and his sprite changes to the appropiate image according to the
+direction he is moving. I also placed walls down but only at random right now, I am working on creating the maps so the walls
+make structures. I also am working on making a Viewport (camera that zooms in and follows chip, but for debugging purposes for the
+whole map I am leaving the camera zoomed out for now. I also will make moveable blocks, enemies and doors.
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/IMonsterState.java b/src/edu/nd/se2018/homework/ChipsChallenge/IMonsterState.java
new file mode 100644
index 00000000..b7c0e611
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/IMonsterState.java
@@ -0,0 +1,7 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+public interface IMonsterState {
+ public void approachRange();
+ public void leaveRange();
+ public void hitBarrier();
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/Key.java b/src/edu/nd/se2018/homework/ChipsChallenge/Key.java
new file mode 100644
index 00000000..71d36eaa
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/Key.java
@@ -0,0 +1,11 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import javafx.scene.Node;
+
+public interface Key {
+ public Node getImageView();
+ public int getKeyX();
+ public int getKeyY();
+ public String getColor();
+ public void delete();
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/Monster.java b/src/edu/nd/se2018/homework/ChipsChallenge/Monster.java
new file mode 100644
index 00000000..e124ab55
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/Monster.java
@@ -0,0 +1,131 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import java.util.Observable;
+import java.util.Observer;
+
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+
+public class Monster implements Observer{
+
+ Image monsterLeftImage;
+ Image monsterRightImage;
+ Image monsterSleepImage;
+ ImageView monsterImageView;
+ ChipsMap map;
+ int scale;
+ int triggerPoint;
+ int xLocation;
+ int yLocation;
+ String direction;
+
+ private IMonsterState monsterSleeping;
+ private IMonsterState monsterLeft;
+ private IMonsterState monsterRight;
+ private IMonsterState currState;
+
+
+ public Monster(){}
+
+ public Monster(ChipsMap chipsmap, String direction, int x, int y, int scalingFactor) {
+ this.scale = scalingFactor;
+ this.direction = direction;
+ map = chipsmap;
+ triggerPoint = 4;
+ xLocation = x;
+ yLocation = y;
+
+ monsterLeftImage = new Image("images\\MonsterLeft.png",scale, scale, false, true);
+ monsterRightImage = new Image("images\\MonsterRight.png",scale, scale, false, true);
+ monsterSleepImage = new Image("images\\MonsterSleep.png",scale, scale, false, true);
+ monsterImageView = new ImageView(monsterSleepImage);
+
+ monsterSleeping = new MonsterSleeping(this);
+ monsterLeft = new MonsterLeft(this);
+ monsterRight = new MonsterRight(this);
+ currState = monsterSleeping;
+
+ }
+
+ public void move() {
+ if (currState == monsterLeft) {
+ monsterImageView.setImage(monsterLeftImage);
+ xLocation -= 1;
+ }else if (currState == monsterRight) {
+ monsterImageView.setImage(monsterRightImage);
+ xLocation += 1;
+ }else if (currState == monsterSleeping) {
+ monsterImageView.setImage(monsterSleepImage);
+ }
+
+ }
+
+ public void canMove() {
+ if (currState == monsterLeft) {
+ if(xLocation > 0) {
+ if(map.chipsGrid[xLocation - 1][yLocation] == 1)
+ currState.hitBarrier();
+ }else {
+ currState.hitBarrier();
+ }
+ }else if (currState == monsterRight) {
+ if(xLocation < 24) {
+ if(map.chipsGrid[xLocation + 1][yLocation] == 1)
+ currState.hitBarrier();
+ }else {
+ currState.hitBarrier();
+ }
+ }
+ }
+
+ public void setImageView() {
+ monsterImageView.setX(xLocation*scale);
+ monsterImageView.setY(yLocation*scale);
+ }
+
+ public int getX() {
+ return xLocation;
+ }
+ public int getY() {
+ return yLocation;
+ }
+
+ public ImageView getImageView() {
+ return monsterImageView;
+ }
+
+ public IMonsterState getMonsterSleepingState() {
+ return monsterSleeping;
+ }
+ public IMonsterState getDirectionState() {
+ if (direction == "Left")
+ return monsterLeft;
+ else
+ return monsterRight;
+ }
+ public IMonsterState getMonsterLeftState() {
+ return monsterLeft;
+ }
+ public IMonsterState getMonsterRightState() {
+ return monsterRight;
+ }
+ public void setMonsterState(IMonsterState newState) {
+ currState = newState;
+ }
+
+ @Override
+ public void update(Observable o, Object arg) {
+ // TODO Auto-generated method stub
+ if (o instanceof Chip){
+ Chip chip = (Chip)o;
+ if (Math.abs(chip.getChipLocation().x - xLocation) > triggerPoint || Math.abs(chip.getChipLocation().y - yLocation) > triggerPoint)
+ currState.leaveRange();
+ else if(Math.abs(chip.getChipLocation().x - xLocation) <= triggerPoint || Math.abs(chip.getChipLocation().y - yLocation) <= triggerPoint){
+ currState.approachRange();
+ }
+ }
+ }
+
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/MonsterLeft.java b/src/edu/nd/se2018/homework/ChipsChallenge/MonsterLeft.java
new file mode 100644
index 00000000..21db053d
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/MonsterLeft.java
@@ -0,0 +1,26 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+public class MonsterLeft implements IMonsterState{
+
+ private Monster monster;
+
+ protected MonsterLeft(Monster monster){
+ this.monster = monster;
+ }
+ @Override
+ public void approachRange() {
+ // N/A
+
+ }
+
+ @Override
+ public void leaveRange() {
+ monster.setMonsterState(monster.getMonsterSleepingState());
+ }
+
+ @Override
+ public void hitBarrier() {
+ monster.setMonsterState(monster.getMonsterRightState());
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/MonsterRight.java b/src/edu/nd/se2018/homework/ChipsChallenge/MonsterRight.java
new file mode 100644
index 00000000..2c3d7fad
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/MonsterRight.java
@@ -0,0 +1,27 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+public class MonsterRight implements IMonsterState{
+
+ private Monster monster;
+
+ protected MonsterRight(Monster monster){
+ this.monster = monster;
+ }
+
+ @Override
+ public void approachRange() {
+ // N/A
+
+ }
+
+ @Override
+ public void leaveRange() {
+ monster.setMonsterState(monster.getMonsterSleepingState());
+ }
+
+ @Override
+ public void hitBarrier() {
+ monster.setMonsterState(monster.getMonsterLeftState());
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/MonsterSleeping.java b/src/edu/nd/se2018/homework/ChipsChallenge/MonsterSleeping.java
new file mode 100644
index 00000000..8bb9ce73
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/MonsterSleeping.java
@@ -0,0 +1,28 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+public class MonsterSleeping implements IMonsterState{
+
+ private Monster monster;
+
+ protected MonsterSleeping(Monster monster){
+ this.monster = monster;
+ }
+
+ @Override
+ public void approachRange() {
+ monster.setMonsterState(monster.getDirectionState());
+ }
+
+ @Override
+ public void leaveRange() {
+ // N/A
+
+ }
+
+ @Override
+ public void hitBarrier() {
+ // N/A
+
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/MoveableBlock.java b/src/edu/nd/se2018/homework/ChipsChallenge/MoveableBlock.java
new file mode 100644
index 00000000..e4cd4cf4
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/MoveableBlock.java
@@ -0,0 +1,60 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import java.awt.Point;
+
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+public class MoveableBlock{
+ ChipsMap map;
+ Point location = new Point();
+ final int scalingFactor = 26;
+ Image blockImage;
+ ImageView blockImageView;
+
+ public MoveableBlock(ChipsMap chipMap, int x, int y) {
+ map = chipMap;
+ location.x = x;
+ location.y = y;
+ blockImage = new Image("images\\moveableBlock.png",scalingFactor, scalingFactor, false, true);
+ blockImageView = new ImageView(blockImage);
+ }
+
+ public void setImageView() {
+ blockImageView.setX(location.x*scalingFactor);
+ blockImageView.setY(location.y*scalingFactor);
+ }
+
+ public ImageView getImageView(){
+ return blockImageView;
+ }
+
+ public Point getBlockLocation() {
+ return location;
+ }
+
+ public void goEast() {
+ if(location.x < 24 && map.chipsGrid[location.x +1][location.y] != 1) {
+ location.x += 1;
+ }
+ }
+
+ public void goWest() {
+ if(location.x > 0 && map.chipsGrid[location.x -1][location.y] != 1) {
+ location.x -= 1;
+ }
+ }
+
+ public void goNorth() {
+ if(location.y > 0 && map.chipsGrid[location.x][location.y-1] != 1) {
+ location.y -= 1;
+ }
+ }
+
+ public void goSouth() {
+ if(location.y < 24 && map.chipsGrid[location.x][location.y +1] != 1) {
+ location.y += 1;
+ }
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/RedDoor.java b/src/edu/nd/se2018/homework/ChipsChallenge/RedDoor.java
new file mode 100644
index 00000000..e8f57bbc
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/RedDoor.java
@@ -0,0 +1,50 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import java.awt.Point;
+
+import javafx.scene.Node;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+public class RedDoor implements Door{
+ Image doorImage;
+ ImageView doorImageView;
+ Point location = new Point();
+ String color;
+
+ public RedDoor(int x, int y, int scalingFactor) {
+ location.x = x;
+ location.y = y;
+ color = "Red";
+ Image doorImage = new Image("images\\redKeyWall.png",scalingFactor, scalingFactor, false, true);
+ doorImageView = new ImageView(doorImage);
+ doorImageView.setX(x*scalingFactor);
+ doorImageView.setY(y*scalingFactor);
+ }
+
+ @Override
+ public Node getImageView() {
+ return doorImageView;
+ }
+
+ @Override
+ public int getDoorX() {
+ return location.x;
+ }
+
+ @Override
+ public int getDoorY() {
+ return location.y;
+ }
+
+ @Override
+ public void delete() {
+
+ }
+
+ @Override
+ public String getColor() {
+ return color;
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ChipsChallenge/RedKey.java b/src/edu/nd/se2018/homework/ChipsChallenge/RedKey.java
new file mode 100644
index 00000000..a6e73279
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ChipsChallenge/RedKey.java
@@ -0,0 +1,51 @@
+package edu.nd.se2018.homework.ChipsChallenge;
+
+import java.awt.Point;
+
+import javafx.scene.Node;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+public class RedKey implements Key {
+ Image keyImage;
+ ImageView keyImageView;
+ Point location = new Point();
+ String color;
+
+ public RedKey(int x, int y, int scalingFactor) {
+ location.x = x;
+ location.y = y;
+ color = "Red";
+ Image keyImage = new Image("images\\redKey.png",scalingFactor, scalingFactor, false, true);
+ keyImageView = new ImageView(keyImage);
+ keyImageView.setX(x*scalingFactor);
+ keyImageView.setY(y*scalingFactor);
+ }
+
+ @Override
+ public Node getImageView() {
+ return keyImageView;
+ }
+
+ @Override
+ public int getKeyX() {
+ return location.x;
+ }
+
+ @Override
+ public int getKeyY() {
+ return location.y;
+ }
+
+ @Override
+ public String getColor() {
+ return color;
+ }
+
+ @Override
+ public void delete() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ColumbusGame/Colubus game Class Diagram.pdf b/src/edu/nd/se2018/homework/ColumbusGame/Colubus game Class Diagram.pdf
new file mode 100644
index 00000000..98eebbbe
Binary files /dev/null and b/src/edu/nd/se2018/homework/ColumbusGame/Colubus game Class Diagram.pdf differ
diff --git a/src/edu/nd/se2018/homework/ColumbusGame/Columbus Class Diagram.ucls b/src/edu/nd/se2018/homework/ColumbusGame/Columbus Class Diagram.ucls
new file mode 100644
index 00000000..95e66c22
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ColumbusGame/Columbus Class Diagram.ucls
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/edu/nd/se2018/homework/ColumbusGame/Columbus Game Reflection.docx b/src/edu/nd/se2018/homework/ColumbusGame/Columbus Game Reflection.docx
new file mode 100644
index 00000000..c802f514
Binary files /dev/null and b/src/edu/nd/se2018/homework/ColumbusGame/Columbus Game Reflection.docx differ
diff --git a/src/edu/nd/se2018/homework/ColumbusGame/OceanExplorer.java b/src/edu/nd/se2018/homework/ColumbusGame/OceanExplorer.java
new file mode 100644
index 00000000..3118ee62
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ColumbusGame/OceanExplorer.java
@@ -0,0 +1,110 @@
+package edu.nd.se2018.homework.ColumbusGame;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javafx.application.Application;
+import javafx.event.EventHandler;
+import javafx.scene.input.KeyEvent;
+import javafx.scene.Scene;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.AnchorPane;
+import javafx.scene.layout.Pane;
+import javafx.stage.Stage;
+
+public class OceanExplorer extends Application{
+
+ boolean[][] islandMap;
+ Pane root;
+ final int dimensions = 10;
+ final int islandCount = 10;
+ final int scalingFactor = 50;
+ Image shipImage;
+ ImageView shipImageView;
+ Image pirateImage;
+ ImageView pirateImageView;
+ OceanMap oceanMap;
+ Scene scene;
+ Ship ship;
+ List pirates;
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ @Override
+ public void start(Stage mapStage) throws Exception {
+
+ oceanMap = new OceanMap();
+ //islandMap = oceanMap.getMap();
+
+ root = new AnchorPane();
+ oceanMap.drawMap(root.getChildren(), scalingFactor);
+ oceanMap.placeIslands(root.getChildren(), scalingFactor);
+
+ ship = new Ship(oceanMap);
+
+ pirates = new LinkedList();
+ int pirateCount = 2;
+ for(int j = 0; j< pirateCount; j++)
+ pirates.add(new PirateShip(oceanMap));
+
+ // register observers of the ship
+ for(PirateShip pirate: pirates)
+ ship.addObserver(pirate);
+ // Load images on map
+ loadShipImage();
+ for(PirateShip pirate: pirates) {
+ pirate.setImageView();
+ }
+ // set scene
+ scene = new Scene(root,500,500);
+ mapStage.setTitle("Christopher Columbus Sails the Ocean Blue");
+ mapStage.setScene(scene);
+ mapStage.show();
+ startSailing();
+ }
+
+ private void startSailing() {
+
+ scene.setOnKeyPressed(new EventHandler(){
+
+ @Override
+ public void handle(KeyEvent ke) {
+ switch(ke.getCode()){
+ case RIGHT:
+ ship.goEast();
+ break;
+ case LEFT:
+ ship.goWest();
+ break;
+ case UP:
+ ship.goNorth();
+ break;
+ case DOWN:
+ ship.goSouth();
+ break;
+ default:
+ break;
+ }
+ shipImageView.setX(ship.getShipLocation().x*scalingFactor);
+ shipImageView.setY(ship.getShipLocation().y*scalingFactor);
+ }
+ });
+
+ }
+
+ private void loadShipImage(){
+
+ Image shipImage = new Image("images\\ColumbusShip.png",scalingFactor, scalingFactor, false, true);
+ shipImageView = new ImageView(shipImage);
+ shipImageView.setX(ship.getShipLocation().x*scalingFactor);
+ shipImageView.setY(ship.getShipLocation().y*scalingFactor);
+
+ root.getChildren().add(shipImageView);
+ for (PirateShip pirate: pirates)
+ root.getChildren().add(pirate.getImageView());
+ }
+
+}
\ No newline at end of file
diff --git a/src/edu/nd/se2018/homework/ColumbusGame/OceanMap.java b/src/edu/nd/se2018/homework/ColumbusGame/OceanMap.java
new file mode 100644
index 00000000..1f9a10c2
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ColumbusGame/OceanMap.java
@@ -0,0 +1,49 @@
+package edu.nd.se2018.homework.ColumbusGame;
+import javafx.collections.ObservableList;
+import javafx.scene.Node;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import java.util.concurrent.ThreadLocalRandom;
+
+public class OceanMap {
+
+ int[][] oceanGrid = new int[10][10];
+ final int dimensions = 10;
+ Image island;
+ ImageView islandImageView;
+ Image ocean;
+ ImageView oceanImageView;
+
+ public void drawMap(ObservableList root, int scale) {
+ Image ocean = new Image("images\\oceanSprite.png",scale, scale, false, true);
+ for(int x = 0; x < dimensions; x++) {
+ for(int y = 0; y < dimensions; y++) {
+ oceanImageView = new ImageView(ocean);
+ oceanImageView.setX(x*scale);
+ oceanImageView.setY(y*scale);
+ root.add(oceanImageView);
+ oceanGrid[x][y] = 0;
+ }
+ }
+ }
+
+ public void placeIslands(ObservableList root, int scale) {
+ int randomNum;
+ int randomNum2;
+ for(int i = 0; i <= 9; i++) {
+ randomNum = ThreadLocalRandom.current().nextInt(0, 10);
+ randomNum2 = ThreadLocalRandom.current().nextInt(0, 10);
+ if (oceanGrid[randomNum][randomNum2] == 0) {
+ oceanGrid[randomNum][randomNum2] = 1;
+ island = new Image("images\\islandSprite.png",scale, scale, false, true);
+ islandImageView = new ImageView(island);
+ islandImageView.setX(randomNum*scale);
+ islandImageView.setY(randomNum2*scale);
+ root.add(islandImageView);
+ }else {
+ i -= 1;
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/edu/nd/se2018/homework/ColumbusGame/PirateShip.java b/src/edu/nd/se2018/homework/ColumbusGame/PirateShip.java
new file mode 100644
index 00000000..9e028ae8
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ColumbusGame/PirateShip.java
@@ -0,0 +1,63 @@
+package edu.nd.se2018.homework.ColumbusGame;
+import java.awt.Point;
+import java.util.concurrent.ThreadLocalRandom;
+
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import java.util.Observable;
+import java.util.Observer;
+
+public class PirateShip implements Observer{
+
+ Point pirateLocation = new Point();
+ Point shipLocation;
+ final int scalingFactor = 50;
+ Image pirateImage;
+ ImageView pirateImageView;
+ int randomNum = ThreadLocalRandom.current().nextInt(0, 10);
+ int randomNum2 = ThreadLocalRandom.current().nextInt(0, 10);
+ OceanMap map;
+
+ public PirateShip(OceanMap oceanMap) {
+ map = oceanMap;
+ do {
+ pirateLocation.x = ThreadLocalRandom.current().nextInt(0, 10);
+ pirateLocation.y = ThreadLocalRandom.current().nextInt(0, 10);
+ } while (map.oceanGrid[pirateLocation.x][pirateLocation.y] != 0);
+ pirateImage = new Image("images\\pirateship.gif",50,50,true,true);
+ pirateImageView = new ImageView(pirateImage);
+ }
+
+ public void setImageView() {
+ pirateImageView.setX(pirateLocation.x*scalingFactor);
+ pirateImageView.setY(pirateLocation.y*scalingFactor);
+ }
+
+ public ImageView getImageView(){
+ return pirateImageView;
+ }
+
+ public void movePirate() {
+
+ if (pirateLocation.x - shipLocation.x < 0 && map.oceanGrid[pirateLocation.x +1][pirateLocation.y] == 0 ) {
+ pirateLocation.x++;
+ }else if (pirateLocation.x - shipLocation.x > 0 && map.oceanGrid[pirateLocation.x -1][pirateLocation.y] == 0) {
+ pirateLocation.x--;
+ }else if (pirateLocation.y - shipLocation.y < 0 && map.oceanGrid[pirateLocation.x][pirateLocation.y+1] == 0) {
+ pirateLocation.y++;
+ }else if (pirateLocation.y - shipLocation.y > 0 && map.oceanGrid[pirateLocation.x][pirateLocation.y-1] == 0) {
+ pirateLocation.y--;
+ }
+ setImageView();
+ }
+
+ @Override
+ public void update(Observable s, Object arg) {
+ if (s instanceof Ship){
+ shipLocation = ((Ship)s).getShipLocation();
+ movePirate();
+ }
+
+ }
+
+}
diff --git a/src/edu/nd/se2018/homework/ColumbusGame/Ship.java b/src/edu/nd/se2018/homework/ColumbusGame/Ship.java
new file mode 100644
index 00000000..2a2e6a0f
--- /dev/null
+++ b/src/edu/nd/se2018/homework/ColumbusGame/Ship.java
@@ -0,0 +1,56 @@
+package edu.nd.se2018.homework.ColumbusGame;
+import java.awt.Point;
+import java.util.Observable;
+import java.util.concurrent.ThreadLocalRandom;
+
+public class Ship extends Observable{
+
+ Point location = new Point();
+ OceanMap map;
+
+ public Ship(OceanMap oceanMap){
+ map = oceanMap;
+ do {
+ location.x = ThreadLocalRandom.current().nextInt(0, 10);
+ location.y = ThreadLocalRandom.current().nextInt(0, 10);
+ } while (map.oceanGrid[location.x][location.y] != 0);
+ }
+
+ public Point getShipLocation() {
+ return location;
+ }
+
+ public void goEast() {
+ if(location.x < 9 && map.oceanGrid[location.x +1][location.y] != 1) {
+ location.x += 1;
+ }
+ setChanged();
+ notifyObservers();
+ }
+
+ public void goWest() {
+ if(location.x > 0 && map.oceanGrid[location.x -1][location.y] != 1) {
+ location.x -= 1;
+ }
+ setChanged();
+ notifyObservers();
+ }
+
+ public void goNorth() {
+ if(location.y > 0 && map.oceanGrid[location.x][location.y-1] != 1) {
+ location.y -= 1;
+ }
+ setChanged();
+ notifyObservers();
+ }
+
+ public void goSouth() {
+ if(location.y < 9 && map.oceanGrid[location.x][location.y +1] != 1) {
+ location.y += 1;
+ }
+ setChanged();
+ notifyObservers();
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/edu/nd/se2018/homework/hwk1/Question1.java b/src/edu/nd/se2018/homework/hwk1/Question1.java
index d990b3b1..928b0a3c 100644
--- a/src/edu/nd/se2018/homework/hwk1/Question1.java
+++ b/src/edu/nd/se2018/homework/hwk1/Question1.java
@@ -1,10 +1,27 @@
package edu.nd.se2018.homework.hwk1;
+/**
+ * Homework 2 Problem 1
+ * @author Elijah hager
+ *
+ */
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.Iterator;
public class Question1 {
+
+ public int getSumWithoutDuplicates(int[] arr) {
+ HashSet nums = IntStream.of(arr).boxed().collect(Collectors.toCollection(HashSet::new));
- public Question1(){}
-
- public int getSumWithoutDuplicates(int[] numbers){
- return 0;
+ int sum = 0;
+ Iterator it = nums.iterator();
+ while(it.hasNext()){
+ sum += it.next();
+ }
+
+ System.out.println(sum);
+ return sum;
}
-}
+
+}
\ No newline at end of file
diff --git a/src/edu/nd/se2018/homework/hwk1/Question2.java b/src/edu/nd/se2018/homework/hwk1/Question2.java
index b04a7f86..7b38e2fb 100644
--- a/src/edu/nd/se2018/homework/hwk1/Question2.java
+++ b/src/edu/nd/se2018/homework/hwk1/Question2.java
@@ -1,10 +1,42 @@
package edu.nd.se2018.homework.hwk1;
+/**
+ * Homework 2 Problem 2
+ * @author Elijah hager
+ *
+ */
+import java.util.*;
+import java.util.Map.Entry;
public class Question2 {
- public Question2(){}
+ public Object getMostFrequentWord(String inputString, String stopWords) {
+ HashMap map = new HashMap<>();
+
+ String[] tokens1 = stopWords.split(" "); // split by space
+ HashSet stopSet = new HashSet<>(Arrays.asList(tokens1));
+
+ String[] tokens2 = inputString.split(" "); // split by space
+
+ for (String token: tokens2){
+ if(!stopSet.contains(token)) {
+ if(map.containsKey(token)) {
+ int count = map.get(token);
+ map.put(token, count+1); // increment word count
+ } else {
+ map.put(token, 1);
+ }
+ }
+ }
- public String getMostFrequentWord(String input, String stopwords){
- return "";
+ Object[] numbers = map.values().toArray(); // turn map values into sorted array to check last two values
+ Arrays.sort(numbers);
+ if (numbers[numbers.length-1] == numbers[numbers.length-2]) { // check last two numbers
+ return null;
+ }
+
+ Map.Entry temp = (Entry) map.entrySet().stream().sorted(Map.Entry.comparingByValue().reversed()).findFirst().get();
+ System.out.println(temp.getKey());
+
+ return temp.getKey();
}
-}
+}
\ No newline at end of file
diff --git a/src/edu/nd/se2018/homework/hwk1/Question3.java b/src/edu/nd/se2018/homework/hwk1/Question3.java
index 740d282c..75b576b2 100644
--- a/src/edu/nd/se2018/homework/hwk1/Question3.java
+++ b/src/edu/nd/se2018/homework/hwk1/Question3.java
@@ -1,9 +1,47 @@
package edu.nd.se2018.homework.hwk1;
+/**
+ * Homework 2 Problem 2
+ * @author Elijah hager
+ *
+ */
+
public class Question3 {
- public Question3(){}
+ public int getMirrorCount(int[] arr) {
+ int[] reversedArr = mirrorArr(arr);
+
+ return maxCount(arr, reversedArr);
+ }
+
+ private int[] mirrorArr(int[] arr) {
+ int[] newArray = new int[arr.length];
+
+ for (int i = arr.length-1, j = 0; i >= 0; i--, j++) {
+ newArray[j] = arr[i];
+ }
+
+ return newArray;
+ }
- public int getMirrorCount(int[] numbers){
- return 0;
+ private int maxCount(int[] forward, int[] reversed) {
+ int maxCount = 0;
+ int count = 0;
+
+ for (int i = 0; i < forward.length; i++) {
+
+ if (forward[i] == reversed[i]) {
+ count++;
+ }else {
+ count = 0;
+ }
+
+ if (count > maxCount) {
+ maxCount = count;
+ }
+
+ }
+ System.out.println(maxCount);
+ return maxCount;
}
+
}
diff --git a/src/horse_race_hwk2/MonsterBack.png b/src/horse_race_hwk2/MonsterBack.png
new file mode 100644
index 00000000..d93de461
Binary files /dev/null and b/src/horse_race_hwk2/MonsterBack.png differ
diff --git a/src/horse_race_hwk2/MonsterRight.png b/src/horse_race_hwk2/MonsterRight.png
new file mode 100644
index 00000000..0dce17b7
Binary files /dev/null and b/src/horse_race_hwk2/MonsterRight.png differ
diff --git a/src/horse_race_hwk2/ReaceTest.java b/src/horse_race_hwk2/ReaceTest.java
new file mode 100644
index 00000000..cada56a7
--- /dev/null
+++ b/src/horse_race_hwk2/ReaceTest.java
@@ -0,0 +1,16 @@
+package horse_race_hwk2;
+import org.junit.Test;
+
+import design_patterns.horses.Race;
+
+public class ReaceTest {
+ @Test
+ public void test() throws InterruptedException {
+ Race race1 = new Race();
+ race1.enrollHorse("Jimmy", 43, "steady");
+ race1.enrollHorse("Klien", 46, "slow");
+ race1.enrollHorse("Dabo", 45, "early");
+ race1.enrollHorse("Sheen", 42, "slow");
+ race1.enrollHorse("Biscuit", 41, "steady");
+ }
+}
diff --git a/src/horse_race_hwk2/package-info.java b/src/horse_race_hwk2/package-info.java
new file mode 100644
index 00000000..7cce0bed
--- /dev/null
+++ b/src/horse_race_hwk2/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author elija
+ *
+ */
+package horse_race_hwk2;
\ No newline at end of file
diff --git a/src/images/BlankTile.png b/src/images/BlankTile.png
new file mode 100644
index 00000000..c594f20d
Binary files /dev/null and b/src/images/BlankTile.png differ
diff --git a/src/images/Brick.png b/src/images/Brick.png
new file mode 100644
index 00000000..83996b1e
Binary files /dev/null and b/src/images/Brick.png differ
diff --git a/src/images/Heart.png b/src/images/Heart.png
new file mode 100644
index 00000000..172095ee
Binary files /dev/null and b/src/images/Heart.png differ
diff --git a/src/images/MonsterFront.png b/src/images/MonsterFront.png
new file mode 100644
index 00000000..bccd4cb3
Binary files /dev/null and b/src/images/MonsterFront.png differ
diff --git a/src/images/MonsterLeft.png b/src/images/MonsterLeft.png
new file mode 100644
index 00000000..17141cad
Binary files /dev/null and b/src/images/MonsterLeft.png differ
diff --git a/src/images/MonsterRight.png b/src/images/MonsterRight.png
new file mode 100644
index 00000000..0dce17b7
Binary files /dev/null and b/src/images/MonsterRight.png differ
diff --git a/src/images/MonsterSleep.png b/src/images/MonsterSleep.png
new file mode 100644
index 00000000..d483a388
Binary files /dev/null and b/src/images/MonsterSleep.png differ
diff --git a/src/images/Train2.png b/src/images/Train2.png
new file mode 100644
index 00000000..0b4d4d1d
Binary files /dev/null and b/src/images/Train2.png differ
diff --git a/chip/textures/blueKey.png b/src/images/blueKey.png
similarity index 100%
rename from chip/textures/blueKey.png
rename to src/images/blueKey.png
diff --git a/chip/textures/blueKeyWall.png b/src/images/blueKeyWall.png
similarity index 100%
rename from chip/textures/blueKeyWall.png
rename to src/images/blueKeyWall.png
diff --git a/src/images/chipBack.png b/src/images/chipBack.png
new file mode 100644
index 00000000..d08da7da
Binary files /dev/null and b/src/images/chipBack.png differ
diff --git a/src/images/chipFront.png b/src/images/chipFront.png
new file mode 100644
index 00000000..2a87458b
Binary files /dev/null and b/src/images/chipFront.png differ
diff --git a/src/images/chipLeft.png b/src/images/chipLeft.png
new file mode 100644
index 00000000..1e78c810
Binary files /dev/null and b/src/images/chipLeft.png differ
diff --git a/src/images/chipRight.png b/src/images/chipRight.png
new file mode 100644
index 00000000..e78607ad
Binary files /dev/null and b/src/images/chipRight.png differ
diff --git a/src/images/islandSprite.png b/src/images/islandSprite.png
new file mode 100644
index 00000000..a0619e00
Binary files /dev/null and b/src/images/islandSprite.png differ
diff --git a/src/images/lava_tile.png b/src/images/lava_tile.png
new file mode 100644
index 00000000..6aae8338
Binary files /dev/null and b/src/images/lava_tile.png differ
diff --git a/src/images/moveableBlock.png b/src/images/moveableBlock.png
new file mode 100644
index 00000000..d4aba3f3
Binary files /dev/null and b/src/images/moveableBlock.png differ
diff --git a/src/images/oceanSprite.png b/src/images/oceanSprite.png
new file mode 100644
index 00000000..a80e4549
Binary files /dev/null and b/src/images/oceanSprite.png differ
diff --git a/chip/textures/portal.png b/src/images/portal.png
similarity index 100%
rename from chip/textures/portal.png
rename to src/images/portal.png
diff --git a/src/images/redKey.png b/src/images/redKey.png
new file mode 100644
index 00000000..3bb88b4b
Binary files /dev/null and b/src/images/redKey.png differ
diff --git a/src/images/redKeyWall.png b/src/images/redKeyWall.png
new file mode 100644
index 00000000..8ac73e32
Binary files /dev/null and b/src/images/redKeyWall.png differ
diff --git a/src/images/tiles.png b/src/images/tiles.png
new file mode 100644
index 00000000..55ae1c0c
Binary files /dev/null and b/src/images/tiles.png differ
diff --git a/src/images/wall.png b/src/images/wall.png
new file mode 100644
index 00000000..77304176
Binary files /dev/null and b/src/images/wall.png differ