示例#1
0
 private void Save_Click(object sender, EventArgs e)
 {
     if (Pitanje.Text.Length > 0 && Odgovor.Text.Length > 0)
     {
         ZavrsnaIgra nova = new ZavrsnaIgra(Pitanje.Text, Odgovor.Text);
         ZavrsnaIgraAccess.AddZavrsnaIgra(nova);
         Pitanje.Text = "";
         Odgovor.Text = "";
     }
     else
     {
         MessageBox.Show("Popunite sva polja");
     }
 }
示例#2
0
 public static string AddZavrsnaIgra(ZavrsnaIgra zavr)
 {
     using (SQLiteConnection connection = DB.GetConnection())
     {
         try
         {
             connection.Open();
             string        insertZavr = @"insert into Zavr(Pitanje, Odgovor)
                                     values ('" + zavr.Pitanje + "', '" + zavr.Odgovor + "')";
             SQLiteCommand command    = new SQLiteCommand(insertZavr, connection);
             command.ExecuteNonQuery();
         }
         catch (Exception)
         {
             return("Error: insert to table Zavr");
         }
         return(null);
     }
 }
示例#3
0
        public static List <ZavrsnaIgra> getAll()
        {
            List <ZavrsnaIgra> pitanja = new List <ZavrsnaIgra>();

            using (SQLiteConnection connection = DB.GetConnection())
            {
                connection.Open();

                string           select  = @"select * from Zavr";
                SQLiteCommand    command = new SQLiteCommand(select, connection);
                SQLiteDataReader row     = command.ExecuteReader();

                while (row.Read())
                {
                    int         id      = Int32.Parse(row["Id"].ToString());
                    string      pitanje = row["Pitanje"].ToString();
                    string      odgovor = row["Odgovor"].ToString();
                    ZavrsnaIgra nova    = new ZavrsnaIgra(id, pitanje, odgovor);
                    pitanja.Add(nova);
                }

                return(pitanja);
            }
        }
示例#4
0
        async public void postaviPitanje()
        {
            if (brojPitanja < 5)
            {
                prijava.Image = Kviskoteka.Properties.Resources.gumb;
                Random      rand = new Random();
                ZavrsnaIgra prva = svaPitanja[rand.Next(0, svaPitanja.Count)];
                svaPitanja.Remove(prva);

                timer.Text = "";
                await Task.Delay(1000);

                pictureBox1.BackColor = Color.Transparent;
                pictureBox2.BackColor = Color.Transparent;

                pitanje.Text = prva.Pitanje;
                List <KeyValuePair <int, double> > vrijemeNaTasteru = new List <KeyValuePair <int, double> >();
                prijava.Enabled = true;

                start       = DateTime.Now;
                naseVrijeme = DateTime.Now.AddSeconds(3);

                Random rnd            = new Random();
                double vrijemeIgraca1 = rnd.NextDouble() * 3;

                double vrijemeIgraca2 = rnd.NextDouble() * 3;

                double trazenoVrijeme = rnd.NextDouble() * 3;
                for (int i = 3; i >= 1; i--)
                {
                    timer.Text = i.ToString();
                    await Task.Delay(1000);
                }
                timer.Text = "0";
                await Task.Delay(3000); // u ovom vremenu se ocekuje nas eventualni klik na taster

                timer.Text      = "";
                prijava.Enabled = false;
                double vrijemeIgraca = naseVrijeme.Second + (double)naseVrijeme.Millisecond / 1000 - start.Second - (double)start.Millisecond / 1000;

                vrijemeNaTasteru.Add(new KeyValuePair <int, double>(1, Math.Abs(vrijemeIgraca1 - trazenoVrijeme)));
                vrijemeNaTasteru.Add(new KeyValuePair <int, double>(2, Math.Abs(vrijemeIgraca2 - trazenoVrijeme)));
                vrijemeNaTasteru.Add(new KeyValuePair <int, double>(0, Math.Abs(vrijemeIgraca - trazenoVrijeme)));

                vrijemeNaTasteru.Sort(
                    delegate(KeyValuePair <int, double> pair1,
                             KeyValuePair <int, double> pair2)
                {
                    return(pair1.Value.CompareTo(pair2.Value));
                }
                    );

                while (true)
                {
                    if (vrijemeNaTasteru.Count == 0)
                    {
                        ++brojPitanja;
                        postaviPitanje();
                        break;
                    }
                    else if (vrijemeNaTasteru.First().Key == 0)
                    {
                        vrijemeNaTasteru.Remove(vrijemeNaTasteru.First());

                        DateTime sad = DateTime.Now;
                        string   odgovor;
                        using (Odgovor formOptions = new Odgovor())
                        {
                            formOptions.ShowDialog();
                            odgovor = formOptions.GetMyResult;
                        }
                        if (odgovor != null && odgovor.ToLower() == prva.Odgovor.ToLower())
                        {
                            player     += 2 * (ulozio + 1);
                            label2.Text = "Bodovi: " + player.ToString();
                            ++brojPitanja;
                            postaviPitanje();
                            break;
                        }
                    }
                    else if (vrijemeNaTasteru.First().Key == 1)
                    {
                        vrijemeNaTasteru.Remove(vrijemeNaTasteru.First());
                        pictureBox1.BackColor = Color.SteelBlue;
                        await Task.Delay(1000);

                        Random random = new Random();
                        if (random.NextDouble() < player1Tezina)
                        {
                            player1              += 2 * (ulozio1 + 1);
                            bodovi1.Text          = "Bodovi: " + player1.ToString();
                            pictureBox1.BackColor = Color.SeaGreen;
                            label3.Text           = prva.Odgovor;
                            await Task.Delay(1000);

                            label3.Text = "";
                            ++brojPitanja; postaviPitanje(); break;
                        }
                        else
                        {
                            pictureBox1.BackColor = Color.Maroon;
                            await Task.Delay(500);
                        }
                    }
                    else if (vrijemeNaTasteru.First().Key == 2)
                    {
                        vrijemeNaTasteru.Remove(vrijemeNaTasteru.First());
                        pictureBox2.BackColor = Color.SteelBlue;
                        await Task.Delay(1000);

                        Random random = new Random();
                        if (random.NextDouble() < player1Tezina)
                        {
                            player2              += 2 * (ulozio1 + 1);
                            bodovi2.Text          = "Bodovi: " + player2.ToString();
                            pictureBox2.BackColor = Color.SeaGreen;
                            label4.Text           = prva.Odgovor;
                            await Task.Delay(1000);

                            label4.Text = "";
                            ++brojPitanja; postaviPitanje(); break;
                        }
                        else
                        {
                            pictureBox2.BackColor = Color.Maroon;
                            await Task.Delay(500);
                        }
                    }
                }
            }
            else
            {
                await Task.Delay(700);

                Kraj ni = new Kraj(player, player1, player2);
                this.Hide();
                ni.ShowDialog();
                this.Close();
            }
        }