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