diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-04-22 00:48:54 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-04-22 00:48:54 +0200 |
commit | 70834814edf45cfe68d9bb65a21523e02c80f926 (patch) | |
tree | 66f04f8726067dc256e9af3503cfc2a5d7f9cc88 | |
parent | 4c7bb3b5086f3eef81d3c02716b9f10945ced585 (diff) |
Make the visual debug really fancy
-rw-r--r-- | main.rb | 19 | ||||
-rw-r--r-- | maze.rb | 4 |
2 files changed, 20 insertions, 3 deletions
@@ -13,9 +13,26 @@ class MazeGenerator @visitedCells = [@currentPos] @stack = [Pos.new(rand(@maze.width), rand(@maze.height))] + 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;35mGenerating maze...\e[0m ]\n\n" # Print some nice graphics + print "\e[s" # Save the cursor position + end + + print "\e[s" if ENV["DEBUG"] == "visual" + while !@stack.empty? - puts @maze if ENV["DEBUG"] == "visual" step() + if ENV["DEBUG"] == "visual" + print "\e[u" # Restore the cursor position + print @maze.to_s(" ") + end + end + + if ENV["DEBUG"] == "visual" + print "\e[?1049l" # Restore the state of the terminal end end @@ -53,7 +53,7 @@ class Maze end end - def to_s + def to_s(prefix='') drawingField = Array.new(@height * 2 + 1) { " " * (@width * 2 + 1) } @v_walls.each_index do |x| @@ -76,6 +76,6 @@ class Maze end end - drawingField.join("\n") + drawingField.map { |line| prefix + line }.join("\n") end end |