コード例 #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            //ADD QUESTION BUTTON

            //get combo box selection as string
            string selected = this.correctAnswer.GetItemText(this.correctAnswer.SelectedItem);

            //Select last char from this string e.g. A or B
            selected = selected.Substring(selected.Length - 1);


            string       apiUrl               = "https://craig.im/infosec.php";
            string       apiMethod            = "addQuestions";
            AddQuestions addQuestions_Request = new AddQuestions()
            {
                question      = question.Text,
                answerA       = answerA.Text,
                answerB       = answerB.Text,
                correctAnswer = selected
            };

            // make http post request
            string response = Http.Post(apiUrl, new NameValueCollection()
            {
                { "api_method", apiMethod },
                { "api_data", JsonConvert.SerializeObject(addQuestions_Request) }
            });

            // decode json string to object
            API_Response r = JsonConvert.DeserializeObject <API_Response>(response);

            // check response
            if (!r.IsError)
            {
                //There was no errors when adding the account -> do this:
                MessageBox.Show("Question successfully added.");
                //clear text box
                userID.Text = String.Empty;
                //update lits
                getUserList();
            }
            else
            {
                MessageBox.Show("ERROR: " + r.ErrorMessage);
            }
        }
コード例 #2
0
    private void SetRandomQuestion()
    {
        int rand = UnityEngine.Random.Range(1, unansweredQuestions.Count);

        currentQuestion = unansweredQuestions[rand];

        if (rand % 2 == 0)
        {
            ans1.text = currentQuestion.realAnswer;
            ans2.text = UnityEngine.Random.Range(1, 11).ToString();
        }
        else
        {
            ans1.text = UnityEngine.Random.Range(1, 11).ToString();
            ans2.text = currentQuestion.realAnswer;
        }
        question.text = currentQuestion.question;
        anim.SetBool("MoveAsteroids", true);
    }