Merge remote-tracking branch 'origin/master'

This commit is contained in:
no 2021-06-10 12:40:58 +02:00
commit 264f53f88d
5 changed files with 136 additions and 442 deletions

1
game.set Normal file
View File

@ -0,0 +1 @@
{"game":[{"character2":"ken","character1":"ryu","fullscreen":"true","stage":"default","width":"1920","rounds":"5","height":"1080"}]}

View File

@ -1,165 +1,112 @@
package configuration; package configuration;
import java.util.Random; import java.io.*;
import org.json.simple.*;
import org.json.simple.parser.*;
public class Config { public class Config {
// tester a la main (okay normalement mais ajouter des test) public int width, height, rounds;
public static void main(String[] args) { public boolean fullscreen;
int[] tempfortest = { 0, 2, 1, 1 }; // {arene/nb_joueur/perso1/perso2} 0=alatoire public String stage;
config(tempfortest); public String p1, p2;
public Config() throws FileNotFoundException {
parse();
} }
// les variable a configurer public void parse() throws FileNotFoundException {
// sel1 pour savoir si on a deja selectionner le joueur 1
public static String arene, perso1, perso2; // initialize the parser
public static int nb_joueur; JSONParser jsonP = new JSONParser();
private static boolean sel1 = false; try {
// read the json document
JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("game.set"));
/* // to print all values
* fonction config qui prend en entre un tableau d'entier chaque case // System.out.println(jsonO.values());
* correspondant a une variable, et ne retourne rien mais modifie la valeur des
* variables par des fonctions annexes
*/
private static void config(int[] tab) { // isolate the "test" part and print it
int i = 0; // String test = (String) jsonO.get("test");
while (i < tab.length) { // System.out.println("ceci est un test :" + test);
switch (i) {
case 0:
SelArene(tab[i]);
i++;
break;
case 1: JSONArray game = (JSONArray) jsonO.get("game");
NbJoueur(tab[i]); JSONObject settings = (JSONObject) game.get(0);
i++;
break;
case 2: // print a case of this element
SelPerso(tab[i]); stage = (String) settings.get("stage");
i++;
break;
case 3: // nb players selection
SelPerso(tab[i]); /* JSONArray nb_players = (JSONArray) jsonO.get("nb_players");
i++; System.out.println("nb_player : " + nb_players.get(1)); */
break;
/*
* case 4: ?
*/
default: // character selection
System.out.println("ERROR OUT OF BOUNDS CONFIG ARRAY"); p1 = (String) settings.get("character1");
i = tab.length; p2 = (String) settings.get("character2");
break;
} height = Integer.parseInt((String) settings.get("height")); // String to int
} width = Integer.parseInt((String) settings.get("width"));
System.out.println(arene + " " + nb_joueur + " " + perso1 + " " + perso2 + " " + sel1);
// fullscreen
String fs = (String) settings.get("fullscreen");
if (fs.equals("true")) {
fullscreen = true;
} else fullscreen = false;
// rounds
String temprounds = (String) settings.get("rounds");
switch (temprounds) {
case "1": rounds = 1;
case "3": rounds = 3;
case "5": rounds = 5;
default: rounds = 1;
} }
/* // button selection
* fonction SelArene prend un entier en parametre et permet de choisir l'arene /* JSONArray allButton = (JSONArray) jsonO.get("button");
* du jeu System.out.println(allButton);
*/
private static void SelArene(int s) { String up = (String) allButton.get(0);
switch (s) { System.out.println("button for up is : " + up); */
case 0:
SelArene(random(1, 2));
break;
case 1:
arene = "arene1.png";
break;
case 2: } catch (FileNotFoundException e) {
arene = "arene2.png"; e.printStackTrace();
break; } catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
default:
System.out.println("ERROR ARENE INEXISTANTE");
} }
} }
/* @SuppressWarnings("unchecked")
* fonction NbJoueur prend un entier en parametre et permet de determiner si un public void write(int width, int height, int rounds, boolean fullscreen, String character1, String character2, String stage) throws Exception {
* bot sera necessaire
*/
private static void NbJoueur(int s) { JSONObject metafile = new JSONObject();
switch (s) { JSONArray array = new JSONArray();
case 1:
nb_joueur = 1;
break;
case 2: JSONObject set = new JSONObject();
nb_joueur = 2; set.put("width", Integer.toString(width));
break; set.put("height", Integer.toString(height));
default: set.put("rounds", Integer.toString(rounds));
System.out.println("ERROR NUMBER OF PLAYER"); set.put("fullscreen", Boolean.toString(fullscreen));
} set.put("character1", character1);
set.put("character2", character2);
set.put("stage", stage);
} array.add(set);
/* metafile.put("game", array);
* fonction SelArene prend un entier en parametre et permet de choisir le
* personnage en fonction du joueur
*/
private static void SelPerso(int s) { try (FileWriter file = new FileWriter("game.set", false)) {
if (sel1 == false) { file.write(metafile.toJSONString());
switch (s) { file.close();
case 0:
SelPerso(random(1, 2));
break;
case 1:
perso1 = "perso1.png";
sel1 = true;
break;
case 2:
perso1 = "perso2.png";
sel1 = true;
break;
default:
System.out.println("ERROR PERSO INEXISTANT");
}
} else if (sel1 == true) {
switch (s) { } catch (FileNotFoundException e) {
case 0: e.printStackTrace();
SelPerso(random(1, 2)); } catch (IOException e) {
break; e.printStackTrace();
case 1:
perso2 = "perso1.png";
sel1 = false;
if (perso1 == perso2) {
perso2 = "perso1_swapcolor.png";
}
break;
case 2:
perso2 = "perso2.png";
sel1 = false;
if (perso1 == perso2) {
perso2 = "perso2_swapcolor.png";
}
break;
default:
System.out.println("ERROR PERSO INEXISTANT");
}
} else {
System.out.println("ERROR SELECTION PLAYER");
} }
} }
// fonction nombre aleatoire entre deux borne
private static int random(int min, int max) {
Random random = new Random();
int value = random.nextInt(max - 1 + min) + min;
return value;
}
} }

