package entities.modelExtentions; 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 Flags { private ArrayList<Integer> values = new ArrayList<>(); private int count = 0; //--------------------------------------------------------------- //--------------------------------------------------------------- public Flags() { 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++) values.add(Integer.parseInt(data[i])); for (int v : values) System.out.println(v); } catch (IOException e) { System.out.println("Failed to load stage.txt"); } } //--------------------------------------------------------------- //--------------------------------------------------------------- // getter public ArrayList<Integer> getValues() { return values; } //--------------------------------------------------------------- //--------------------------------------------------------------- // フラグのタイミングと一致しているかをチェック public boolean isFlag(int timing) { for (int flag : values) if (timing == flag) return true; return false; } //--------------------------------------------------------------- // 奇数番目のフラグで穴を開けるフラグを提示する public boolean isOpenFlag(double x) { if (count % 2 != 0) return false; double cx = (double) values.get(count) - 0.5; if (cx <= x) { if (count < values.size() - 1) count++; return true; } return false; } //--------------------------------------------------------------- // 偶数番目のフラグで穴を閉じるフラグを提示する public boolean isCloseFlag(double x) { if (count % 2 == 0) return false; double cx = (double) values.get(count) - 0.5; if (cx <= x + 0.25) { if (count < values.size() - 1) count++; return true; } return false; } }