Exemplo n.º 1
0
        private void dispatBot(object sender, EventArgs e)
        {
            double d = Math.Sqrt(Math.Pow(Canvas.GetTop(bot) - Canvas.GetTop(player), 2) + Math.Pow(Canvas.GetLeft(bot) - Canvas.GetLeft(player), 2));

            if (statusbot == 1)
            {
                bot.Source = new BitmapImage(new Uri(@"\res\walk2.png", UriKind.Relative));
                statusbot  = 2;
            }
            else if (statusbot == 2)
            {
                bot.Source = new BitmapImage(new Uri(@"\res\walk1.png", UriKind.Relative));
                statusbot  = 1;
            }
            if (d < 120)
            {
                if (keyK == true)
                {
                    botHP.Value -= 20;
                    Canvas.SetLeft(bot, Canvas.GetLeft(bot) + 50);
                    if (botHP.Value <= 0)
                    {
                        MainWindow.MN += 100; //add money
                        label1.Content = "$  " + MainWindow.MN;
                        Canvas.SetLeft(bot, Canvas.GetLeft(bot) + 1000);
                        timerbot.Stop();
                    }
                }
            }
            if (d <= 90 && Canvas.GetLeft(player) >= 0)
            {
                playerHP.Value = playerHP.Value - 10;
                Canvas.SetLeft(player, Canvas.GetLeft(player) - 50);
                if (playerHP.Value <= 0)
                {
                    string sql = "UPDATE `logingame1` SET `price`='" + MainWindow.MN + "'   WHERE username ='******'";

                    MySqlConnection con = new MySqlConnection("host=localhost;user=project;password=123456;database=gameshop");
                    MySqlCommand    cmd = new MySqlCommand(sql, con);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    final.result = "GAME OVER";
                    final fn = new final();
                    fn.Show();
                    this.Hide();
                    timer.Stop();
                    timerbot.Stop();
                    timerbot1.Stop();
                    timerbot2.Stop();
                    timerbot3.Stop();
                    timerkunai.Stop();
                }
            }


            Random rd = new Random();
            {
                if (rd.Next(10) >= 8)
                {
                    Canvas.SetLeft(bot, Canvas.GetLeft(bot) + 20);
                }
                else if (Canvas.GetLeft(bot) >= Canvas.GetLeft(player))
                {
                    Canvas.SetLeft(bot, Canvas.GetLeft(bot) - 20);
                }
            }
        }
