Class: SnakesAndLadders::Cell

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

Direct Known Subclasses

Portal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location:, players: []) ⇒ Cell

Returns a new instance of Cell.



5
6
7
8
# File 'lib/snakes_and_ladders/cell.rb', line 5

def initialize(location:, players: [])
  @location = location
  @players = players
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



3
4
5
# File 'lib/snakes_and_ladders/cell.rb', line 3

def location
  @location
end

#playersObject (readonly)

Returns the value of attribute players.



3
4
5
# File 'lib/snakes_and_ladders/cell.rb', line 3

def players
  @players
end

Instance Method Details

#enter(player, board) ⇒ Object



14
15
16
17
# File 'lib/snakes_and_ladders/cell.rb', line 14

def enter(player, board)
  players.push(player) && player.position = location
  puts "#{player} is on square #{location}."
end

#exit(player) ⇒ Object



10
11
12
# File 'lib/snakes_and_ladders/cell.rb', line 10

def exit(player)
  players.delete(player)
end