コード例 #1
0
        public int GetTotalVotes()
        {
            int votes = 0;

            Candidates.ForEach(c =>
            {
                votes += c.Votes.Count;
            });

            return(votes);
        }
コード例 #2
0
        public void OnTick()
        {
            foreach (DateTime dt in StartTimes)
            {
                if (dt.Year == DateTime.Now.Year && DateTime.Now.Month == dt.Month && DateTime.Now.Day > 14 && !ElectionEnded)
                {
                    EndElection();
                }
                else if (dt.Year == DateTime.Now.Year && DateTime.Now.Month == dt.Month && DateTime.Now.Day == dt.Day && ElectionEnded)
                {
                    StartNewElection();
                }
            }

            if (City.Governor == null && AutoPickGovernor != DateTime.MinValue && DateTime.UtcNow > AutoPickGovernor)
            {
                if (City.GovernorElect != null)
                {
                    if (Candidates.Count > 0)
                    {
                        BallotEntry entry = Candidates.FirstOrDefault(c => c.Player == City.GovernorElect);

                        if (entry != null)
                        {
                            Candidates.Remove(entry);
                        }
                    }

                    City.GovernorElect = null;
                }

                if (Candidates.Count > 0)
                {
                    Candidates.Sort();
                    City.GovernorElect = Candidates[0].Player;
                }

                AutoPickGovernor = DateTime.MinValue;
            }

            if (CanNominate())
            {
                Candidates.ForEach(entry =>
                {
                    if (entry.TimeOfNomination + TimeSpan.FromHours(NominationDeadline) < DateTime.UtcNow && entry.Endorsements.Count == 0)
                    {
                        Candidates.Remove(entry);
                    }
                });
            }
        }
コード例 #3
0
        public void Serialize(GenericWriter writer)
        {
            writer.Write(0);

            writer.Write(ElectionEnded);
            writer.Write(AutoPickGovernor);

            writer.Write(StartTimes.Length);
            foreach (DateTime dt in StartTimes)
            {
                writer.Write(dt);
            }

            writer.Write(Candidates.Count);
            Candidates.ForEach(entry => entry.Serialize(writer));
        }