From a5090c2bcf731d7f25aff27aacaeed11e4be4dec Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Sat, 2 Mar 2024 19:18:07 +0100 Subject: [PATCH] improved display --- AppLaser.java | 17 ++++++++++------- Universe.java | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/AppLaser.java b/AppLaser.java index bef31ab..ed18f42 100644 --- a/AppLaser.java +++ b/AppLaser.java @@ -8,8 +8,8 @@ public class AppLaser { int start_i = 3; int start_j = 1; int start_dir = 11; - int universe_width = 6; - int universe_height = 6; + int universe_width = 21; + int universe_height = 20; int firstState_i = start_i; int firstState_j = start_j; @@ -31,7 +31,11 @@ public class AppLaser { universe.addObstacle(2, 4); universe.addObstacle(3, 4); - universe.print(); + + System.out.print("\033[H\033[2J"); + System.out.flush(); + + universe.print(2, 4); int i = 0; while (!universe.isSolved()) { @@ -45,15 +49,14 @@ public class AppLaser { currentState = stack.pop(); universe.reset(currentState); - //System.out.println("\n\n"); - //universe.print(); + universe.print(universe_height + 6, 4); } else { break; } - universe.print(); + //universe.print(universe_height + 6, 4); } System.out.println("\n\n"); - universe.print(); + universe.print(universe_height + 6, 4); } } diff --git a/Universe.java b/Universe.java index 0fde465..43244a1 100644 --- a/Universe.java +++ b/Universe.java @@ -210,10 +210,11 @@ public class Universe { return this.boxes_to_fill == 0; } - public void print() { + public void print(int pos_i, int pos_j) { int i, j; for (i = 0; i < this.height; i++) { for (j = 0; j < this.width; j++) { + System.out.print("\033[" + (i + pos_i) + ";" + (j*2 + pos_j) + "H"); switch (this.grid[i][j]) { case -1: System.out.printf(" X");