Newer
Older
JumpingGame / src / main / java / models / JumpGameModel.java
k-fujii on 7 Dec 2021 4 KB modelに対してgetterを追加
package models;

import entities.*;
import entities.modelExtentions.Flags;

import javax.swing.plaf.synth.SynthTextAreaUI;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

//---------------------------------------------------------------
//
public class JumpGameModel implements IModel {

    private Acceleration acceleration;
    private Force force;
    private Mass mass;
    private Move move;
    private Position position;
    private Velocity velocity;
    private Onground onground;

    //---------------------------------------------------------------
    private Time time;
    private Gameover gameover;
    private Clear clear;

    //---------------------------------------------------------------
    private Ground ground;

    //---------------------------------------------------------------
    private double jumpPower = 256;

    //---------------------------------------------------------------
    private Flags flags;

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    //
    public JumpGameModel() {
        ground = new Ground();
        position = new Position(ground);
        onground = new Onground(ground, position);
        velocity = new Velocity(new Pair<>(1d, 0d), position, onground);
        acceleration = new Acceleration(velocity, onground);
        force = new Force(acceleration);
        mass = new Mass(acceleration);
        move = new Move(velocity);
        time = new Time();
        gameover = new Gameover(position);
        clear = new Clear(position);
        flags = new Flags();
    }

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    // getter
    public Flags getFlags() {
        return flags;
    }

    public Pair<Double> getPosition() {
        return position.getValue();
    }

    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.setValue(x);
    }

    public Pair<Double> getAcceleration() {
        return acceleration.getValue();
    }

    public Pair<Double> getMove() {
        return move.getValue();
    }

    public double getMass() {
        return mass.getValue();
    }

    public boolean getClear() {
        return clear.getClear();
    }

    public boolean getGround() {
        return ground.getValue();
    }

    public Pair<Double> getForce() {
        return force.getValue();
    }

    public Pair<Double> getVelocity() {
        return velocity.getValue();
    }

    public boolean getOnground() {
        return onground.getOnground();
    }

    public double getTime() {
        return time.getValue();
    }

    public boolean getGameover() {
        return gameover.getGameover();
    }

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    // ジャンプ
    public void jump() {
        this.move.moveY(jumpPower);
    }

    //---------------------------------------------------------------
    // マイフレーム更新処理
    public void updateGravity(double gravity) {
        this.time.gravity(gravity);
        this.force.gravity(gravity);
//        System.out.println("swapWindow Gravity");
    }

    //---------------------------------------------------------------
    // 地面のフラグ更新
    public void updateGroundFlag() {
        double x = position.getValue().getFirst();

        if (flags.isOpenFlag(x)) ground.openHole();
        if (flags.isCloseFlag(x)) ground.closeHole();

        System.out.print("x: " + x + "/");
        System.out.println("Ground: " + ground.getValue() + "/");
//        System.out.print("Clear: " + clear.getClear() + "/");
//        System.out.println("GameOver: " + gameover.getGameover());

    }

    //---------------------------------------------------------------
    //

    //---------------------------------------------------------------
    //
    private void init() {

    }


    //---------------------------------------------------------------
}