コード例 #1
0
        public shootMup()
        {
            InitializeComponent();

            try
            {
                SuspendLayout();

                // initial setup
                AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
                AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
                ClientSize          = new System.Drawing.Size(1484, 1075);
                Name           = "shootMup";
                Text           = "shootMup";
                DoubleBuffered = true;

                // generate players
                var human = new ShootMPlayer()
                {
                    Name = "You"
                };
                var players = new Player[100];
                for (int i = 0; i < players.Length; i++)
                {
                    players[i] = new SimpleAI()
                    {
                        Name = string.Format("ai{0}", i)
                    }
                }
                ;

                // generate the world
                World = WorldGenerator.Generate(WorldType.Random, PlayerPlacement.Borders, human, ref players);

                // if we are training for AI, then capture telemetry
                World.OnBeforeAction += AITraining.CaptureBefore;
                World.OnAfterAction  += AITraining.CaptureAfter;
                World.OnDeath        += (elem) =>
                {
                    if (elem is Player)
                    {
                        var winners = new List <string>();

                        // capture the winners
                        foreach (var player in players)
                        {
                            winners.Add(string.Format("{0} [{1}]", player.Name, player.Kills));
                        }

                        AITraining.CaptureWinners(winners);
                    }
                };

                UI = new UIHookup(this, World);
            }
            finally
            {
                ResumeLayout(false);
            }
        }
コード例 #2
0
ファイル: World.cs プロジェクト: Onin1/shootmup
        private void PlayerDied(Element element)
        {
            // check for winner/death (element may be any element that can take damage)
            if (element is Player)
            {
                // check how many players are still alive
                int    alive     = 0;
                var    toplayers = new Dictionary <string, int>();
                Player lastAlive = null;
                foreach (var player in Players)
                {
                    toplayers.Add(player.Name, player.Kills);
                    if (!player.IsDead)
                    {
                        alive++;
                        lastAlive = player;
                    }
                }
                Alive = alive;

                var winners = toplayers.OrderByDescending(kvp => kvp.Value).Select(kvp => string.Format("{0} [{1}]", kvp.Key, kvp.Value)).ToArray();

                if (element.Id == Human.Id || (alive == 1 && !Human.IsDead))
                {
                    if (Constants.CaptureAITrainingData)
                    {
                        AITraining.CaptureWinners(winners);
                    }

                    PlayerRank = alive;
                    Menu       = new Finish()
                    {
                        Kills      = Human.Kills,
                        Ranking    = PlayerRank,
                        Winner     = (alive == 1) ? Human.Name : "",
                        TopPlayers = winners
                    };
                    ShowMenu();

                    if (OnEnd != null)
                    {
                        OnEnd();
                    }
                }
                else if (alive == 1)
                {
                    if (Constants.CaptureAITrainingData)
                    {
                        AITraining.CaptureWinners(winners);
                    }

                    Menu = new Finish()
                    {
                        Kills      = Human.Kills,
                        Ranking    = PlayerRank,
                        Winner     = lastAlive.Name,
                        TopPlayers = winners
                    };
                    ShowMenu();

                    if (OnEnd != null)
                    {
                        OnEnd();
                    }
                }
            }
        }