diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..1f81f9b
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/.project b/.project
index d4ab2e6..bf254a7 100644
--- a/.project
+++ b/.project
@@ -7,5 +7,6 @@
+ org.eclipse.jdt.core.javanature
diff --git a/src/Acceleration.java b/src/Acceleration.java
index 3bccc68..181922b 100644
--- a/src/Acceleration.java
+++ b/src/Acceleration.java
@@ -1,4 +1,5 @@
-import java.util.*;
+import java.util.AbstractMap;
+import java.util.Map;
public class Acceleration {
private double mass;
@@ -6,20 +7,36 @@
private Velocity velocity;
private Onground onground;
private Map.Entry acceleration;
+
public void updateMass(double mass) {
this.mass = mass;
- acceleration = (this.onground.getOnground() ? new AbstractMap.SimpleEntry<>((force.getKey()/mass), 0.0) : new AbstractMap.SimpleEntry<>((force.getKey()/mass), (force.getValue()/mass)));
+
+ if (getOnground())
+ acceleration = new AbstractMap.SimpleEntry<>((force.getKey() / mass), 0.0);
+ else
+ acceleration = new AbstractMap.SimpleEntry<>((force.getKey() / mass), (force.getValue() / mass));
velocity.updateAcceleration(acceleration);
}
+
public void updateForce(Map.Entry force) {
this.force = force;
- acceleration = (this.onground.getOnground() ? new AbstractMap.SimpleEntry<>((force.getKey()/mass), 0.0) : new AbstractMap.SimpleEntry<>((force.getKey()/mass), (force.getValue()/mass)));
+
+ if (getOnground())
+ acceleration = new AbstractMap.SimpleEntry<>((force.getKey() / mass), 0.0);
+ else
+ acceleration = new AbstractMap.SimpleEntry<>((force.getKey() / mass), (force.getValue() / mass));
velocity.updateAcceleration(acceleration);
}
+
public Acceleration(Velocity velocity, Onground onground) {
this.onground = onground;
}
+
public Map.Entry getAcceleration() {
return acceleration;
}
+
+ private boolean getOnground() {
+ return (this.onground.getOnground());
+ }
}
\ No newline at end of file
diff --git a/src/Clear.java b/src/Clear.java
index 5936436..7dfa66a 100644
--- a/src/Clear.java
+++ b/src/Clear.java
@@ -2,10 +2,12 @@
public class Clear {
private Position position;
+
public Clear(Position position) {
this.position = position;
}
+
public boolean getClear() {
- return ((this.position.getPosition().getKey()>100.0) ? true : false);
+ return (this.position.getPosition().getKey() > 100.0);
}
}
\ No newline at end of file
diff --git a/src/Force.java b/src/Force.java
index e379404..345d80e 100644
--- a/src/Force.java
+++ b/src/Force.java
@@ -3,13 +3,16 @@
public class Force {
private Acceleration acceleration;
private Map.Entry force;
+
public Force(Acceleration acceleration) {
this.acceleration = acceleration;
}
+
public void gravity(double y) {
this.force = new AbstractMap.SimpleEntry<>(0.0, y);
acceleration.updateForce(force);
}
+
public Map.Entry getForce() {
return force;
}
diff --git a/src/Gameover.java b/src/Gameover.java
index e0bef2f..e4beb56 100644
--- a/src/Gameover.java
+++ b/src/Gameover.java
@@ -2,10 +2,12 @@
public class Gameover {
private Position position;
+
public Gameover(Position position) {
this.position = position;
}
+
public boolean getGameover() {
- return ((this.position.getPosition().getValue()<-(1.0)) ? true : false);
+ return (this.position.getPosition().getValue() < -(1.0));
}
}
\ No newline at end of file
diff --git a/src/Ground.java b/src/Ground.java
index 6a1763e..19876c3 100644
--- a/src/Ground.java
+++ b/src/Ground.java
@@ -3,9 +3,11 @@
public class Ground {
private Position position;
private boolean ground;
+
public Ground(Position position) {
this.position = position;
}
+
public boolean getGround() {
return ground;
}
diff --git a/src/JumpGame.java b/src/JumpGame.java
index 9aca478..2024353 100644
--- a/src/JumpGame.java
+++ b/src/JumpGame.java
@@ -5,56 +5,71 @@
private Position position = new Position();
private Gameover gameover = new Gameover(position);
private Ground ground = new Ground(position);
- private Onground onground = new Onground(ground,position);
- private Velocity velocity = new Velocity(position,onground);
+ private Onground onground = new Onground(ground, position);
+ private Velocity velocity = new Velocity(position, onground);
private Clear clear = new Clear(position);
private Move move = new Move(velocity);
- private Acceleration acceleration = new Acceleration(velocity,onground);
+ private Acceleration acceleration = new Acceleration(velocity, onground);
private Force force = new Force(acceleration);
private Mass mass = new Mass(acceleration);
+
public void gravity(double y) {
this.force.gravity(y);
this.time.gravity(y);
}
+
public void moveY(double y) {
this.move.moveY(y);
}
+
public void moveX(double x) {
this.move.moveX(x);
}
+
public void setMass(double x) {
this.mass.setMass(x);
}
+
public Map.Entry getAcceleration() {
return acceleration.getAcceleration();
}
+
public Map.Entry getMove() {
return move.getMove();
}
+
public double getMass() {
return mass.getMass();
}
+
public boolean getClear() {
return clear.getClear();
}
+
public boolean getGround() {
return ground.getGround();
}
+
public Map.Entry getForce() {
return force.getForce();
}
+
public Map.Entry getVelocity() {
return velocity.getVelocity();
}
+
public Map.Entry getPosition() {
return position.getPosition();
}
+
public boolean getOnground() {
return onground.getOnground();
}
+
public double getTime() {
return time.getTime();
}
+
public boolean getGameover() {
return gameover.getGameover();
}
diff --git a/src/Mass.java b/src/Mass.java
index c381628..1a8eb69 100644
--- a/src/Mass.java
+++ b/src/Mass.java
@@ -3,13 +3,16 @@
public class Mass {
private Acceleration acceleration;
private double mass;
+
public Mass(Acceleration acceleration) {
this.acceleration = acceleration;
}
+
public void setMass(double x) {
this.mass = x;
acceleration.updateMass(mass);
}
+
public double getMass() {
return mass;
}
diff --git a/src/Move.java b/src/Move.java
index ab8511b..85b668f 100644
--- a/src/Move.java
+++ b/src/Move.java
@@ -3,16 +3,20 @@
public class Move {
private Velocity velocity;
private Map.Entry move;
+
public Move(Velocity velocity) {
this.velocity = velocity;
}
+
public void moveY(double y) {
this.move = new AbstractMap.SimpleEntry<>(this.move.getKey(), y);
velocity.updateMove(move);
}
+
public void moveX(double x) {
this.move = new AbstractMap.SimpleEntry<>(x, this.move.getValue());
}
+
public Map.Entry getMove() {
return move;
}
diff --git a/src/Onground.java b/src/Onground.java
index 694d757..53c9d63 100644
--- a/src/Onground.java
+++ b/src/Onground.java
@@ -3,11 +3,16 @@
public class Onground {
private Ground ground;
private Position position;
+
public Onground(Ground ground, Position position) {
this.ground = ground;
this.position = position;
}
+
+ //AND
public boolean getOnground() {
- return ((this.ground.getGround()==true)&&(this.position.getPosition().getValue()<=0.0));
+ if (!this.ground.getGround())
+ return false;
+ return (this.position.getPosition().getValue() <= 0.0);
}
}
\ No newline at end of file
diff --git a/src/Position.java b/src/Position.java
index 0ecaa4f..e483702 100644
--- a/src/Position.java
+++ b/src/Position.java
@@ -1,18 +1,37 @@
-import java.util.*;
+import java.util.AbstractMap;
+import java.util.Map;
public class Position {
private Map.Entry velocity;
private boolean ground;
private Map.Entry position;
+
public void updateVelocity(Map.Entry velocity) {
this.velocity = velocity;
- position = (((ground==true)&&((this.position.getValue()+(0.01*velocity.getValue()))<0.0)) ? new AbstractMap.SimpleEntry<>((this.position.getKey()+(0.01*velocity.getKey())), 0.0) : new AbstractMap.SimpleEntry<>((this.position.getKey()+(0.01*velocity.getKey())), (this.position.getValue()+(0.01*velocity.getValue()))));
+ if (getOnGround())
+ position = new AbstractMap.SimpleEntry<>((this.position.getKey() + (0.01 * velocity.getKey())), 0.0);
+ else
+ new AbstractMap.SimpleEntry<>((this.position.getKey() + (0.01 * velocity.getKey())),
+ (this.position.getValue() + (0.01 * velocity.getValue())));
}
+
public void updateGround(boolean ground) {
this.ground = ground;
- position = (((ground==true)&&((this.position.getValue()+(0.01*velocity.getValue()))<0.0)) ? new AbstractMap.SimpleEntry<>((this.position.getKey()+(0.01*velocity.getKey())), 0.0) : new AbstractMap.SimpleEntry<>((this.position.getKey()+(0.01*velocity.getKey())), (this.position.getValue()+(0.01*velocity.getValue()))));
+ if (getOnGround())
+ position = new AbstractMap.SimpleEntry<>((this.position.getKey() + (0.01 * velocity.getKey())), 0.0);
+ else
+ new AbstractMap.SimpleEntry<>((this.position.getKey() + (0.01 * velocity.getKey())),
+ (this.position.getValue() + (0.01 * velocity.getValue())));
}
+
public Map.Entry getPosition() {
return position;
}
+
+ // AND
+ private boolean getOnGround() {
+ if (!ground)
+ return false;
+ return ((this.position.getValue() + (0.01 * velocity.getValue())) < 0.0);
+ }
}
\ No newline at end of file
diff --git a/src/Time.java b/src/Time.java
index cf5540a..0a7dc4d 100644
--- a/src/Time.java
+++ b/src/Time.java
@@ -2,9 +2,11 @@
public class Time {
private double time;
+
public void gravity(double y) {
- this.time = (this.time+0.01);
+ this.time = (this.time + 0.01);
}
+
public double getTime() {
return time;
}
diff --git a/src/Velocity.java b/src/Velocity.java
index 4f20c7b..b8c87ff 100644
--- a/src/Velocity.java
+++ b/src/Velocity.java
@@ -1,4 +1,5 @@
-import java.util.*;
+import java.util.AbstractMap;
+import java.util.Map;
public class Velocity {
private Map.Entry acceleration;
@@ -6,20 +7,44 @@
private Position position;
private Onground onground;
private Map.Entry velocity;
+
public void updateAcceleration(Map.Entry acceleration) {
this.acceleration = acceleration;
- velocity = ((this.onground.getOnground()&&(this.velocity.getValue()<0.0)) ? new AbstractMap.SimpleEntry<>((this.velocity.getKey()+(0.01*acceleration.getKey())), 0.0) : new AbstractMap.SimpleEntry<>((this.velocity.getKey()+(0.01*acceleration.getKey())), (this.velocity.getValue()+(0.01*acceleration.getValue()))));
+ if (onJump())
+ velocity = new AbstractMap.SimpleEntry<>((this.velocity.getKey() + (0.01 * acceleration.getKey())), 0.0);
+ else
+ velocity = new AbstractMap.SimpleEntry<>((this.velocity.getKey() + (0.01 * acceleration.getKey())),
+ (this.velocity.getValue() + (0.01 * acceleration.getValue())));
position.updateVelocity(velocity);
}
+
public void updateMove(Map.Entry move) {
this.move = move;
- velocity = ((this.onground.getOnground()&&(move.getValue()>=0.0)) ? move : this.velocity);
+ if (onMove())
+ velocity = move;
+
position.updateVelocity(velocity);
}
+
public Velocity(Position position, Onground onground) {
this.onground = onground;
}
+
public Map.Entry getVelocity() {
return velocity;
}
+
+ // AND, In Air
+ private boolean onJump() {
+ if (!this.onground.getOnground())
+ return false;
+ return (this.velocity.getValue() < 0.0);
+ }
+
+ // AND, Push Button
+ private boolean onMove() {
+ if (!this.onground.getOnground())
+ return false;
+ return (move.getValue() >= 0.0);
+ }
}
\ No newline at end of file