Class: GridBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grid_size, initial_state = []) ⇒ GridBuilder

Returns a new instance of GridBuilder.



5
6
7
8
# File 'lib/generate_game.rb', line 5

def initialize(grid_size, initial_state = [])
  @grid_size = grid_size
  @state = initial_state
end

Instance Attribute Details

#grid_sizeObject (readonly)

Returns the value of attribute grid_size.



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

def grid_size
  @grid_size
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#create_gridObject



10
11
12
13
14
15
16
17
18
# File 'lib/generate_game.rb', line 10

def create_grid
  grid_size.times do
    state << []
  end

  state.each do |row|
    grid_size.times { row << Cell.new }
  end
end