using Otter;

namespace GiraffeRoller.ui
{
    class PlayerHealthDisplay : Entity
    {
        public Health place_units;
        public Health place_tens;
        public Health place_hundreds;
        public Health place_thousands;
        public Health place_tenThousands;
        public long holdingNumber = 0;
        public int size = 0;
        public bool isUnit = false;
        public bool isTens = false;
        public bool isHundreds = false;
        public bool isThousands = false;
        public bool isTenThousands = false;
        private int unitsStart = 0;
        private int tensStart = 0;
        private int hunStart = 0;
        private int thouStart = 0;
        private int tenThouStart = 0;

        private int startingPositionX;
        private int startingPositionY;

        public PlayerHealthDisplay(int spX, int spY)
        {
            startingPositionX = spX;
            startingPositionY = spY;
        }
        public override void Added()
        {
            base.Added();
            Global.GAME.Scene.Add(place_units = new Health(startingPositionX + 112, startingPositionY, "0", Color.Yellow));
            Global.GAME.Scene.Add(place_tens = new Health(startingPositionX + 104, startingPositionY, " ", Color.Yellow));
            Global.GAME.Scene.Add(place_hundreds = new Health(startingPositionX + 96, startingPositionY, " ", Color.Yellow));
            Global.GAME.Scene.Add(place_thousands = new Health(startingPositionX + 88, startingPositionY, " ", Color.Yellow));
            Global.GAME.Scene.Add(place_tenThousands = new Health(startingPositionX + 80, startingPositionY, " ", Color.Yellow));
        }
        public override void Update()
        {
            base.Update();
            if (holdingNumber != Global.PlayerHealth)
            {
                size = (Global.PlayerHealth.ToString()).Length;
                if (size == 1) Units();
                if (size == 2) Tens();
                if (size == 3) Hundreds();
                if (size == 4) Thousands();
                if (size == 5) TenThousands();
                if (isUnit) place_units.c = (Global.PlayerHealth.ToString()).Substring(unitsStart, 1);
                else place_units.c = "";
                if (isTens) place_tens.c = (Global.PlayerHealth.ToString()).Substring(tensStart, 1);
                else place_tens.c = "";
                if (isHundreds) place_hundreds.c = (Global.PlayerHealth.ToString()).Substring(hunStart, 1);
                else place_hundreds.c = "";
                if (isThousands) place_thousands.c = (Global.PlayerHealth.ToString()).Substring(thouStart, 1);
                else place_thousands.c = "";
                if (isTenThousands) place_tenThousands.c = (Global.Score.ToString()).Substring(tenThouStart, 1);
                else place_tenThousands.c = "";

                holdingNumber = Global.PlayerHealth;
            }
        }
        public void Units()
        {
            isUnit = true; unitsStart = 0;
            isTens = false;
            isHundreds = false;
            isThousands = false;
            isTenThousands = false;
        }
        public void Tens()
        {
            isUnit = true; unitsStart = 1;
            isTens = true; tensStart = 0;
            isHundreds = false;
            isThousands = false;
            isTenThousands = false;
        }
        public void Hundreds()
        {
            isUnit = true; unitsStart = 2;
            isTens = true; tensStart = 1;
            isHundreds = true; hunStart = 0;
            isThousands = false;
            isTenThousands = false;
        }
        public void Thousands()
        {
            isUnit = true; unitsStart = 3;
            isTens = true; tensStart = 2;
            isHundreds = true; hunStart = 1;
            isThousands = true; thouStart = 0;
            isTenThousands = false;
        }
        public void TenThousands()
        {
            isUnit = true; unitsStart = 4;
            isTens = true; tensStart = 3;
            isHundreds = true; hunStart = 2;
            isThousands = true; thouStart = 1;
            isTenThousands = true; tenThouStart = 0;
        }
    }
}


