using GiraffeRoller.entities;
using GiraffeRoller.ui;
using GiraffeRoller.Utility;
using Otter;

namespace GiraffeRoller.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 giraffeRoller = "YOU WIN!!!! yes yes yes";
                    var zzz = 0;
                    var ff = .1f;
                    for (var b = 0; b < giraffeRoller.Length; b++)
                    {
                        Add(new Numbers(30 + zzz, 150, giraffeRoller[b].ToString(), Color.Lerp(Color.Yellow, Color.Red, ff), .5f, 4f));
                        Add(new Numbers(30 + zzz, 150, giraffeRoller[b].ToString(), Color.Lerp(Color.Yellow, Color.Red, ff), .5f, 4f, 1, .5f));
                        Add(new Numbers(30 + zzz, 150, giraffeRoller[b].ToString(), Color.Lerp(Color.Yellow, Color.Red, ff), .5f, 4f, 1, .3f));
                        Add(new Numbers(30 + zzz, 150, giraffeRoller[b].ToString(), Color.Lerp(Color.Yellow, Color.Red, ff), .5f, 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.Blue, Color.Cyan, f), .1f));
                        Add(new Numbers(250 + y, 300, author[i].ToString(), Color.Lerp(Color.Blue, Color.Cyan, f), .1f, 1, 1, .5f));
                        Add(new Numbers(250 + y, 300, author[i].ToString(), Color.Lerp(Color.Blue, Color.Cyan, f), .1f, 1, 1, .3f));
                        Add(new Numbers(250 + y, 300, author[i].ToString(), Color.Lerp(Color.Blue, Color.Cyan, 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.Blue, Color.Cyan, fq), .1f));
                        Add(new Numbers(370 + yz, 300, score[i].ToString(), Color.Lerp(Color.Blue, Color.Cyan, fq), .1f, 1, 1, .5f));
                        Add(new Numbers(370 + yz, 300, score[i].ToString(), Color.Lerp(Color.Blue, Color.Cyan, fq), .1f, 1, 1, .3f));
                        Add(new Numbers(370 + yz, 300, score[i].ToString(), Color.Lerp(Color.Blue, Color.Cyan, fq), .1f, 1, 1, .1f));
                        yz += 10;
                        fq += .05f;
                    }
                    string author2 = "Giraffes Lost:";
                    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.Red, Color.Black, f2), .1f));
                        Add(new Numbers(250 + y2, 350, author2[i].ToString(), Color.Lerp(Color.Red, Color.Black, f2), .1f, 1, 1, .5f));
                        Add(new Numbers(250 + y2, 350, author2[i].ToString(), Color.Lerp(Color.Red, Color.Black, f2), .1f, 1, 1, .3f));
                        Add(new Numbers(250 + y2, 350, author2[i].ToString(), Color.Lerp(Color.Red, Color.Black, f2), .1f, 1, 1, .1f));
                        y2 += 10;
                        f2 += .05f;
                    }
                    string nogc = Global.NumberOfGiraffesCollected.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.Red, Color.Black, f3f), .1f));
                        Add(new Numbers(440 + y3, 350, nogc[i].ToString(), Color.Lerp(Color.Red, Color.Black, f3f), .1f, 1, 1, .5f));
                        Add(new Numbers(440 + y3, 350, nogc[i].ToString(), Color.Lerp(Color.Red, Color.Black, f3f), .1f, 1, 1, .3f));
                        Add(new Numbers(440 + y3, 350, nogc[i].ToString(), Color.Lerp(Color.Red, 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.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 = 1000;
                    Global.PlayerCurrentAnim = "";
                    Global.Score = 0;
                    Global.PlayerFiredWaterSpeed = 6f;
                    Global.PlayerFakeSpeed = new Speed(100);
                    Global.StopPlayerCharge = false;
                    Global.BossHealth = 10;//was 10
                    Global.WarehouseHealth = 9;//was 9
                    Global.PowerHealth = 7;//was 7
                    Global.WaterHealth = 6;//was 6
                    Global.StuckInLoop = false;
                    Global.Boss = 5000;
                    Global.BossSpeed = new Speed(.5f); //I have no idea what speed this should be...
                    Global.NumberOfGiraffesCollected = 0;
                    Global.EventTwoCanKillPower = false;
                    Global.EventThreeCanKillWarehouse = false;
                    Global.EventFourCanKillBoss = false;
                    Global.TriggerEnd = false;
                    Global.IsPlayerOneAxisReset = false;
                    Global.IsGamePaused = false;
                    Global.wildGiraffeSpeed = .1f;
                    Global.troopSpeed = .1f;
                    Global.enemyBulletSpeed = 3f;
                    Global.IsScreenShake = false;
                    Global.Done = 0;
                    Global.CameraTimer = 3;
                    Global.Drection = Rand.Int(1, 5);
                    Boss.canPlayerCollide = true;
                    Boss.isSpritemapChanged = true;
                    Player.IsJoystickAxisActive = 0;//use a Joystick axis instead of keys
                    Player.RefreshAxisButtons = false;
                    Player.Charging = false;

                    SoundManager.PlayRequestedSound("_bossBoom3", 2f);
                    Global.GAME.RemoveScene();
                    Global.GAME.AddScene(new TitleScreen());
                }
            }
        }
    }
}
