Class: GooseGame::GameBoard

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

Constant Summary collapse

WINNING_CELLS =
[63]
BRIDGE_CELLS =
[6]
GOOSE_CELLS =
[5, 9, 14, 18, 23, 27]

Instance Method Summary collapse

Instance Method Details

#[](n) ⇒ Object



9
10
11
# File 'lib/goose_game/gameboard.rb', line 9

def [](n)
  cells.fetch(n) { Cell::Bounce.new(n, self) }
end

#cellsObject



13
14
15
16
17
18
19
# File 'lib/goose_game/gameboard.rb', line 13

def cells
  @cells ||= (0..FINISH).reduce({}) { |acc, n| acc[n] = Cell::Base.new(n, self); acc }.tap do |cells|
    WINNING_CELLS.each { |n| cells[n] = Cell::Winning.new(n, self) }
    BRIDGE_CELLS.each { |n| cells[n] = Cell::Bridge.new(n, self) }
    GOOSE_CELLS.each { |n| cells[n] = Cell::Goose.new(n, self) }
  end
end