Commit 5e81412

mo khan <mo@mokhan.ca>
2019-08-05 19:08:05
make clear work on posix and add sleep
1 parent 3cfbf44
Changed files (1)
src/Q9/MovingRobot.java
@@ -155,6 +155,10 @@ public class MovingRobot extends Robot {
 
       clear();
       System.out.println(MovingRobot.printGrid(r1, r2));
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
+      }
     }
 
     System.out.println("=== Question 9 ===");
@@ -163,10 +167,13 @@ public class MovingRobot extends Robot {
     System.out.println(String.format("R2 Route: [%s]", r2.printMoves()));
   }
 
-  public static final void clear() {
+  public static void clear() {
     try {
       if (System.getProperty("os.name").contains("Windows")) Runtime.getRuntime().exec("cls");
-      else Runtime.getRuntime().exec("clear");
+      else {
+        System.out.print("\033[H\033[2J");
+        System.out.flush();
+      }
     } catch (Exception e) {
     }
   }