Class: Mazinator::Maze
- Inherits:
-
Object
- Object
- Mazinator::Maze
- Defined in:
- lib/mazinator/maze.rb
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#exit ⇒ Object
Returns the value of attribute exit.
-
#maze ⇒ Object
Returns the value of attribute maze.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#start ⇒ Object
Returns the value of attribute start.
Instance Method Summary collapse
-
#initialize(rows = 10, cols = 10, maze = nil) ⇒ Maze
constructor
def initialize(rows=10, cols=10, maze_generator=Mazinator::MazeGenerator.new).
- #print ⇒ Object
Constructor Details
#initialize(rows = 10, cols = 10, maze = nil) ⇒ Maze
def initialize(rows=10, cols=10, maze_generator=Mazinator::MazeGenerator.new)
8 9 10 11 12 13 14 |
# File 'lib/mazinator/maze.rb', line 8 def initialize(rows=10, cols=10, maze=nil) @rows = rows @cols = cols @maze = maze @start = maze[0,0] @exit = maze[rows-1, cols-1] end |
Instance Attribute Details
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
5 6 7 |
# File 'lib/mazinator/maze.rb', line 5 def cols @cols end |
#exit ⇒ Object
Returns the value of attribute exit.
4 5 6 |
# File 'lib/mazinator/maze.rb', line 4 def exit @exit end |
#maze ⇒ Object
Returns the value of attribute maze.
4 5 6 |
# File 'lib/mazinator/maze.rb', line 4 def maze @maze end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
5 6 7 |
# File 'lib/mazinator/maze.rb', line 5 def rows @rows end |
#start ⇒ Object
Returns the value of attribute start.
4 5 6 |
# File 'lib/mazinator/maze.rb', line 4 def start @start end |
Instance Method Details
#print ⇒ Object
16 17 18 19 20 |
# File 'lib/mazinator/maze.rb', line 16 def print board = Array.new(@rows*3) { Array.new(@cols*3,'X') } @maze.each{ |cell| put_cell_on_board(cell, board) } board.each{|row| puts row.join('')} end |