Example #1
0
        public override void EndGame()
        {
            MVP.SetText("Tutorial completed");
            MVP.Show();
            HEADS[key_player].OnDie -= trigger_die_restart;
            //phase = Phases.ENDGAME;

            if (ApplicationRunning)
            {
                new Thread(() => {
                    Thread.CurrentThread.Name = "EndGame";
                    int endtick = Tick + 180;
                    SpinWait.SpinUntil(() => Tick > endtick || !ApplicationRunning);


                    TutorialActive = false;
                    start_round();
                    Clear();
                    world.Clear();

                    bot.Remove();
                    bot1.Remove();

                    Neural_Network.Neat n = new Neural_Network.Neat();
                    n.SetupGenZero();
                    n.AddKey();

                    IKey.UpdateAll();

                    Program.Map.StartGame();
                }).Start();
            }
        }
Example #2
0
        public Tutorial(World world)
        {
            Orbits     = Empty;
            this.world = world;
            key_player = ActiveKeys[0];

            trigger_die_restart = () => { if (phase != Phases.ENDROUND)
                                          {
                                              EndRound();
                                          }
            };
            HEADS[key_player].OnDie += trigger_die_restart;

            Standard.Add(new Orbit(.1f, .2f, 1f / 13));
            Standard.Add(new Orbit(.367f, .2f, 1f / 13));
            Standard.Add(new Orbit(.633f, .2f, 1f / 13));
            Standard.Add(new Orbit(.9f, .2f, 1f / 13));
            Standard.Add(new Orbit(2f / 9, .5f, 1f / 13));
            Standard.Add(new Orbit(.5f, .5f, 1f / 13));
            Standard.Add(new Orbit(7f / 9, .5f, 1f / 13));
            Standard.Add(new Orbit(.1f, .8f, 1f / 13));
            Standard.Add(new Orbit(.633f, .8f, 1f / 13f));
            Standard.Add(new Orbit(.9f, .8f, 1f / 13));

            new Thread(() => {
                Thread.CurrentThread.Name = "Tutorial_Manager";
                MVP.SetText("Tutorial");
                MVP.Hide();
                SpinWait.SpinUntil(() => step == 1 || !ApplicationRunning);
                step  = 0;
                stage = 2;
                EndRound();

                SpinWait.SpinUntil(() => step == 23 || !ApplicationRunning);
                step  = 0;
                stage = 3;
                EndRound();

                SpinWait.SpinUntil(() => step > 1 || !ApplicationRunning);
                step  = 0;
                stage = 4;
                EndRound();

                SpinWait.SpinUntil(() => step == 4 || !ApplicationRunning);
                step  = 0;
                stage = 5;
                EndRound();

                SpinWait.SpinUntil(() => step == 15 || !ApplicationRunning);
                step        = 0;
                stage       = 6;
                bot1.OnDie += () => step++;
                EndRound();

                SpinWait.SpinUntil(() => step == 13 || !ApplicationRunning);
                step  = 0;
                stage = 7;
                EndGame();
            }).Start();
        }
Example #3
0
 public override void EndRound()
 {
     MVP.SetText($"Stage {stage-1}/6");
     MVP.Flash();
     phase = Phases.ENDROUND;
     if (ApplicationRunning)
     {
         new Thread(() => {
             Thread.CurrentThread.Name = "EndRound";
             int endtick = Tick + 180;
             SpinWait.SpinUntil(() => Tick > endtick || !ApplicationRunning);
             StartRound();
         }).Start();
     }
 }
