diff --git a/src/Acceleration.java b/src/Acceleration.java new file mode 100644 index 0000000..8a8aef6 --- /dev/null +++ b/src/Acceleration.java @@ -0,0 +1,37 @@ +import java.util.*; + +public class Acceleration { + private Map.Entry force; + private double mass; + private Velocity velocity; + private Onground onground; + private Map.Entry acceleration; + public void updateForce(Map.Entry force) { + this.force = force; + Map.Entry temp_l3; + if(this.onground.getOnground()) { + temp_l3 = new AbstractMap.SimpleEntry<>((force.getKey()/mass), 0.0); + } else { + temp_l3 = new AbstractMap.SimpleEntry<>((force.getKey()/mass), (force.getValue()/mass)); + } + acceleration = temp_l3; + velocity.updateAcceleration(acceleration); + } + public void updateMass(double mass) { + this.mass = mass; + Map.Entry temp_l6; + if(this.onground.getOnground()) { + temp_l6 = new AbstractMap.SimpleEntry<>((force.getKey()/mass), 0.0); + } else { + temp_l6 = new AbstractMap.SimpleEntry<>((force.getKey()/mass), (force.getValue()/mass)); + } + acceleration = temp_l6; + velocity.updateAcceleration(acceleration); + } + public Acceleration(Velocity velocity, Onground onground) { + this.onground = onground; + } + public Map.Entry getAcceleration() { + return acceleration; + } +} \ No newline at end of file diff --git a/src/Clear.java b/src/Clear.java new file mode 100644 index 0000000..336e723 --- /dev/null +++ b/src/Clear.java @@ -0,0 +1,17 @@ +import java.util.*; + +public class Clear { + private Position position; + public Clear(Position position) { + this.position = position; + } + public boolean getClear() { + boolean temp_l1; + if((this.position.getPosition().getKey()>100.0)) { + temp_l1 = true; + } else { + temp_l1 = false; + } + return temp_l1; + } +} \ No newline at end of file diff --git a/src/Force.java b/src/Force.java new file mode 100644 index 0000000..e379404 --- /dev/null +++ b/src/Force.java @@ -0,0 +1,16 @@ +import java.util.*; + +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; + } +} \ No newline at end of file diff --git a/src/Gameover.java b/src/Gameover.java new file mode 100644 index 0000000..5f17032 --- /dev/null +++ b/src/Gameover.java @@ -0,0 +1,17 @@ +import java.util.*; + +public class Gameover { + private Position position; + public Gameover(Position position) { + this.position = position; + } + public boolean getGameover() { + boolean temp_l5; + if((this.position.getPosition().getValue()<-(1.0))) { + temp_l5 = true; + } else { + temp_l5 = false; + } + return temp_l5; + } +} \ No newline at end of file diff --git a/src/Ground.java b/src/Ground.java new file mode 100644 index 0000000..f3dfaf8 --- /dev/null +++ b/src/Ground.java @@ -0,0 +1,8 @@ +import java.util.*; + +public class Ground { + private boolean ground; + public boolean getGround() { + return ground; + } +} \ No newline at end of file diff --git a/src/JumpGame.java b/src/JumpGame.java new file mode 100644 index 0000000..8684695 --- /dev/null +++ b/src/JumpGame.java @@ -0,0 +1,61 @@ +import java.util.*; + +public class JumpGame { + private Time time = new Time(); + private Ground ground = new Ground(); + private Position position = new Position(ground); + private Gameover gameover = new Gameover(position); + 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 Mass mass = new Mass(acceleration); + private Force force = new Force(acceleration); + public void gravity(double y) { + this.force.gravity(y); + this.time.gravity(y); + } + public void moveX(double x) { + this.move.moveX(x); + } + public void moveY(double y) { + this.move.moveY(y); + } + 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(); + } +} \ No newline at end of file diff --git a/src/Mass.java b/src/Mass.java new file mode 100644 index 0000000..c381628 --- /dev/null +++ b/src/Mass.java @@ -0,0 +1,16 @@ +import java.util.*; + +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; + } +} \ No newline at end of file diff --git a/src/Move.java b/src/Move.java new file mode 100644 index 0000000..5f99f99 --- /dev/null +++ b/src/Move.java @@ -0,0 +1,19 @@ +import java.util.*; + +public class Move { + private Velocity velocity; + private Map.Entry move; + public Move(Velocity velocity) { + this.velocity = velocity; + } + public void moveX(double x) { + this.move = new AbstractMap.SimpleEntry<>(x, this.move.getValue()); + velocity.updateMove(move); + } + public void moveY(double y) { + this.move = new AbstractMap.SimpleEntry<>(this.move.getKey(), y); + } + public Map.Entry getMove() { + return move; + } +} \ No newline at end of file diff --git a/src/Onground.java b/src/Onground.java new file mode 100644 index 0000000..694d757 --- /dev/null +++ b/src/Onground.java @@ -0,0 +1,13 @@ +import java.util.*; + +public class Onground { + private Ground ground; + private Position position; + public Onground(Ground ground, Position position) { + this.ground = ground; + this.position = position; + } + public boolean getOnground() { + return ((this.ground.getGround()==true)&&(this.position.getPosition().getValue()<=0.0)); + } +} \ No newline at end of file diff --git a/src/Position.java b/src/Position.java new file mode 100644 index 0000000..e69ad66 --- /dev/null +++ b/src/Position.java @@ -0,0 +1,21 @@ +import java.util.*; + +public class Position { + private Ground ground; + private Map.Entry position; + public void updateVelocity(Map.Entry velocity) { + Map.Entry temp_l4; + if(((this.ground.getGround()==true)&&((this.position.getValue()+(0.01*velocity.getValue()))<0.0))) { + temp_l4 = new AbstractMap.SimpleEntry<>((this.position.getKey()+(0.01*velocity.getKey())), 0.0); + } else { + temp_l4 = new AbstractMap.SimpleEntry<>((this.position.getKey()+(0.01*velocity.getKey())), (this.position.getValue()+(0.01*velocity.getValue()))); + } + position = temp_l4; + } + public Position(Ground ground) { + this.ground = ground; + } + public Map.Entry getPosition() { + return position; + } +} \ No newline at end of file diff --git a/src/Time.java b/src/Time.java new file mode 100644 index 0000000..cf5540a --- /dev/null +++ b/src/Time.java @@ -0,0 +1,11 @@ +import java.util.*; + +public class Time { + private double time; + public void gravity(double y) { + this.time = (this.time+0.01); + } + public double getTime() { + return time; + } +} \ No newline at end of file diff --git a/src/Velocity.java b/src/Velocity.java new file mode 100644 index 0000000..5522079 --- /dev/null +++ b/src/Velocity.java @@ -0,0 +1,37 @@ +import java.util.*; + +public class Velocity { + private Map.Entry move; + private Map.Entry acceleration; + private Position position; + private Onground onground; + private Map.Entry velocity; + public void updateMove(Map.Entry move) { + this.move = move; + Map.Entry temp_l0; + if((this.onground.getOnground()&&(move.getValue()>=0.0))) { + temp_l0 = move; + } else { + temp_l0 = this.velocity; + } + velocity = temp_l0; + position.updateVelocity(velocity); + } + public void updateAcceleration(Map.Entry acceleration) { + this.acceleration = acceleration; + Map.Entry temp_l2; + if((this.onground.getOnground()&&(this.velocity.getValue()<0.0))) { + temp_l2 = new AbstractMap.SimpleEntry<>((this.velocity.getKey()+(0.01*acceleration.getKey())), 0.0); + } else { + temp_l2 = new AbstractMap.SimpleEntry<>((this.velocity.getKey()+(0.01*acceleration.getKey())), (this.velocity.getValue()+(0.01*acceleration.getValue()))); + } + velocity = temp_l2; + position.updateVelocity(velocity); + } + public Velocity(Position position, Onground onground) { + this.onground = onground; + } + public Map.Entry getVelocity() { + return velocity; + } +} \ No newline at end of file