require "colorize"

class Tile
  attr_reader :bomb, :neighbours, :revealed

  def initialize
    @bomb = false
    @flagged = false
    @revealed = false

    @neighbours = 0
  end

  def add_neighbour
    @neighbours += 1
  end

  def flag
    @flagged = !@flagged unless @revealed
  end

  def reveal
    @revealed = true unless @flagged
  end

  def set_bomb
    @bomb = true
  end

  def to_s
    return "F".colorize(:red) if @flagged
    return "." unless @revealed
    bomb ? "X" : (@neighbours == 0 ? " " : @neighbours.to_s.colorize(:blue))
  end
end