using LOoSE_sLOTS.entities;
using LOoSE_sLOTS.objects;
using LOoSE_sLOTS.Scenes;
using LOoSE_sLOTS.UI;
using LOoSE_sLOTS.Utilities;
using Otter;

namespace LOoSE_sLOTS
{
    class WinScreen : Scene
    {
        public Image loseImage = new Image(Assets.TITLESCREEN);
        private int _xo = 50; //offset because i'm lazy xD
        private int _yo = 30; //offset because i'm lazy xD
        private bool writethiscrapherebecauseconstructorisborked;

        public WinScreen()
        {
            //loseImage.ScaleY = 0.80f;
            AddGraphic(loseImage);
            AddScore();
            AddCoins();
            AddKills();
            AddHealth();
        }

        public override void Update()
        {
            base.Update();
            if (Global.PlayerSession.Controller.Button("R").Pressed)
            {//testing do over (without going back to the menu i believe)
                //Global.GAME.RemoveScene();
                //Global.GAME.AddScene(new Casino());
            }
            if (Global.PlayerSession.Controller.Button("LeftMouseClick").Pressed || Global.PlayerSession.Controller.Button("Start").Pressed)
            {
                //reset all variables.
                //reset globals
                Global.PlayerSpeed = new Speed(200);//lets try 200;
                Global.PlayerX = 0;
                Global.PlayerY = 0;
                Global.PlayerFiredCoinSpeed = 6f;//was 1
                Global.troopSpeed = 1f;
                Global.enemyBulletSpeed = 3f;//was 1
                Global.civilianSpeed = .2f;//was 1
                Global.GiveHimTheMoney = false;
                Global.GaveHimHisMoney = false;
                Global.SkipIntro = false;
                Global.SkipCasinoIntro = false;
                Global.AllowedToCollideWithTruck = false;
                Global.NumberOfSlotMachinesDropped = 0;
                Global.PickupTruckX = 0;
                Global.PickupTruckY = 0;
                Global.PlayerHealth = 100;
                Global.CiviliansKilled = 0;
                Global.kills = 0;
                Global.score = 0;
                //reset statics
                IntroCharacter.IntroX = 0;
                IntroCharacter.IntroY = 0;
                IntroCharacter.IsDodging = false;
                TitleScreen.isTitleAllowed = false;
                Player.canPlayerCollide = true;
                Player.isSpritemapChanged = true;
                RedPickupTruck.IntroX = Global.I_MW / 2;
                RedPickupTruck.IntroY = Global.I_MH / 2;
                SlotMachine.IsDead = false;
                Coin.donebouncing = false;

                Global.GAME.RemoveScene();
                Global.GAME.AddScene(new TitleScreen());
            }
            if (!writethiscrapherebecauseconstructorisborked)//it wasn't the constructor, it was the MW and MH being wrong because the intro screen is only 720/480...
            {
                writethiscrapherebecauseconstructorisborked = true;
                Global.WriteWord(200, 10, "YESSSSSS!", Color.Blue, 2f, 1, Global.GAME.Scene, 0);//shadow first
                Global.WriteWord(200 - 2, 10 - 2, "YESSSSSS!", Color.White, 2f, 1, Global.GAME.Scene, 0);//regular text on top(second)                
                Global.WriteWord(230, 70, "You WON!", Color.Blue, 3f, 1, Global.GAME.Scene, 0, 16);//shadow first
                Global.WriteWord(230 - 2, 70 - 2, "you WON!", Color.White, 3f, 1, Global.GAME.Scene, 0, 16);//regular text on top(second)
                Global.WriteWord(200, 155, "Score:", Color.Blue, 2f, 1, Global.GAME.Scene, 0);//shadow first
                Global.WriteWord(200 - 2, 155 - 2, "Score:", Color.White, 2f, 1, Global.GAME.Scene, 0);//regular text on top(second)
                Global.WriteWord(200, 190, "Kills:", Color.Blue, 2f, 1, Global.GAME.Scene, 0);//shadow first
                Global.WriteWord(200 - 2, 190 - 2, "Kills:", Color.White, 2f, 1, Global.GAME.Scene, 0);//regular text on top(second)
                Global.WriteWord(15, 225, "Civilian Causalties:", Color.Blue, 2f, 1, Global.GAME.Scene, 0);//shadow first
                Global.WriteWord(15 - 2, 225 - 2, "Civilian Causalties:", Color.White, 2f, 1, Global.GAME.Scene, 0);//regular text on top(second)
                Global.WriteWord(200, 270, "Coins:", Color.Blue, 2f, 1, Global.GAME.Scene, 0);//shadow first
                Global.WriteWord(200 - 2, 270 - 2, "Coins:", Color.White, 2f, 1, Global.GAME.Scene, 0);//regular text on top(second)
                Global.WriteWord(50, 350, "Press Enter To Go Back To The Main Menu", Color.Blue, 2f, 1, Global.GAME.Scene, 0);//shadow first
                Global.WriteWord(50 - 2, 350 - 2, "Press Enter To Go Back To The Main Menu", Color.White, 2f, 1, Global.GAME.Scene, 0);//regular text on top(second)
                SoundManager.PlayRequestedSound("_win");
            }
        }

        private void AddScore()
        {
            string author = Global.score.ToString();
            var y = 0;
            for (var i = 0; i < author.Length; i++)
            {
                Add(new Numbers(271 + _xo + y, 186 - _yo, author[i].ToString(), Color.Blue, 2f));
                Add(new Numbers(270 + _xo + y, 185 - _yo, author[i].ToString(), Color.White, 2f));
                y += 17;
            }

        }

        private void AddCoins()
        {
            string author = Global.kills.ToString();
            var y = 0;
            for (var i = 0; i < author.Length; i++)
            {
                Add(new Numbers(271 + _xo + y, 221 - _yo, author[i].ToString(), Color.Blue, 2f));
                Add(new Numbers(270 + _xo + y, 220 - _yo, author[i].ToString(), Color.White, 2f));
                y += 17;
            }
        }

        private void AddKills()
        {
            string author = Global.CiviliansKilled.ToString();
            var y = 0;
            for (var i = 0; i < author.Length; i++)
            {
                Add(new Numbers(271 + _xo + y, 255 - _yo, author[i].ToString(), Color.Blue, 2f));
                Add(new Numbers(270 + _xo + y, 254 - _yo, author[i].ToString(), Color.White, 2f));
                y += 17;
            }
        }
        private void AddHealth()//eyah i know it's not used here. It's used on the win screen bu i'm preessed for time and cant get rid of it but williing to type this message here instead. lol
        {
            string author = Global.PlayerHealth.ToString();
            var y = 0;
            for (var i = 0; i < author.Length; i++)
            {
                Add(new Numbers(271 + _xo + y, 300 - _yo, author[i].ToString(), Color.Blue, 2f));
                Add(new Numbers(270 + _xo + y, 299 - _yo, author[i].ToString(), Color.White, 2f));
                y += 17;
            }
        }
    }
}


