Newer
Older
JumpingGame / src / main / java / models / JumpingGameModel.java
package models;

import entities.*;
import entities.modelExtentions.Stage;

public class JumpingGameModel implements IModel{
    private Gameover gameover;
    private Time time;
    private Onground onground;
    private Ground ground;
    private Clear clear;
    private Position position;
    private Velocity velocity;
    private Movey movey;
    private Movex movex;
    private Acceleration acceleration;
    private Mass mass;
    private Force force;

    private Stage stage; //added

    public JumpingGameModel() {
        gameover = new Gameover();
        time = new Time();
        onground = new Onground();
        ground = new Ground(onground);
        clear = new Clear();
        position = new Position(gameover,clear,onground,ground);
        velocity = new Velocity(position,onground);
        movey = new Movey(velocity);
        movex = new Movex(velocity);
        acceleration = new Acceleration(velocity,onground);
        mass = new Mass(acceleration);
        force = new Force(acceleration);
        stage = new Stage(); // added
    }
    public void gravity(double y) {
        this.force.gravity(y);
        this.time.gravity(y);
    }
    public void closeHole() {
        this.ground.closeHole();
    }
    public void openHole() {
        this.ground.openHole();
    }
    public void jump(double y2) {
        this.movey.jump(y2);
    }
    public void run(double x2) {
        this.movex.run(x2);
    }
    public void setMass(double x) {
        this.mass.setMass(x);
    }
    public Pair<Double> getAcceleration() {
        return acceleration.getValue();
    }
    public double getMovex() {
        return movex.getValue();
    }
    public double getMass() {
        return mass.getValue();
    }
    public boolean getClear() {
        return clear.getValue();
    }
    public boolean getGround() {
        return ground.getValue();
    }
    public Pair<Double> getForce() {
        return force.getValue();
    }
    public Pair<Double> getVelocity() {
        return velocity.getValue();
    }
    public Pair<Double> getPosition() {
        return position.getValue();
    }
    public boolean getOnground() {
        return onground.getValue();
    }
    public double getTime() {
        return time.getValue();
    }
    public double getMovey() {
        return movey.getValue();
    }
    public boolean getGameover() {
        return gameover.getValue();
    }

    // added
    public Stage getStage() {
        return stage;
    }
    // added
    public void updateGroundFlag() {
        double x = position.getValue().getLeft();

        if (stage.isOpenFlag(x)) ground.openHole();
        if (stage.isCloseFlag(x)) ground.closeHole();
    }
}