Class: SnakesAndLadders::Portal
- Defined in:
- lib/snakes_and_ladders/portal.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
Attributes inherited from Cell
Instance Method Summary collapse
- #enter(player, board) ⇒ Object
-
#initialize(location:, destination:) ⇒ Portal
constructor
A new instance of Portal.
- #type ⇒ Object
Methods inherited from Cell
Constructor Details
#initialize(location:, destination:) ⇒ Portal
Returns a new instance of Portal.
5 6 7 8 9 10 |
# File 'lib/snakes_and_ladders/portal.rb', line 5 def initialize(location:, destination:) @destination = destination super(location: location) raise ArgumentError, "Location and destination can not be equal" if location.equal?(destination) end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
3 4 5 |
# File 'lib/snakes_and_ladders/portal.rb', line 3 def destination @destination end |
Instance Method Details
#enter(player, board) ⇒ Object
12 13 14 15 |
# File 'lib/snakes_and_ladders/portal.rb', line 12 def enter(player, board) puts "#{player} moves to square #{location} and takes a #{type}!" board.move(player, location, destination) end |
#type ⇒ Object
17 18 19 |
# File 'lib/snakes_and_ladders/portal.rb', line 17 def type location > destination ? :snake : :ladder end |