Example #1
0
        private void RemoveBird(BirdTimer BirdTimer)
        {
            if (BirdTimer != null)
            {
                FlyingBirds.Remove(BirdTimer);

                BirdTimer.Stop();
                BirdTimer.BirdBox.Dispose();
                BirdTimer.Dispose();
            }
        }
Example #2
0
        public void AddNewBird(string Direction, string Bird)
        {
            BirdTimer BirdTimer = new BirdTimer();

            BirdTimer.BirdBox = NewBirdBox(Direction, Bird);

            BirdTimer.Interval = Extensions.GetRandomInterval();
            BirdTimer.Tick    += new EventHandler(BirdTimer_Tick);

            this.Controls.Add(BirdTimer.BirdBox);

            FlyingBirds.Add(BirdTimer);

            BirdTimer.Start();
        }
Example #3
0
        private void BirdTimer_Tick(object sender, EventArgs e)
        {
            /*
             * + xử lý toạ con chim bay
             * + trạng thái của chim
             * + thêm mới chim nếu con cũ chết
             * + điều kiện để chim chết
             */
            BirdTimer BirdTimer = (BirdTimer)sender;

            if (BirdTimer != null)
            {
                int XLocation = 0;
                int YLocation = 0;

                if (BirdTimer.BirdBox.Status == "Alive")
                #region Code xử lý nếu chim vẫn sống
                {
                    if (BirdTimer.BirdBox.Location.X + BirdTimer.BirdBox.Size.Width < 0)
                    {
                        // Nếu con chim bay ra phía ngoài màn hình -> xoá
                        XLocation = BirdTimer.BirdBox.Location.X - Extensions.GetRandomNumber();
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else
                    {
                        // Nếu không thì cho con chim bay về bên trái
                        XLocation = BirdTimer.BirdBox.Location.X - Extensions.GetRandomNumber();
                    }

                    if (BirdTimer.BirdBox.Location.Y + BirdTimer.BirdBox.Size.Height > this.Height - 50)
                    {
                        // Nếu con chim bay lên cao quá so với màn hình -> xoá
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else if (BirdTimer.BirdBox.Location.Y + BirdTimer.BirdBox.Size.Height - 50 < 0)
                    {
                        // Nếu chim bay dưới màn hình -> xoá
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else
                    {
                        // Nếu không thì con chim bay ngẫu nhiên lên trên, xuống dưới
                        YLocation = BirdTimer.BirdBox.Location.Y + Extensions.GetLimitedRandomNumber(-10, 10);
                    }

                    // Truyền toạ độ mới
                    BirdTimer.BirdBox.Location = new Point(XLocation, YLocation);
                }
                #endregion

                else if (BirdTimer.BirdBox.Status == "Dead")
                #region Code xử lý nếu con chim bị bắn trúng (hoặc chết)
                {
                    if (BirdTimer.BirdBox.Location.X + BirdTimer.BirdBox.Size.Width < 0)
                    {
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else
                    {
                        XLocation = BirdTimer.BirdBox.Location.X - Extensions.GetLimitedRandomNumber(17, 23);
                    }

                    if (BirdTimer.BirdBox.Location.Y + BirdTimer.BirdBox.Size.Height > this.Height)
                    {
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else
                    {
                        YLocation = BirdTimer.BirdBox.Location.Y + Extensions.GetLimitedRandomNumber(20, 25);
                    }

                    BirdTimer.BirdBox.Location = new Point(XLocation, YLocation);
                }
                #endregion

                else if (BirdTimer.BirdBox.Status == "Downed")
                {
                    AddNewBird("", "");
                    RemoveBird(BirdTimer);
                }
            }
        }
Example #4
0
        private void BirdTimer_Tick(object sender, EventArgs e)
        {
            BirdTimer BirdTimer = (BirdTimer)sender;

            if (BirdTimer != null)
            {
                int XLocation = 0;
                int YLocation = 0;

                if (BirdTimer.BirdBox.Status == "Alive")
                {
                    if (BirdTimer.BirdBox.Location.X + BirdTimer.BirdBox.Size.Width < 0)
                    {
                        //XLocation = this.Width;
                        XLocation = BirdTimer.BirdBox.Location.X - Extensions.GetRandomNumber();
                        BirdTimer.BirdBox.Status = "Downed";
                    }
                    else
                    {
                        XLocation = BirdTimer.BirdBox.Location.X - Extensions.GetRandomNumber();
                    }

                    if (BirdTimer.BirdBox.Location.Y + BirdTimer.BirdBox.Size.Height > this.Height - 50)
                    {
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else if (BirdTimer.BirdBox.Location.Y + BirdTimer.BirdBox.Size.Height - 50 < 0)
                    {
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else
                    {
                        YLocation = BirdTimer.BirdBox.Location.Y + Extensions.GetLimitedRandomNumber(-8, 8);
                    }

                    //this.SuspendLayout();
                    BirdTimer.BirdBox.Location = new Point(XLocation, YLocation);
                    //this.ResumeLayout();
                }
                else if (BirdTimer.BirdBox.Status == "Dead")
                {
                    if (BirdTimer.BirdBox.Location.X + BirdTimer.BirdBox.Size.Width < 0)
                    {
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else
                    {
                        XLocation = BirdTimer.BirdBox.Location.X - Extensions.GetLimitedRandomNumber(5, 10);
                    }

                    if (BirdTimer.BirdBox.Location.Y + BirdTimer.BirdBox.Size.Height > this.Height)
                    {
                        BirdTimer.BirdBox.Status = "Downed";
                        return;
                    }
                    else
                    {
                        YLocation = BirdTimer.BirdBox.Location.Y + Extensions.GetLimitedRandomNumber(10, 15);
                    }

                    //this.SuspendLayout();
                    BirdTimer.BirdBox.Location = new Point(XLocation, YLocation);
                    //this.ResumeLayout();
                }
                else if (BirdTimer.BirdBox.Status == "Downed")
                {
                    RemoveBird(BirdTimer);
                    AddNewBird("", "");
                }
            }
        }