Exemplo n.º 1
0
    // get randome quesyion get elemnt from questionpool randomly
    private Gene GetRandomQuestion(int GIndex)
    {
        if (GIndex == 0)
        {
            QuestionTList = new List <Qtype>(SQuestionTList);
            QuestionList  = new List <Gene>(SQuestionList1);
            foreach (Qtype qt in QuestionTList)
            {
                qt.numquestion = qt.numOfType;
            }
        }
        foreach (Qtype qt in QuestionTList)
        {
            if (qt.numquestion <= 0)
            {
                QuestionList.RemoveAll(x => x.type.Equals(qt.name));
            }
        }

        //Response.Write("<script>alert('"+(QuestionList1.Count - 1)+"')</script>");
        randome = new System.Random();
        // int i = randome.Next(QuestionList.Count);
        //return QuestionList[i];
        int  l   = QuestionList.Count - 1;
        int  i   = randome.Next(l);
        Gene qst = (Gene)(QuestionList[i].Clone());

        QuestionTList.Find(x => x.name.Equals(qst.type)).numquestion--;
        QuestionList.RemoveAt(i);
        //Response.Write(qst.Answer + "    " + i + "\r\n");
        return(qst);
        // return QuestionPool[randome.Next(QuestionPool.Length - 1)];
    }
Exemplo n.º 2
0
        private void AskQuestionBtn_Click(object sender, RoutedEventArgs e)         //提问
        {
            if (User.UserId == null)
            {
                tipWindow warning = new tipWindow("请先登录");
                warning.ShowDialog();
                return;
            }
            askQuestionWindow ask = new askQuestionWindow(User, Keyword.Text);

            ask.ShowDialog();
            if (ask.HasAsked == true)
            {
                bool success = User.Ask(ask.QContent, ask.Reward);
                if (success)
                {
                    Question newQuestion = new Question(ask.QContent, ask.Reward, User.UserId, false, DateTime.Now, new List <Answer>());
                    QuestionList.Insert(0, newQuestion);
                    if (QuestionList.Count > 15)
                    {
                        QuestionList.RemoveAt(14);
                    }
                    this.User.Coin            -= ask.Reward;
                    this.QuesItem.ItemsSource  = null;
                    this.QuesItem.ItemsSource  = QuestionList;
                    CurrentQuestion            = QuestionList[0];
                    this.ques_info.DataContext = QuestionList[0];
                    this.AnsItem.ItemsSource   = new List <DisplayAnswer>();
                    coin.Text = "积分:" + User.Coin.ToString();
                }
                else
                {
                    tipWindow warning = new tipWindow("未知错误");
                    warning.ShowDialog();
                    return;
                }
            }
        }