Class: Pacman::Arcade::Position

Inherits:
Data
  • Object
show all
Defined in:
lib/pacman/arcade/position.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#colObject (readonly)

Returns the value of attribute col

Returns:

  • (Object)

    the current value of col



5
6
7
# File 'lib/pacman/arcade/position.rb', line 5

def col
  @col
end

#rowObject (readonly)

Returns the value of attribute row

Returns:

  • (Object)

    the current value of row



5
6
7
# File 'lib/pacman/arcade/position.rb', line 5

def row
  @row
end

Instance Method Details

#distance_sq(other) ⇒ Object



10
11
12
# File 'lib/pacman/arcade/position.rb', line 10

def distance_sq(other)
  ((row - other.row)**2) + ((col - other.col)**2)
end

#step(direction) ⇒ Object



6
7
8
# File 'lib/pacman/arcade/position.rb', line 6

def step(direction)
  Position.new(row: row + direction.dy, col: col + direction.dx)
end