Class: SnakesAndLadders::Portal

Inherits:
Cell
  • Object
show all
Defined in:
lib/snakes_and_ladders/portal.rb

Instance Attribute Summary collapse

Attributes inherited from Cell

#location, #players

Instance Method Summary collapse

Methods inherited from Cell

#exit

Constructor Details

#initialize(location:, destination:) ⇒ Portal

Returns a new instance of Portal.

Raises:

  • (ArgumentError)


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

#destinationObject (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

#typeObject



17
18
19
# File 'lib/snakes_and_ladders/portal.rb', line 17

def type
  location > destination ? :snake : :ladder
end