Added setting file manipulator class to launcher package.

Contains getters, setters, setDefaultSettings method in case of failure
of parseSettings method (currently not implemented).
This commit is contained in:
François Autin 2021-05-28 00:50:57 +02:00
parent 809c9e5be7
commit b52bbb506a
No known key found for this signature in database
GPG Key ID: 24025429AC559B7C

155
src/launcher/Settings.java Normal file
View File

@ -0,0 +1,155 @@
package launcher;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Settings {
private class Player {
private int controller_id;
private String character;
private int color;
public Player(int cid, String ch, int col) {
controller_id = cid;
character = ch;
color = col;
}
protected int getController_id() {
return controller_id;
}
protected void setController_id(int controller_id) {
this.controller_id = controller_id;
}
protected String getCharacter() {
return character;
}
protected void setCharacter(String character) {
this.character = character;
}
protected int getColor() {
return color;
}
protected void setColor(int color) {
this.color = color;
}
}
private FileInputStream f_is;
private int width, height, r_x, r_y, rounds;
private boolean fullscreen;
private Player p1, p2;
public Settings() throws Exception {
try {
f_is = new FileInputStream("game.set");
} catch (FileNotFoundException e) {
File f = new File("game.set");
f.createNewFile();
} finally {
f_is = new FileInputStream("game.set");
}
try {
parseSettings();
} finally {
setDefaultSettings();
}
}
private void parseSettings() throws Exception {
//TODO: parseSettings() (Needs settings syntax fixed)
}
public void setSettings() throws Exception {
//TODO: parseSettings() (Needs settings syntax fixed)
}
private void setDefaultSettings() {
width = 800;
height = 600;
r_x = 4;
r_y = 3;
rounds = 3;
fullscreen = false;
p1 = new Player(0, "base", 0);
p2 = new Player(0, "base", 0);
}
protected FileInputStream getF_is() {
return f_is;
}
protected int getWidth() {
return width;
}
protected int getHeight() {
return height;
}
protected int getR_x() {
return r_x;
}
protected int getR_y() {
return r_y;
}
protected int getRounds() {
return rounds;
}
protected boolean isFullscreen() {
return fullscreen;
}
protected Player getP1() {
return p1;
}
protected Player getP2() {
return p2;
}
protected void setF_is(FileInputStream f_is) {
this.f_is = f_is;
}
protected void setWidth(int width) {
this.width = width;
}
protected void setHeight(int height) {
this.height = height;
}
protected void setR_x(int r_x) {
this.r_x = r_x;
}
protected void setR_y(int r_y) {
this.r_y = r_y;
}
protected void setRounds(int rounds) {
this.rounds = rounds;
}
protected void setFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
}
protected void setP1(Player p1) {
this.p1 = p1;
}
protected void setP2(Player p2) {
this.p2 = p2;
}
}