using Otter;
using PpbbffttMiningHa.entities;
using PpbbffttMiningHa.ui;

namespace PpbbffttMiningHa.scenes
{
    class WinScreen : Scene
    {
        public Image titleImage = new Image(Assets.TITLE_IMAGE);
        private bool one = true;
        private bool boss;

        public WinScreen()
        {
            titleImage.ScaleY = 0.80f;
            AddGraphic(titleImage);

            Add(new Title(150, -460));
            Add(new PausePerson());
        }

        public override void Update()
        {
            base.Update();
            if (!IsGroupPaused(0))
            {
                if (one)
                {
                    if (!boss)
                    {
                        boss = true;
                        //SoundManager.PlayRequestedSound("_bossIWantToGoOnTheChair");
                    }
                    one = false;
                    string lol = "YOU WIN!!!! yes yes yes";
                    var zzz = 0;
                    var ff = .1f;
                    for (var b = 0; b < lol.Length; b++)
                    {
                        Add(new Numbers(30 + zzz, 150, lol[b].ToString(), Color.Lerp(Color.FromBytes(238, 227, 98, 255), Color.FromBytes(70, 35, 0, 255), ff), .1f, 4f));
                        Add(new Numbers(30 + zzz, 150, lol[b].ToString(), Color.Lerp(Color.FromBytes(238, 227, 98, 255), Color.FromBytes(70, 35, 0, 255), ff), .1f, 4f, 1, .5f));
                        Add(new Numbers(30 + zzz, 150, lol[b].ToString(), Color.Lerp(Color.FromBytes(238, 227, 98, 255), Color.FromBytes(70, 35, 0, 255), ff), .1f, 4f, 1, .3f));
                        Add(new Numbers(30 + zzz, 150, lol[b].ToString(), Color.Lerp(Color.FromBytes(238, 227, 98, 255), Color.FromBytes(70, 35, 0, 255), ff), .1f, 4f, 1, .1f));
                        zzz += 45;
                        ff += .05f;
                    }
                    string author = "Score:";
                    var f = .1f;
                    var y = 0;
                    for (var i = 0; i < author.Length; i++)
                    {
                        Add(new Numbers(250 + y, 300, author[i].ToString(), Color.Lerp(Color.Yellow, Color.Gold, f), .1f));
                        Add(new Numbers(250 + y, 300, author[i].ToString(), Color.Lerp(Color.Yellow, Color.Gold, f), .1f, 1, 1, .5f));
                        Add(new Numbers(250 + y, 300, author[i].ToString(), Color.Lerp(Color.Yellow, Color.Gold, f), .1f, 1, 1, .3f));
                        Add(new Numbers(250 + y, 300, author[i].ToString(), Color.Lerp(Color.Yellow, Color.Gold, f), .1f, 1, 1, .1f));
                        y += 10;
                        f += .05f;
                    }
                    string score = Global.Score.ToString().Trim();
                    var fq = .1f;
                    var yz = 0;
                    for (var i = 0; i < score.Length; i++)
                    {
                        Add(new Numbers(370 + yz, 300, score[i].ToString(), Color.Lerp(Color.Yellow, Color.Gold, fq), .1f));
                        Add(new Numbers(370 + yz, 300, score[i].ToString(), Color.Lerp(Color.Yellow, Color.Gold, fq), .1f, 1, 1, .5f));
                        Add(new Numbers(370 + yz, 300, score[i].ToString(), Color.Lerp(Color.Yellow, Color.Gold, fq), .1f, 1, 1, .3f));
                        Add(new Numbers(370 + yz, 300, score[i].ToString(), Color.Lerp(Color.Yellow, Color.Gold, fq), .1f, 1, 1, .1f));
                        yz += 10;
                        fq += .05f;
                    }
                    string author2 = "Gems Collected:";
                    var f2 = .1f;
                    var y2 = 0;
                    for (var i = 0; i < author2.Length; i++)
                    {
                        Add(new Numbers(250 + y2, 350, author2[i].ToString(), Color.Lerp(Color.FromBytes(3, 153, 209, 255), Color.Black, f2), .1f));
                        Add(new Numbers(250 + y2, 350, author2[i].ToString(), Color.Lerp(Color.FromBytes(3, 153, 209, 255), Color.Black, f2), .1f, 1, 1, .5f));
                        Add(new Numbers(250 + y2, 350, author2[i].ToString(), Color.Lerp(Color.FromBytes(3, 153, 209, 255), Color.Black, f2), .1f, 1, 1, .3f));
                        Add(new Numbers(250 + y2, 350, author2[i].ToString(), Color.Lerp(Color.FromBytes(3, 153, 209, 255), Color.Black, f2), .1f, 1, 1, .1f));
                        y2 += 10;
                        f2 += .05f;
                    }
                    string nogc = Global.TotalGemsCollected.ToString().Trim();
                    var f3f = .1f;
                    var y3 = 0;
                    for (var i = 0; i < nogc.Length; i++)
                    {
                        Add(new Numbers(440 + y3, 350, nogc[i].ToString(), Color.Lerp(Color.FromBytes(3, 153, 209, 255), Color.Black, f3f), .1f));
                        Add(new Numbers(440 + y3, 350, nogc[i].ToString(), Color.Lerp(Color.FromBytes(3, 153, 209, 255), Color.Black, f3f), .1f, 1, 1, .5f));
                        Add(new Numbers(440 + y3, 350, nogc[i].ToString(), Color.Lerp(Color.FromBytes(3, 153, 209, 255), Color.Black, f3f), .1f, 1, 1, .3f));
                        Add(new Numbers(440 + y3, 350, nogc[i].ToString(), Color.Lerp(Color.FromBytes(3, 153, 209, 255), Color.Black, f3f), .1f, 1, 1, .1f));
                        y3 += 10;
                        f3f += .05f;
                    }
                    var pressStart = "Press Enter to Go Back To Main Menu!";
                    var a = 0;
                    for (var b = 0; b < pressStart.Length; b++)
                    {
                        Add(new Numbers(200 + a, 420, pressStart[b].ToString(), Color.White));
                        Add(new Numbers(200 + a, 420, pressStart[b].ToString(), Color.White, .1f, 1, 1, .5f));
                        Add(new Numbers(200 + a, 420, pressStart[b].ToString(), Color.White, .1f, 1, 1, .3f));
                        Add(new Numbers(200 + a, 420, pressStart[b].ToString(), Color.White, .1f, 1, 1, .1f));
                        a += 10;
                    }
                }

                if (Global.PlayerSession.Controller.Button("P1Start").Pressed)
                {
                    //refresh ALL the Globals and PUblic static variables. 
                    Global.PlayerOneHighScoreName = "";
                    Global.PlayerOneOldHighScoreName = "";
                    Global.PlayerOneHighScoreSet = false;
                    Global.PlayerOneHighScoreIsSet = false;
                    Global.PlayerX = 0.0f;
                    Global.PlayerY = 0.0f;
                    Global.PlayerSpeed = 1.0f;//was 3, seems good though.
                    Global.PlayerLives = 0;//was 2
                    Global.PlayerExtraLifeThreshold = 30000;//starts here. 
                    Global.PlayerHealth = 300;
                    Global.PlayerCurrentAnim = "";
                    Global.Score = 0;
                    Global.IsPlayerOneAxisReset = false;
                    Global.IsGamePaused = false;
                    Global.IsScreenShake = false;
                    Global.Done = 0;
                    Global.CameraTimer = 3;
                    Global.Drection = Rand.Int(1, 5);
                    Global.dirtSpeed = 3f;
                    Global.AlligatorSpeed = 4f;
                    Global.AlligatorHealth = 10;
                    Global.DirtInHand = 0;
                    Global.GemsInHand = 0;
                    Global.HasKey = false;
                    Global.TotalGemsCollected = 0;
                    Global.PrairieDogSpeed = 5f;
                    Global.GhostSpeed = 6f;
                    Global.PrairieDogHealth = 20;
                    Global.GhostHealth = 30;
                    Global.HasTreasure = false;
                    //move on to the next section
                    Global.GAME.RemoveScene();
                    Global.GAME.AddScene(new TitleScreen());
                }
            }
        }
    }
}

