summaryrefslogtreecommitdiff
path: root/maze_solver.rb
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-04-22 16:37:42 +0200
committerNoah Loomans <noahloomans@gmail.com>2018-04-22 16:37:42 +0200
commitdf356d42954107688b7484b595ff1e33cd70291c (patch)
tree192851916fe75b0f7cb569e90a7e78170fb92875 /maze_solver.rb
parentf5bcd76d2c0420e61425f3cfd000f6a86445cb62 (diff)
Move TUI to commands to seperate file
Diffstat (limited to 'maze_solver.rb')
-rw-r--r--maze_solver.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/maze_solver.rb b/maze_solver.rb
index e5fd87e..5633515 100644
--- a/maze_solver.rb
+++ b/maze_solver.rb
@@ -1,5 +1,6 @@
require_relative 'pos'
require_relative 'maze'
+require_relative 'tui'
class MazeSolver
attr_reader :maze
@@ -15,26 +16,27 @@ class MazeSolver
def solve!()
if ENV["DEBUG"] == "visual"
- print "\e[?1049h" # Save the state of the terminal
- print "\e[2J" # Clear the screen
- print "\e[0;0H" # Move the cursor to 0, 0
- print "\n [ \e[1;35mSolving maze...\e[0m ]\n\n" # Print some nice graphics
- print "\e[s" # Save the cursor position
+ TUI::Screen.save
+ TUI::Screen.reset
+ print "\n [ #{TUI::Color.purple}Solving maze...#{TUI::Color.reset} ]\n\n"
+ TUI::Cursor.save
+
end
while @stack.last != @end_pos
step()
if ENV["DEBUG"] == "visual"
- print "\e[u" # Restore the cursor position
+ TUI::Cursor.restore
print @maze.to_s(" ", @stack)
print "\n\n"
puts " Stack size: #{@stack.length}"
+ puts " Current algorithm: Depth-first search"
end
end
if ENV["DEBUG"] == "visual"
- print "\e[?1049l" # Restore the state of the terminal
+ TUI::Screen.restore
end
end