View File

@ -1,75 +0,0 @@
package configuration;
import java.io.*;
import org.json.simple.*;
import org.json.simple.parser.*;
public class JsonToJava {
public static void main(String args[]) {
JsonRecover();
}
private static void JsonRecover() {
// initialize the parser
JSONParser jsonP = new JSONParser();
try {
// read the json document
JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("src/configuration/config.json"));
// to print all values
// System.out.println(jsonO.values());
// isolate the "test" part and print it
// String test = (String) jsonO.get("test");
// System.out.println("ceci est un test :" + test);
// arena selection
// select an element on the list
JSONArray arena = (JSONArray) jsonO.get("arena");
// print a case of this element
System.out.println("arena : " + arena.get(1));
// nb players selection
JSONArray nb_players = (JSONArray) jsonO.get("nb_players");
System.out.println("nb_player : " + nb_players.get(1));
// character selection
JSONArray character1 = (JSONArray) jsonO.get("character1");
System.out.println("players 1 : " + character1.get(1));
JSONArray character2 = (JSONArray) jsonO.get("character2");
System.out.println("players 2 : " + character2.get(1));
// resolution
JSONArray resolution = (JSONArray) jsonO.get("resolution");
// resolution string " width x heigth"
JSONObject reso = (JSONObject) resolution.get(1);
String heightStr = (String) reso.get("height");
int height = Integer.parseInt(heightStr); // String to int
String widthStr = (String) reso.get("width");
int width = Integer.parseInt(widthStr);
System.out.println("heigth : " + height + " width : " + width);
// button selection
JSONArray allButton = (JSONArray) jsonO.get("button");
System.out.println(allButton);
String up = (String) allButton.get(0);
System.out.println("button for up is : " + up);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}

View File

@ -1,55 +0,0 @@
{
"arena": [
"random",
"arena1.png",
"arena2.png"
],
"nb_players": [
"1",
"2"
],
"character1": [
"random",
"character1.png",
"character2.png"
],
"character2": [
"random",
"character1.png",
"character1_swapcolor.png",
"character2.png",
"character2_swapcolor.png"
],
"resolution": [
{
"width": "800",
"height": "600"
},
{
"width": "1280",
"height": "1024"
},
{
"width": "1680",
"height": "1050"
},
{
"width": "1920",
"height": "1080"
},
{
"persoWidth": "800",
"persoHeight": "600"
}
],
"button": [
"UP",
"DOWN",
"RIGTH",
"LEFT",
"A",
"B",
"X",
"Y"
]
}

View File

@ -3,162 +3,38 @@ package launcher;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.HashMap;
import configuration.*;
public class Settings { public class Settings {
private class Player { private Config config;
private int controller_id; public Settings() {
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 String stage;
private Player p1, p2;
public Settings() throws Exception {
try { try {
f_is = new FileInputStream("game.set"); config = new Config();
} catch (FileNotFoundException e) { } catch (Exception e) {
File f = new File("game.set"); e.printStackTrace();
f.createNewFile(); System.exit(1);
} 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 { public void setSettings() throws Exception {
//TODO: parseSettings() (Needs settings syntax fixed) HashMap<String, Object> set = Launcher.pointer.getArraysettings();
} int width = (Integer) set.get("width");
int height = (Integer) set.get("height");
int rounds = (Integer) set.get("rounds");
boolean fullscreen = (Boolean) set.get("fullscreen");
String character1 = (String) set.get("character1");
String character2 = (String) set.get("character2");
String stage = (String) set.get("stage");
private void setDefaultSettings() { try {
width = 800; config.write(width, height, rounds, fullscreen, character1, character2, stage);
height = 600; } catch (Exception e) {
r_x = 4; e.printStackTrace();
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 String getStage() {
return stage;
}
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 setStage(String stage) {
this.stage = stage;
}
protected void setP1(Player p1) {
this.p1 = p1;
}
protected void setP2(Player p2) {
this.p2 = p2;
} }
} }