示例#1
0
        private void timerUpdate_Tick(object sender, EventArgs e)
        {
            player.HandleOutsideClient(this);
            int j = -1;

            if (mediaPlayer.status == "Stopped")
            {
                mediaPlayer.controls.play();
            }

            if (!isGameOver)
            {
                for (int i = monsters.Count - 1; i >= 0; i--)
                {
                    if (player.isCollision(monsters[i]))
                    {
                        timerUpdate.Stop();

                        if (monsters[i].IsBoss == true)
                        {
                            mediaPlayer.URL = ConfigurationManager.AppSettings.Get("musicPath") + "BossFight.mp3";
                            mediaPlayer.controls.play();
                            OpenTrashTalk(i, "Mày đây rồi, thằng khốn! Chạy đâu cho thoát!", "Bố đã làm gì mày đâu?");
                            j = i;
                            break;
                        }
                        else
                        {
                            if (isCorrect >= 0)
                            {
                                if (isCorrect == 1)
                                {
                                    // Init dead.
                                    PictureBox pb = new PictureBox();
                                    pb.BackColor = Color.Transparent;
                                    pb.Image     = Image.FromFile(ConfigurationManager.AppSettings.Get("imgPath_database") + "Monsters/dead.png");
                                    pb.Location  = monsters[i].Location;
                                    pb.SizeMode  = PictureBoxSizeMode.StretchImage;
                                    pb.Size      = size_Normal;
                                    pb.Show();
                                    this.Controls.Add(pb);

                                    monsters.Remove(monsters[i]);

                                    ManageUserAction.UpdateDiamond(ManageUserAction.GetDiamond() + 1);
                                }
                                else
                                {
                                    player.Location = new Point(0, this.ClientSize.Height / 2);
                                    currentHealth  -= 1;
                                }

                                isCorrect = -1;
                                timerUpdate.Start();
                                inFighting = false;
                            }
                            else
                            {
                                inFighting = true;
                                timerQuestion.Start();
                                ChangeFlashCard(questions[currentQuiz].GetFlashCard().Viet, questions[currentQuiz].GetFlashCard().IdCard);

                                pnlQuestion.Show();
                            }
                        }
                    }

                    else if (monsters[i].IsDeath == false)
                    {
                        monsters[i].Move(monsters[i].Cur);

                        if (monsters[i].Y + monsters[i].Size.Height > this.Height)
                        {
                            monsters[i].Cur = Direction.Up;
                        }
                        else if (monsters[i].Y < this.Height / 3)
                        {
                            monsters[i].Cur = Direction.Down;
                        }
                    }
                }

                if (j >= 0 && monsters[j].IsBoss == true)
                {
                    InitFinalRound();
                    isFinalRound = true;
                }

                if (isFinalRound == true)
                {
                    if (isCorrect >= 0)
                    {
                        if (isCorrect == 1)
                        {
                            ManageUserAction.UpdateDiamond(ManageUserAction.GetDiamond() + 1);
                            bullets.Clear();
                            bullets.Add(player.Attack(idWeapon));
                            turn = 1;
                            timerBullet.Start();
                        }
                        else
                        {
                            bullets.Clear();
                            turn = 2;
                            bullets.Add(monsters[0].Attack(idWeapon));
                            timerBullet.Start();
                        }
                        isCorrect = -1;
                        timerUpdate.Start();
                    }
                }


                if (currentHealth > 0)
                {
                    double percent = (((double)currentHealth) / player.Health) * 100;
                    if (pgbHealth.Value != (int)percent)
                    {
                        pgbHealth.Value = (int)percent;
                    }
                }
                else
                {
                    pgbHealth.Value = 0;
                    currentHealth   = 0;
                    isGameOver      = true;
                    isWin           = false;

                    music.URL = ConfigurationManager.AppSettings.Get("musicPath") + "lose1.mp3";
                    music.controls.play();
                }

                lbDiamond.Text = ManageUserAction.GetDiamond().ToString();
                this.Invalidate();
                this.Focus();
            }
            else
            {
                double percent = (((double)currentHealth) / player.Health) * 100;
                if (pgbHealth.Value != (int)percent)
                {
                    pgbHealth.Value = (int)percent;
                }
                btnClose.Visible   = true;
                btnDetails.Visible = true;
                HandleMusicGameOver();
                HandleGameOver();
                timerUpdate.Stop();
            }
        }