示例#1
0
        private async void button21_Click(object sender, EventArgs e)
        {
            if (textBox5.Text.ToLower() == rjesenja[4].ToLower())
            {
                textBox5.Enabled = false;

                button21.BackColor = Color.SeaGreen;
                await Task.Delay(700);

                button21.BackColor = Color.SkyBlue;

                foreach (Control x in this.Controls)
                {
                    if (x is Button && x.Text != "?" && x.Text == "")
                    {
                        x.Text = x.Tag.ToString();
                    }
                }

                //Gotova Igra
                player += 2 * (ulozio + 1);
                foreach (Control x in this.Controls)
                {
                    if (x is TextBox && x.Text == "")
                    {
                        player += 2 * (ulozio + 1);
                    }
                }
                await Task.Delay(700);

                KviskoForm2 ni = new KviskoForm2(kviskoBodovi, kviskoBodovi1, kviskoBodovi2, player, player1, player2);
                this.Hide();
                ni.ShowDialog();
                this.Close();
            }

            else
            {
                MessageBox.Show("Pogrešan odgovor, drugi igrač je na redu");
                textBox5.Text = "";
                drugiIgrac();
            }
        }
示例#2
0
        public async void treciIgrac()
        {
            pictureBox2.BackColor = Color.SteelBlue;
            await Task.Delay(700);

            List <Button> buttoni = new List <Button>();

            foreach (Control x in this.Controls)
            {
                if (x is Button && x.Text == "")
                {
                    buttoni.Add((Button)x);
                }
            }

            Random rnd = new Random();
            Dictionary <TextBox, int> l = new Dictionary <TextBox, int>();

            if (buttoni.Count != 0)
            {
                Button btn = buttoni[rnd.Next(buttoni.Count)];
                btn.Text    = btn.Tag.ToString();
                btn.Enabled = false;
                string num = btn.Name.Substring(6, btn.Name.Length - 6);
                int    t   = Int32.Parse(num);
                if (t < 5)
                {
                    otv1++;
                }
                else if (t < 9)
                {
                    otv2++;
                }
                else if (t < 13)
                {
                    otv3++;
                }
                else
                {
                    otv4++;
                }

                await Task.Delay(700);

                l.Add(textBox1, otv1);
                l.Add(textBox2, otv2);
                l.Add(textBox3, otv3);
                l.Add(textBox4, otv4);
                l.OrderByDescending(pair => pair.Value);
                while (true)
                {
                    //ako je sve ostalo pogođeno, pogađamo konačno rješenje
                    if (l.Count == 0)
                    {
                        break;
                    }
                    else if (l.First().Key.Text != "")
                    {
                        l.Remove(l.First().Key);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            double postotak;

            if (l.Count != 0)
            {
                if (player2Tezina == 1)
                {
                    postotak = -5;
                }
                else if (player2Tezina == 2)
                {
                    postotak = 15;
                }
                else
                {
                    postotak = 35;
                }
                postotak += 20 * l.First().Value;
                if (postotak < 0)
                {
                    postotak = 0;
                }
            }
            else
            {
                l.Add(textBox5, 0);
                if (player1Tezina == 1)
                {
                    postotak = 30;
                }
                else if (player1Tezina == 2)
                {
                    postotak = 60;
                }
                else
                {
                    postotak = 90;
                }
            }
            string s    = l.First().Key.Name.Substring(7, l.First().Key.Name.Length - 7);
            int    temp = Int32.Parse(s);

            if (rnd.NextDouble() < postotak / 100)
            {
                l.First().Key.Text = rjesenja[temp - 1];
                pictureBox2.BackColor = Color.SeaGreen;
                if (temp == 1)
                {
                    button1.Text      = button1.Tag.ToString();
                    button1.Enabled   = false;
                    button2.Text      = button2.Tag.ToString();
                    button2.Enabled   = false;
                    button3.Text      = button3.Tag.ToString();
                    button3.Enabled   = false;
                    button4.Text      = button4.Tag.ToString();
                    button4.Enabled   = false;
                    button17.Enabled  = false;
                    textBox1.ReadOnly = true;
                }
                else if (temp == 2)
                {
                    button5.Text      = button5.Tag.ToString();
                    button5.Enabled   = false;
                    button6.Text      = button6.Tag.ToString();
                    button6.Enabled   = false;
                    button7.Text      = button7.Tag.ToString();
                    button7.Enabled   = false;
                    button8.Text      = button8.Tag.ToString();
                    button8.Enabled   = false;
                    button18.Enabled  = false;
                    textBox2.ReadOnly = true;
                }
                else if (temp == 3)
                {
                    button9.Text      = button9.Tag.ToString();
                    button9.Enabled   = false;
                    button10.Text     = button10.Tag.ToString();
                    button10.Enabled  = false;
                    button11.Text     = button11.Tag.ToString();
                    button11.Enabled  = false;
                    button12.Text     = button12.Tag.ToString();
                    button12.Enabled  = false;
                    button19.Enabled  = false;
                    textBox3.ReadOnly = true;
                }
                else if (temp == 4)
                {
                    button13.Text     = button13.Tag.ToString();
                    button13.Enabled  = false;
                    button14.Text     = button14.Tag.ToString();
                    button14.Enabled  = false;
                    button15.Text     = button15.Tag.ToString();
                    button15.Enabled  = false;
                    button16.Text     = button16.Tag.ToString();
                    button16.Enabled  = false;
                    button20.Enabled  = false;
                    textBox4.ReadOnly = true;
                }
                await Task.Delay(700);

                player2     += 2 * (ulozio2 + 1);
                bodovi2.Text = "Bodovi: " + player2.ToString();
                if (temp == 5)
                {
                    await Task.Delay(1000);

                    KviskoForm2 ni = new KviskoForm2(kviskoBodovi, kviskoBodovi1, kviskoBodovi2, player, player1, player2);
                    this.Hide();
                    ni.ShowDialog();
                    this.Close();
                }
                else
                {
                    treciIgrac();
                }
            }
            else
            {
                pictureBox2.BackColor = Color.Maroon;
                await Task.Delay(700);

                pictureBox2.BackColor = Color.Transparent;
                foreach (Control x in this.Controls)
                {
                    if (x is Button && x.Text != "?" && x.Text == "")
                    {
                        x.Enabled = true;
                    }
                }
            }
        }