Пример #1
0
        public static void poll(CommandArgs args)
        {
            if (args.Parameters.Count < 1)
            {
                if (args.Player.Group.HasPermission("poll.admin"))
                {
                    args.Player.SendErrorMessage("Invalid syntax! proper syntax: /poll <reset/addquestion/addanswer/end/showresult/start/vote/gui>");
                    return;
                }
                else
                {
                    args.Player.SendErrorMessage("Invalid syntax! proper syntax: /poll vote <answer>");
                    return;
                }
            }
            string str = string.Empty;
            switch (args.Parameters[0])
            {
                case "reset":
                    #region reset
                    pollitem = new Pollitem();
                    break;
                    #endregion reset
                case "addquestion":
                    #region addquestion
                    if (args.Parameters.Count < 2)
                    {
                        args.Player.SendErrorMessage("Invalid syntax! valid syntax: /poll addquestion <question>");
                        return;
                    }
                    str = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));
                    pollitem.question = str;
                    args.Player.SendMessage("question set: " + str, PollColor);
                    break;
                    #endregion addquestion
                case "addanswer":
                    #region addanswer
                    if (args.Parameters.Count < 2)
                    {
                        args.Player.SendErrorMessage("Invalid syntax! valid syntax: /poll addanswer <answer>");
                        return;
                    }
                    str = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));
                    pollitem.answers.Add(str.ToLower());
                    args.Player.SendMessage("answer added: " + args.Parameters[1].ToLower(), PollColor);
                    break;
                    #endregion addanswer
                case "start":
                    #region start
                    if (pollitem.question == null)
                    {
                        args.Player.SendErrorMessage("This poll has no question!");
                        return;
                    }
                    if (pollitem.answers.Count < 2)
                    {
                        args.Player.SendErrorMessage("This poll has no answers!");
                        return;
                    }
                    for (int i = 0; i < pollitem.answers.Count; i++)
                    {
                        pollitem.votes.Add(new vote(pollitem.answers[i], 0));
                    }
                    PollStarted = true;
                    TSPlayer.All.SendMessage("[Poll] question: " + pollitem.question, PollColor);
                    TSPlayer.All.SendMessage("[Poll] valid answers: " + string.Join(", ", pollitem.answers), PollColor);
                    TSPlayer.All.SendMessage("[Poll] vote by typing /poll vote <answer>", PollColor);
                    break;
                    #endregion start
                case "vote":
                    #region vote
                    if (args.Parameters.Count != 2)
                    {
                        args.Player.SendErrorMessage("Invalid syntax! valid syntax: /poll vote <answer>");
                        return;
                    }
                    if (!PollStarted)
                    {
                        args.Player.SendErrorMessage("There is no poll running currently!");
                        return;
                    }
                    if (pollitem.voters.Contains(args.Player))
                    {
                        args.Player.SendErrorMessage("You have already voted for this poll!");
                        return;
                    }
                    bool found = false;
                    for (int i = 0; i < pollitem.votes.Count; i++)
                    {

                        if (pollitem.votes[i].Name == args.Parameters[1].ToLower())
                        {
                            pollitem.votes[i].Count++;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        args.Player.SendErrorMessage("Invalid answer! list of answers: " + string.Join(",", pollitem.answers));
                        return;
                    }
                    pollitem.voters.Add(args.Player);
                    TSPlayer.All.SendMessage(args.Player.Name + " has voted: " + args.Parameters[1], PollColor);
                    args.Player.SendMessage("Thank you for your vote!", PollColor);
                    break;
                    #endregion vote
                case "end":
                    #region end
                    PollStarted = false;
                    TSPlayer.All.SendMessage(args.Player.Name + " has ended the poll!", PollColor);
                    break;
                    #endregion end
                case "showresult":
                    #region showresult
                    if (pollitem.question == null)
                    {
                        args.Player.SendErrorMessage("Nothing to display!");
                        return;
                    }
                    var q = from a in pollitem.votes orderby a.Count select a;
                    List<vote> vtresult = q.ToList();
                    TSPlayer.All.SendMessage("[Poll] Poll results", PollColor);
                    foreach (vote v in vtresult)
                    {
                        TSPlayer.All.SendMessage(v.Name + ": " + v.Count.ToString(), PollColor);
                    }
                    break;
                    #endregion showresult
                case "gui":
                    #region gui
                    Poll.poll.open(args);
                    break;
                default:
                    if (args.Player.Group.HasPermission("poll.admin"))
                        args.Player.SendErrorMessage("Invalid syntax! proper syntax: /poll <reset/addquestion/addanswer/end/showresult/start/vote/gui>");

                    else
                        args.Player.SendErrorMessage("Invalid syntax! proper syntax: /poll vote <answer>");
                    return;
                    #endregion gui
            }
        }
Пример #2
0
 // /poll reset
 private void button1_Click(object sender, EventArgs e)
 {
     timer1.Stop();
     PollStarted = false;
     labelquestion.Text = "";
     textBoxAnswer.Text = "";
     textBoxquestion.Text = "";
     pollitem = new Pollitem();
     listBox1.Items.Clear();
     listBox2.Items.Clear();
 }