Class: GooseGame::Cell::Base

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

Direct Known Subclasses

Bounce, Bridge, Goose, Winning

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num, gameboard) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/goose_game/cell.rb', line 6

def initialize(num, gameboard)
  @num = num.to_i
  @gameboard = gameboard
  @tokens = []
end

Instance Attribute Details

#gameboardObject (readonly)

Returns the value of attribute gameboard.



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

def gameboard
  @gameboard
end

#numObject (readonly)

Returns the value of attribute num.



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

def num
  @num
end

Instance Method Details

#call(player, dice) ⇒ Object



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

def call(player, dice)
  position.tap do |pos|
    player.move(pos)
    @tokens.clear
    @tokens << "#{player} rolls #{dice.d1}, #{dice.d2}"
    @tokens << "#{player} moves from #{player.prev} to #{dest}"
  end
end

#to_sObject



21
22
23
# File 'lib/goose_game/cell.rb', line 21

def to_s
  @tokens.join(". ")
end