Class: GooseGame::Cell::Base
- Inherits:
-
Object
- Object
- GooseGame::Cell::Base
- Defined in:
- lib/goose_game/cell.rb
Instance Attribute Summary collapse
-
#gameboard ⇒ Object
readonly
Returns the value of attribute gameboard.
-
#num ⇒ Object
readonly
Returns the value of attribute num.
Instance Method Summary collapse
- #call(player, dice) ⇒ Object
-
#initialize(num, gameboard) ⇒ Base
constructor
A new instance of Base.
- #to_s ⇒ Object
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
#gameboard ⇒ Object (readonly)
Returns the value of attribute gameboard.
4 5 6 |
# File 'lib/goose_game/cell.rb', line 4 def gameboard @gameboard end |
#num ⇒ Object (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_s ⇒ Object
21 22 23 |
# File 'lib/goose_game/cell.rb', line 21 def to_s @tokens.join(". ") end |