Class: Mazinator::Maze

Inherits:
Object
  • Object
show all
Defined in:
lib/mazinator/maze.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#colsObject (readonly)

Returns the value of attribute cols.



5
6
7
# File 'lib/mazinator/maze.rb', line 5

def cols
  @cols
end

#exitObject

Returns the value of attribute exit.



4
5
6
# File 'lib/mazinator/maze.rb', line 4

def exit
  @exit
end

#mazeObject

Returns the value of attribute maze.



4
5
6
# File 'lib/mazinator/maze.rb', line 4

def maze
  @maze
end

#rowsObject (readonly)

Returns the value of attribute rows.



5
6
7
# File 'lib/mazinator/maze.rb', line 5

def rows
  @rows
end

#startObject

Returns the value of attribute start.



4
5
6
# File 'lib/mazinator/maze.rb', line 4

def start
  @start
end

Instance Method Details



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