示例#1
0
        private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Timer.Interval = QuestionInterval;
            Timer.Stop();
            int          rand            = rnd.Next(0, Math.Max(0, Questions.Count - 1));
            TrivQuestion currentQuestion = Questions[rand];

            CurrentAnswer = currentQuestion.Answer;
            Program.client.SendMessage(Program.client.JoinedChannels[0], currentQuestion.Question);
            WaitingOnAnswer = true;
            for (int i = 0; i < 3; i++)
            {
                for (int x = 0; x < HintInterval; x++)
                {
                    if (!WaitingOnAnswer)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                if (!WaitingOnAnswer)
                {
                    break;
                }
                switch (i)
                {
                case 0: break;

                case 1: break;

                case 2: break;

                default: break;
                }
            }
            if (!WaitingOnAnswer)
            {
                Handlers.DatabaseHandler.ExecuteNonQuery($"INSERT INTO Users (username,points) VALUES ('{Winner}', {answerPoints}) ON DUPLICATE KEY UPDATE points = points + {answerPoints}");
                Program.client.SendMessage(Program.client.JoinedChannels[0], $"{Winner} answered first with the correct answer and has earned {answerPoints} points!");
            }
            else
            {
                Program.client.SendMessage(Program.client.JoinedChannels[0], $"Time has ended. The correct answer was {CurrentAnswer}");
            }
            TrivQuestion questionToMove = currentQuestion;

            Questions.Remove(currentQuestion);
            UsedQuestions.Add(questionToMove);
            if (Questions.Count < 2)
            {
                Questions = UsedQuestions;
                UsedQuestions.Clear();
            }
            Timer.Start();
        }
示例#2
0
        public static void Load()
        {
            Timer          = new System.Timers.Timer();
            Timer.Interval = QuestionInterval;
            Timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
            dbConnection   = new MySqlConnection(Handlers.DatabaseHandler.myConnectionString); //I had no other way than to do this in this class instead of handling it in the Handlers.DatabaseHandler one.
            dbConnection.Open();
            string       query = "SELECT * FROM Questions ORDER BY UID";
            MySqlCommand cmd   = new MySqlCommand(query, dbConnection);

            MySqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                TrivQuestion item = new TrivQuestion();
                item.ID       = dr.GetInt32(0);
                item.Question = dr.GetString(1);
                item.Answer   = dr.GetString(2);
                Questions.Add(item);
            }
            dbConnection.Close();
        }