From de8f816d6674750b6cd88a930684e366e9b320f5 Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Sun, 3 Mar 2024 20:26:09 +0100 Subject: [PATCH] ouais --- .gitignore | 2 +- AppLaser.java | 33 ++++++++++++++++++++++++++++++++- Universe.java | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2054c98..9c54898 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.class *.jar -saves/*.yaml \ No newline at end of file +saves/*.txt \ No newline at end of file diff --git a/AppLaser.java b/AppLaser.java index fe7df31..37c6a69 100644 --- a/AppLaser.java +++ b/AppLaser.java @@ -2,6 +2,8 @@ import java.util.Scanner; import java.time.Instant; +import java.io.File; +import java.io.FileWriter; public class AppLaser { public static void main(String [] args) { @@ -63,7 +65,9 @@ public class AppLaser { System.out.println("\n1 - Resize universe"); System.out.println("2 - Change start position"); System.out.println("3 - Add obstacle"); - System.out.println("4 - Resolve"); + System.out.println("4 - Save universe"); + System.out.println("5 - Load universe"); + System.out.println("6 - Resolve"); System.out.println("0 - Exit"); // prompt the user @@ -126,6 +130,33 @@ public class AppLaser { break; case 4: + System.out.print("\nHow do you want to name your universe : "); + String name = ""; + + while (name.isEmpty()) { + name = scanner.nextLine(); + } + + try { + File file = new File("./saves/" + name + ".txt"); + + file.createNewFile(); + + FileWriter writer = new FileWriter("./saves/" + name + ".txt"); + + for (int i = 0; i < universe_height + 2; i++) { + for (int j = 0; j < universe_width + 2; j++) { + writer.write(universe.grid[i][j]); + } + writer.write("\n"); + } + writer.close(); + } + catch (Exception e) {} + + break; + + case 6: boolean display_progress = false, display_regress = false; System.out.println("\n1 - display progress and regress"); diff --git a/Universe.java b/Universe.java index e13590f..cee4fe1 100644 --- a/Universe.java +++ b/Universe.java @@ -3,7 +3,7 @@ public class Universe { // Atributes - private int[][] grid; + public int[][] grid; private int width, height; private int boxes_to_fill;