Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Generation {
- private final File file = new File("src/safeguard.txt");
- private final Scanner sc = new Scanner(System.in);
- private Map<String, Integer> map = new LinkedHashMap<>();
- // Chargement et vérification du fichier de configuration
- public void load() {
- boolean answer;
- System.out.println("Loup-Garou version 1.0");
- System.out.print("\nCharger une sauvegarde ? : ");
- if ((answer = sc.nextBoolean()) == true) {
- if (!file.exists()) {
- System.err.println("\nImpossible de lire le fichier !");
- selection();
- }
- } else selection();
- try {
- final List<String> list = FileUtils.loadContent(file);
- for (String line : list) {
- if (!line.startsWith("//")) {
- String[] args = line.split(": ");
- map.put(args[0], Integer.parseInt(args[1]));
- }
- }
- parse();
- } catch (ConfigurationException e) {
- e.printStackTrace();
- }
- }
- private void selection() {
- int sv, lg;
- System.out.println("\nConfiguration ->");
- System.out.print("\nSimple_Villageois : ");
- sv = sc.nextInt();
- System.out.print("Loup-Garou : ");
- lg = sc.nextInt();
- FileUtils.deleteFile(file);
- FileUtils.save(file, "SIMPLE_VILLAGEOIS: " + sv);
- FileUtils.save(file, "LOUP-GAROU: " + lg);
- }
- // Vérification de la validité de la configuration
- private void parse() throws ConfigurationException {
- if (map.isEmpty()) throw new ConfigurationException("Bad configuration !");
- if (map.get("SIMPLE_VILLAGEOIS") == 0 || map.get("LOUP-GAROU") == 0) {
- throw new ConfigurationException("Wolf or Villager amount cannot be equals to 0 !");
- }
- if (map.get("LOUP-GAROU") >= map.get("SIMPLE_VILLAGEOIS")) {
- throw new ConfigurationException("Wolf amount must be lower than Villager !");
- }
- }
- public Integer get(String key) {
- return map.get(key);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement