class MineField::Point

Attributes

content[R]
coordinate_x[R]
coordinate_y[R]
opened[RW]

Public Class Methods

new(map, x, y, content) click to toggle source
# File lib/mine_field/point.rb, line 6
def initialize(map, x, y, content)
  @coordinate_x = x
  @coordinate_y = y
  @content = content
  @opened = false
  @map = map
end

Public Instance Methods

neighbors() click to toggle source
# File lib/mine_field/point.rb, line 14
def neighbors
  items = []

  ((@coordinate_x - 1)..(@coordinate_x + 1)).each do |x|
    ((@coordinate_y - 1)..(@coordinate_y + 1)).each do |y|
      point = @map.get_point(x, y)
      items.push(point) unless point.nil?
    end
  end

  items
end
to_s() click to toggle source
# File lib/mine_field/point.rb, line 27
def to_s
  if @opened
    if @content == MINE_CHARACTER
      MINE_CHARACTER
    else
      neighbors.select {|p| p.content == MINE_CHARACTER}.count.to_s
    end
  else
    NOT_OPENED_CHARACTER
  end
end