Ejemplo n.º 1
0
        private void beetle_Click(object sender, EventArgs e)
        {
            Beetle hittedBeetle = new Beetle(new Point());

            foreach (Beetle beetle in Beetles)
            {
                if (beetle.Picture.Name == (sender as PictureBox).Name)
                {
                    hittedBeetle = beetle;
                    break;
                }
            }

            Task.Run(() => BeetleExplode(hittedBeetle));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Makes the beetle crush after clicking it
        /// </summary>
        private void BeetleExplode(Beetle beetle)
        {
            beetle.isDead = true;

            Action action = () => { beetle.Picture.Image = Properties.Resources.dead_beetle; };

            BeginInvoke(action);

            Thread.Sleep(400);

            action = () => {
                beetle.Picture.Dispose();
                Beetles.Remove(beetle);
            };
            BeginInvoke(action);
        }