summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-04-21 20:14:21 +0200
committerNoah Loomans <noahloomans@gmail.com>2018-04-21 20:14:21 +0200
commit6be27e99f15c5668f260ef7fe874400e43616c07 (patch)
tree86b84cf0a0f2ade3ee99a3d5efa030fdcb5ddde8
parent6d3752fa1a5ee1b49cabf4de55d1d54b9c720d1a (diff)
Add maze representation
-rw-r--r--main.rb32
1 files changed, 29 insertions, 3 deletions
diff --git a/main.rb b/main.rb
index 133a21f..3f0d701 100644
--- a/main.rb
+++ b/main.rb
@@ -89,9 +89,37 @@ class Maze
@v_walls[pos.x][pos.y] = state
end
end
+
+ def to_s
+ drawingField = Array.new(@height * 2 + 1) { " " * (@width * 2 + 1) }
+
+ @v_walls.each_index do |x|
+ @v_walls[x].each_index do |y|
+ next if @v_walls[x][y] == false
+
+ drawingField[y * 2][x * 2] = "█"
+ drawingField[y * 2 + 1][x * 2] = "█"
+ drawingField[y * 2 + 2][x * 2] = "█"
+ end
+ end
+
+ @h_walls.each_index do |x|
+ @h_walls[x].each_index do |y|
+ next if @h_walls[x][y] == false
+
+ drawingField[y * 2][x * 2] = "█"
+ drawingField[y * 2][x * 2 + 1] = "█"
+ drawingField[y * 2][x * 2 + 2] = "█"
+ end
+ end
+
+ drawingField.join("\n")
+ end
end
class MazeGenerator
+ attr_reader :maze
+
def initialize(width, height)
@maze = Maze.new(width, height)
end
@@ -126,6 +154,4 @@ end
mazeGenerator = MazeGenerator.new(15, 15)
mazeGenerator.generate
-# p mazeGenerator
-# maze = Maze.new(15, 15)
-# p maze.neighbors(Pos.new(0,0))
+puts mazeGenerator.maze