
Counter = public()

function Counter:Create()
  self:Set(0)
  self:SetStep(1)
end


function Counter:SetStep(i)
  self.Step = i
end

function Counter:SetEvent(f)
  self.Event = f
end

function Counter:SetLimt(n)
  self.Limit = n
end

function Counter:Set(n)
  self.N = n
end

function Counter:Get()
  return self.N
end

function Counter:Dec()
  self:Add(-self.Step)
end

function Counter:Inc()
  self:Add(self.Step)
end

function Counter:Sub(n)
  self:Add(-n)
end

function Counter:Add(n)
  self.N = self.N + n
  self:ShowN()
  if self.Limit ~= nil and self.N == self.Limit then
    if self.Event ~= nil then
      self.Event()
    end
  end
end

function Counter:ShowN()
  print(self.N)
end


TextCounter = public(Counter)

function TextCounter:Create()
  self:SetStep(1)
  self:Set(0)
  self.Control = self[1]
  self.DigitCount = 2
end

function TextCounter:ShowN()
  txt = tostring(self.N)
  dif = string.len(txt) - self.DigitCount
  if dif < 0 then
    while (dif < 0) do
      txt = "0"..txt
      dif = dif + 1
    end
  end
  self.Control:SetText(txt)
end

function TextCounter:SetDigitCount(n)
  if (n > 0) then
    self.DigitCount = n
  end
end

function TextCounter:Clear(n)
  self.Control:SetText("")
end

SpriteCounter = public(Counter)

function SpriteCounter:ShowN()
  print("SpriteCounter", self.N)
end
