using Otter;

namespace GiraffeRoller.ui
{
    class Lives : Entity
    {
        public Numbers place_units;
        public Numbers place_tens;
        public Numbers place_hundreds;
        public long holdingNumber = 0;
        public int size = 0;
        public bool isUnit = false;
        public bool isTens = false;
        public bool isHundreds = false;
        private int unitsStart = 0;
        private int tensStart = 0;
        private int hunStart = 0;

        private int startingPositionX = -100;
        private int startingPositionY = 462;

        public Lives(int spX)
        {
            startingPositionX = spX;
        }
        public override void Added()
        {
            base.Added();
            Global.GAME.Scene.Add(place_units = new Numbers(startingPositionX + 112, startingPositionY, "0", Color.Yellow));
            Global.GAME.Scene.Add(place_tens = new Numbers(startingPositionX + 104, startingPositionY, " ", Color.Yellow));
            Global.GAME.Scene.Add(place_hundreds = new Numbers(startingPositionX + 96, startingPositionY, " ", Color.Yellow));
        }
        public override void Update()
        {
            base.Update();
            if (holdingNumber != Global.PlayerLives)
            {
                size = (Global.PlayerLives.ToString()).Length;
                if (size == 1) Units();
                if (size == 2) Tens();
                if (size == 3) Hundreds();
                if (isUnit) place_units.c = (Global.PlayerLives.ToString()).Substring(unitsStart, 1);
                else place_units.c = "";
                if (isTens) place_tens.c = (Global.PlayerLives.ToString()).Substring(tensStart, 1);
                else place_tens.c = "";
                if (isHundreds) place_hundreds.c = (Global.PlayerLives.ToString()).Substring(hunStart, 1);
                else place_hundreds.c = "";

                holdingNumber = Global.PlayerLives;
            }
        }
        public void Units()
        {
            isUnit = true; unitsStart = 0;
            isTens = false;
            isHundreds = false;
        }
        public void Tens()
        {
            isUnit = true; unitsStart = 1;
            isTens = true; tensStart = 0;
            isHundreds = false;
        }
        public void Hundreds()
        {
            isUnit = true; unitsStart = 2;
            isTens = true; tensStart = 1;
            isHundreds = true; hunStart = 0;
        }
    }
}


