package models; import entities.*; import entities.player.*; import java.io.BufferedReader; import java.io.File; 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 = 32; //--------------------------------------------------------------- private ArrayList<Integer> flagTimings; // フラグ切り替え private boolean tileType = true; private int flag = 0; //--------------------------------------------------------------- //--------------------------------------------------------------- // public JumpGameModel() { ground = new Ground(); position = new Position(new Pair<>(640d, 480d), ground); onground = new Onground(ground, position); velocity = new Velocity(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); flagTimings = loadText(); } //--------------------------------------------------------------- //--------------------------------------------------------------- // getter public boolean getTileType() { return tileType; } public Position getPosition() { return position; } public ArrayList<Integer> getFlags() { return flagTimings; } public Ground getGround() { return ground; } //--------------------------------------------------------------- //--------------------------------------------------------------- // ジャンプ 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"); } //--------------------------------------------------------------- //--------------------------------------------------------------- // ステージデータの読み込み private ArrayList<Integer> loadText() { ArrayList<Integer> flagTimings = new ArrayList<>(); Path file = Paths.get("resources/stage.txt"); String[] data = new String[1]; try { List<String> lines = Files.readAllLines(file, Charset.forName("Shift-JIS")); for (int i = 0; i < lines.size(); i++) data = lines.get(i).split(","); for (int i = 0; i < data.length; i++) flagTimings.add(Integer.parseInt(data[i])); } catch (IOException e) { System.out.println("Failed to load stage.txt"); } return flagTimings; } //--------------------------------------------------------------- // private void init() { } //--------------------------------------------------------------- }