示例#1
0
        static void Main(string[] args)
        {
            var lBallot = new Ballot()
            {
                Name      = "Test",
                Threshold = 60
            };

            lBallot.AddNewChoice("Radio 10");
            lBallot.AddNewChoice("Veronica");
            lBallot.AddNewChoice("Q Music");
            lBallot.AddNewChoice("538");
            lBallot.AddNewChoice("Arrow");

            GenerateRandomVotes(lBallot, 20);

            var lVote = lBallot.GetVoteForVoter("Test");

            var lStop        = false;
            var lDirectionUp = true;

            Choice[] lCurrentRanking;
            int      i = 0;

            while (!lStop)
            {
                lCurrentRanking = lVote.GetCurrentRanking();
                ShowVoteMenu(lCurrentRanking);

                var s = Console.ReadLine();

                switch (s?.ToLowerInvariant())
                {
                case "q":
                    lStop = true;
                    break;

                case "u":
                    lDirectionUp = true;
                    break;

                case "d":
                    lDirectionUp = false;
                    break;

                case "s":
                    lBallot.SubmitVote(lVote);
                    lVote = lBallot.GetVoteForVoter("Test" + i);
                    i++;
                    break;

                case "r":
                    GenerateRandomVotes(lBallot, 20);
                    break;

                case "c":
                    ShowResult(lBallot.CalcResult());
                    break;

                default:
                    if (int.TryParse(s, out int lInt))
                    {
                        if (lDirectionUp)
                        {
                            lVote.IncreaseChoiceRank(lCurrentRanking[lInt].UniqueID);
                        }
                        else
                        {
                            lVote.DecreaseChoiceRank(lCurrentRanking[lInt].UniqueID);
                        }
                    }
                    break;
                }
            }
        }