Exemplo n.º 2
0
        private void dispatBoss(object sender, EventArgs e)
        {
            double d = Math.Sqrt(Math.Pow(Canvas.GetTop(boss) - Canvas.GetTop(player), 2) + Math.Pow(Canvas.GetLeft(boss) - Canvas.GetLeft(player), 2));

            if (d >= 200)
            {
                if (statusBoss == 1)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (2).png", UriKind.Relative));
                    statusBoss  = 2;
                }
                else if (statusBoss == 2)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (3).png", UriKind.Relative));
                    statusBoss  = 3;
                }
                else if (statusBoss == 3)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (4).png", UriKind.Relative));
                    statusBoss  = 4;
                }
                else if (statusBoss == 4)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (5).png", UriKind.Relative));
                    statusBoss  = 5;
                }
                else if (statusBoss == 5)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (6).png", UriKind.Relative));
                    statusBoss  = 6;
                }
                else if (statusBoss == 6)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (7).png", UriKind.Relative));
                    statusBoss  = 7;
                }
                else if (statusBoss == 7)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (8).png", UriKind.Relative));
                    statusBoss  = 8;
                }
                else if (statusBoss == 8)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (9).png", UriKind.Relative));
                    statusBoss  = 9;
                }
                else if (statusBoss == 9)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (10).png", UriKind.Relative));
                    statusBoss  = 10;
                }
                else if (statusBoss == 10)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\idle 2 (1).png", UriKind.Relative));
                    statusBoss  = 1;
                }
            }
            else if (d <= 199)
            {
                if (statusBoss == 1)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss2.png", UriKind.Relative));
                    statusBoss  = 2;
                }
                else if (statusBoss == 2)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss3.png", UriKind.Relative));
                    statusBoss  = 3;
                }
                else if (statusBoss == 3)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss4.png", UriKind.Relative));
                    statusBoss  = 4;
                }
                else if (statusBoss == 4)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss5.png", UriKind.Relative));
                    statusBoss  = 5;
                }
                else if (statusBoss == 5)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss6.png", UriKind.Relative));
                    statusBoss  = 6;
                }
                else if (statusBoss == 6)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss7.png", UriKind.Relative));
                    statusBoss  = 7;
                }
                else if (statusBoss == 7)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss8.png", UriKind.Relative));
                    statusBoss  = 8;
                }
                else if (statusBoss == 8)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss9.png", UriKind.Relative));
                    statusBoss  = 9;
                }
                else if (statusBoss == 9)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss10.png", UriKind.Relative));
                    statusBoss  = 10;
                }
                else if (statusBoss == 10)
                {
                    boss.Source = new BitmapImage(new Uri(@"\res\Boss1.png", UriKind.Relative));
                    statusBoss  = 1;
                }
            }


            if (d < 100)
            {
                if (keyK == true)
                {
                    BossHP.Value -= 20;
                    Canvas.SetLeft(boss, Canvas.GetLeft(boss) + 50);
                    if (BossHP.Value <= 0)
                    {
                        MainWindow.MN += 100; //add money
                        label1.Content = "$  " + MainWindow.MN;
                        Canvas.SetLeft(boss, Canvas.GetLeft(boss) + 1000);
                        Winner wn = new Winner();
                        wn.Show();
                        this.Hide();
                        timer.Stop();
                        timerKunai.Stop();
                        timerBoss.Stop();
                    }
                }
            }
            if (d < 100 && Canvas.GetLeft(player) >= 0)
            {
                playerHP.Value -= 20;
                Canvas.SetLeft(player, Canvas.GetLeft(player) - 50);
                if (playerHP.Value <= 0)
                {
                    final.result = "GAME OVER";
                    final fn = new final();
                    fn.Show();
                    this.Hide();
                    timer.Stop();
                    timerKunai.Stop();
                    timerBoss.Stop();
                }
            }


            Random rn = new Random();
            {
                if (rn.Next(10) >= 8)
                {
                    Canvas.SetLeft(boss, Canvas.GetLeft(boss) + 20);
                }
                else if (Canvas.GetLeft(boss) >= Canvas.GetLeft(player))
                {
                    Canvas.SetLeft(boss, Canvas.GetLeft(boss) - 20);
                }
            }
        }
        private void dispatTickbot1(object sender, EventArgs e)
        {
            if (statusbot1 == 1)
            {
                bot1.Source = new BitmapImage(new Uri(@"\res\run2.png", UriKind.Relative));
                statusbot1  = 2;
            }
            else if (statusbot1 == 2)
            {
                bot1.Source = new BitmapImage(new Uri(@"\res\run1.png", UriKind.Relative));
                statusbot1  = 1;
            }

            //ฟังชันตีมอนเตอร์
            double d = Math.Sqrt(Math.Pow(Canvas.GetTop(bot1) - Canvas.GetTop(player), 2) + Math.Pow(Canvas.GetLeft(bot1) - Canvas.GetLeft(player), 2));

            if (d < 120)
            {
                if (keyK == true)
                {
                    bot1Hp.Value = bot1Hp.Value - 20;
                    Canvas.SetLeft(bot1, Canvas.GetLeft(bot1) + 50);
                }

                if (bot1Hp.Value <= 0)
                {
                    label1.Content = "$  " + MainWindow.MN;
                    MainWindow.MN += 100;
                    Canvas.SetTop(bot1, Canvas.GetTop(bot1) - 200);
                    Canvas.SetLeft(bot1, Canvas.GetLeft(bot1) + 1000);
                    timerbot1.Stop();
                }
            }
            if (d <= 90 && Canvas.GetLeft(player) >= 0)
            {
                playerHP.Value = playerHP.Value - 10;
                Canvas.SetLeft(player, Canvas.GetLeft(player) - 50);
                if (playerHP.Value <= 0)
                {
                    string sql = "UPDATE `logingame1` SET `price`='" + MainWindow.MN + "'   WHERE username ='******'";

                    MySqlConnection con = new MySqlConnection("host=localhost;user=project;password=123456;database=gameshop");
                    MySqlCommand    cmd = new MySqlCommand(sql, con);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    final.result = "GAME OVER";
                    final fn = new final();
                    fn.Show();
                    this.Hide();
                    timer.Stop();
                    timerbot.Stop();
                    timerbot1.Stop();
                }
            }


            //การทำงานของบอท
            Random rnd = new Random();

            if (rnd.Next(10) >= 8 && Canvas.GetLeft(bot1) <= 950)
            {
                Canvas.SetLeft(bot1, Canvas.GetLeft(bot1) + 20);
            }
            else if (Canvas.GetLeft(bot1) >= Canvas.GetLeft(player) && Canvas.GetLeft(bot1) > 0)
            {
                Canvas.SetLeft(bot1, Canvas.GetLeft(bot1) - 20);
            }
        }