Example #4
0
        private void window_keydown(object sender, KeyEventArgs e)
        {
            if (keydown.Contains(e.KeyCode) || e.KeyCode == Keys.NumLock || e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.Menu)
            {
                return;
            }
            else
            {
                keydown.Add(e.KeyCode);
            }

            Keys ekey = e.KeyCode;

            if (e.KeyCode == Keys.Delete)
            {
                ekey = Keys.Decimal;
            }
            else if (e.KeyCode == Keys.Insert)
            {
                ekey = Keys.NumPad0;
            }
            else if (e.KeyCode == Keys.Clear)
            {
                ekey = Keys.NumPad5;
            }

            else if (e.KeyCode == Keys.F2)
            {
                ContrastMode = !ContrastMode;
                return;
            }
            else if (e.KeyCode == Keys.F3)
            {
                if (state == States.NEWGAME && Neat.All.Count < 24)
                {
                    OpenFileDialog dialog = new OpenFileDialog();
                    dialog.Filter           = "Bot files (*.bot)|*.bot|All files (*.*)|*.*";
                    dialog.RestoreDirectory = true;

                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        List <byte> bytes = new List <byte>(File.ReadAllBytes(dialog.FileName));
                        Neat.remove(bytes, 8);

                        Neat n = Neat.decompile(bytes);
                        n.SetupGenZero();
                        n.AddKey();

                        IKey.UpdateAll();
                        Map.SetMaxPoints();

                        // Set color
                        Program.HEADS[n.Key].color = n.color.GetValueOrDefault(Entities.Head.GenerateColor());
                    }
                }
                return;
            }
            else if (e.KeyCode == Keys.F1)
            {
                if (state != States.NEWGAME)
                {
                    return;
                }
                if (ActiveKeys.Count > 0)
                {
                    new AI(ActiveKeys[ActiveKeys.Count - 1]);
                    MVP.Flash($"AI added to {HEADS[ActiveKeys[ActiveKeys.Count - 1]].DisplayKey}");
                    HEADS[ActiveKeys[ActiveKeys.Count - 1]].DisplayKey = "AI";
                }
                return;
            }
            else if (e.KeyCode == Keys.F4 && !e.Alt)
            {
                if (state == States.NEWGAME)
                {
                    if (Neat.All.Count > 0)
                    {
                        Neat toRemove = Neat.All.Last();
                        toRemove.Remove();
                        IKey.UpdateAll();
                    }
                    Map.SetMaxPoints();
                }
                return;
            }
            else if (e.KeyCode == Keys.F9 && e.Alt)
            {
                if (ActiveKeys.Count == 0 || InactiveKeys.Count == 0)
                {
                    return;
                }

                HEADS[InactiveKeys[0]].Reward(0, ActiveKeys[0]);
                HEADS[ActiveKeys[0]].Die();
                return;
            }
            else if (e.KeyCode == Keys.F10)
            {
                if (SyncUpdate)
                {
                    SyncUpdate = false;
                    UpdateThread.Stop();
                    NeuralThread.Stop();
                    StartAsyncUpdate();
                }
                else
                {
                    SyncUpdate = true;
                    UpdateThread.Start();
                    NeuralThread.Start();
                }
                return;
            }
            else if (e.KeyCode == Keys.F7)
            {
                SlowMo = true;
                return;
            }
            else if (e.KeyCode == Keys.F8)
            {
                SpeedMo = true;
                return;
            }
            else if (e.KeyCode == Keys.F11)
            {
                FullScreen = !FullScreen;
                if (FullScreen)
                {
                    Width           = Screen.PrimaryScreen.Bounds.Width;
                    FormBorderStyle = FormBorderStyle.None;
                    WindowState     = FormWindowState.Maximized;
                    Cursor.Hide();
                }
                else
                {
                    Width           = 1024;
                    Height          = 600;
                    FormBorderStyle = FormBorderStyle.Sizable;
                    WindowState     = FormWindowState.Normal;
                    Cursor.Show();
                }
                return;
            }

            else if (e.KeyCode == Keys.F12)
            {
                if (!e.Alt)
                {
                    if (map is BotArena)
                    {
                        List <byte> bytes = new List <byte>();
                        bytes.AddRange(((BotArena)map).GetGeneration());
                        foreach (Neat bot in ((BotArena)map).bots)
                        {
                            bytes.AddRange(Neat.compile(bot));
                        }

                        SaveFileDialog dialog = new SaveFileDialog();
                        dialog.Filter           = "Bot files (*.bot)|*.bot|All files (*.*)|*.*";
                        dialog.RestoreDirectory = true;

                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            File.WriteAllBytes(dialog.FileName, bytes.ToArray());
                        }
                    }
                    else if (ActiveKeys.Count == 0)
                    {
                        Cursor.Show();
                        OpenFileDialog dialog = new OpenFileDialog();
                        dialog.Filter           = "Bot files (*.bot)|*.bot|All files (*.*)|*.*";
                        dialog.RestoreDirectory = true;

                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            List <byte> bytes = new List <byte>(File.ReadAllBytes(dialog.FileName));

                            BotArena arena = new BotArena(BotArena.Type.MAX_POINTS);
                            arena.SetGeneration(bytes);
                            map = arena;

                            while (bytes.Count > 0)
                            {
                                arena.bots.Add(Neat.decompile(bytes));
                            }

                            arena.AddBots(false);
                            Map.StartGame();

                            Ingame = true;
                            state  = States.INGAME;
                        }
                        if (FullScreen)
                        {
                            Cursor.Hide();
                        }
                    }
                }
                else if (state == States.NEWGAME && !TutorialActive)
                {
                    if (ActiveKeys.Count != 1)
                    {
                        return;
                    }
                    TUTO           = new Tutorial(Map);
                    TutorialActive = true;
                    Map.StartGame();
                    if (SyncUpdate)
                    {
                        NeuralThread.Start();
                    }
                }
                return;
                // trigger tutorial
            }
            else if (e.KeyCode == Keys.F6)
            {
                if (ActiveKeys.Count != 0)
                {
                    return;
                }

                BotArena arena = new BotArena(7, BotArena.Type.MAX_POINTS);                 /// <   -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

                map = arena;
                arena.AddBots(false);
                Map.StartGame();

                Ingame = true;
                state  = States.INGAME;

                return;
                // trigger bot arena
            }
            else if (e.KeyCode == Keys.F5)
            {
                if (state != States.NEWGAME)
                {
                    return;
                }
                switch (Gamemode)
                {
                case Gamemodes.CLASSIC:
                    MVP.SetText("Red chaos");
                    Gamemode = Gamemodes.CHAOS_RED;
                    foreach (Head head in HEADS.Values)
                    {
                        head.NewColor(true);
                    }
                    break;

                case Gamemodes.CHAOS_RED:
                    MVP.SetText("Rainbow chaos");
                    Gamemode = Gamemodes.CHAOS_RAINBOW;
                    foreach (Head head in HEADS.Values)
                    {
                        head.NewColor();
                    }
                    break;

                case Gamemodes.CHAOS_RAINBOW:
                    MVP.SetText("King of the hill");
                    foreach (Head head in HEADS.Values)
                    {
                        head.NewColor(false);
                    }
                    Map.MaxOrbs = 7;
                    Gamemode    = Gamemodes.KING_OF_THE_HILL;
                    break;

                case Gamemodes.KING_OF_THE_HILL:
                    MVP.SetText("Hidden");
                    Map.MaxOrbs = 8;
                    Gamemode    = Gamemodes.HIDDEN;
                    break;

                case Gamemodes.HIDDEN:
                    MVP.SetText("Yeet Mode");
                    Gamemode       = Gamemodes.YEET_MODE;
                    Map.blastSpawn = BlastSpawn.RARE;
                    break;

                case Gamemodes.YEET_MODE:
                    MVP.SetText("Classic");
                    Map.MaxOrbs = 255;
                    Gamemode    = Gamemodes.CLASSIC;
                    break;
                }

                UpdateColors?.Invoke();
                return;
            }

            switch (state)
            {
            case States.NEWGAME:
                //add new player
                if (e.KeyCode == Keys.Enter && ActiveKeys.Count > 0)                           // (re)start game
                {
                    if (e.Shift)
                    {
                        Map.ResumeGame();
                    }
                    else
                    {
                        Map.StartGame();
                    }
                    if (SyncUpdate)
                    {
                        NeuralThread.Start();
                    }
                    Ingame = true;
                    state  = States.INGAME;
                }
                else if (e.KeyCode == Keys.Escape)                             // clear all keys
                {
                    HashSet <Neat> NeatCopy = new HashSet <Neat>(Neat.All);
                    foreach (Neat neat in NeatCopy)
                    {
                        neat.Remove();
                    }
                    HashSet <Head> HeadCopy = new HashSet <Head>(HEADS.Values);
                    foreach (Head head in HeadCopy)
                    {
                        head.Remove();
                    }
                    Map.MaxPoints = 0;
                    Leader        = Keys.None;
                }
                else if (0 <= e.KeyValue && e.KeyValue < 256)                             //add key
                {
                    lock (ActiveLock) {
                        if (ActiveKeys.Contains(ekey))
                        {
                            HEADS[ekey].Remove();
                        }
                        else
                        {
                            if (HEADSOnPause.ContainsKey(ekey))
                            {
                                HEADS.Add(ekey, new Head(HEADSOnPause[ekey]));
                            }
                            else
                            {
                                HEADS.Add(ekey, new Head(ekey));
                            }
                            ActiveKeys.Add(ekey);
                            Map.SetMaxPoints();
                        }
                    }
                    IKey.UpdateAll();
                }
                break;

            case States.INGAME:
                if (e.KeyCode == Keys.Escape)                           //pause game
                {
                    ApplicationPause();
                }
                else if (ActiveKeys.Contains(ekey))                             //default action
                {
                    HEADS[ekey].Action();
                }
                break;

            case States.PAUSED:
                if (e.KeyCode == Keys.Escape)                           // unpause
                {
                    state  = States.INGAME;
                    Ingame = true;
                    if (SyncUpdate)
                    {
                        UpdateThread.Start();
                        NeuralThread.Start();
                    }
                    else
                    {
                        StartAsyncUpdate();
                    }
                    VisualThread.Start();
                    //ForcePaused = false;
                }
                else if (e.KeyCode == Keys.Enter)                             // let players join
                {
                    HEADSOnPause.Clear();
                    foreach (KeyValuePair <Keys, Head> player in HEADS)
                    {
                        HEADSOnPause.Add(player.Key, player.Value);
                    }
                    Map.EndGame();
                    Map.Clear();
                    Map.phase = Phases.NONE;
                    state     = States.NEWGAME;
                    MVP.Show("Prepare!");
                    lock (ActiveLock) foreach (Keys key in ActiveKeys)
                        {
                            HEADS[key].v = IVector.Up;
                        }
                    Ingame = false;
                    VisualThread.Start();
                    if (SyncUpdate)
                    {
                        UpdateThread.Start();
                    }
                    else
                    {
                        StartAsyncUpdate();
                    }
                }
                break;
            }
        }