Ejemplo n.º 1
0
        public bool AddVote(ulong userId, ulong mafiaId)
        {
            if (userId == mafiaId)
            {
                return(false);                   // We don't allow you to vote for yourself
            }
            if (!Players.ContainsKey(userId))
            {
                return(false);                              // filter out people voting who aren't in the game
            }
            if (!Players.ContainsKey(mafiaId))
            {
                return(false);                               // filter out votes for users not in the game
            }
            if (!Votes.ContainsKey(userId))
            {
                Votes[userId] = new ulong[] { mafiaId };
                return(true);
            }

            if (Votes[userId].Length >= Mafia.Count)
            {
                return(false);                                     // only accept the first votes of up to the number of mafia
            }
            if (Votes[userId].Contains(mafiaId))
            {
                return(false);                                 // we already counted this vote
            }
            Votes[userId] = Votes[userId].Append(mafiaId).ToArray();
            return(true);
        }
        public void Vote(string voteFor)
        {
            var connectionId = Context.ConnectionId;

            if (VoteTracker.ContainsKey(connectionId)) // CHANGE VOTE!
            {
                Votes[VoteTracker[connectionId]]--;
            }

            if (Votes.ContainsKey(voteFor))
            {
                Votes[voteFor]++;
            }
            else
            {
                Votes[voteFor] = 1;
            }

            VoteTracker[connectionId] = voteFor;

            List <WijPieChartSeriesItem> seriesList = new List <WijPieChartSeriesItem>();

            foreach (string key in Votes.Keys)
            {
                seriesList.Add(new WijPieChartSeriesItem()
                {
                    label       = key,
                    legendEntry = true,
                    data        = Votes[key]
                });
                Debug.WriteLine(string.Format("{0} == {1}", key, Votes[key]));
            }

            Clients.updateVotes(seriesList);
        }
 public void ProcessAnswer(string text)
 {
     if (int.TryParse(text, out int number))
     {
         if (Votes.ContainsKey(number))
         {
             Votes[number] += 1;
         }
     }
 }
Ejemplo n.º 4
0
        public bool Score()
        {
            var mafia = Mafia;

            if (!WinningTeam.HasValue)
            {
                return(false);                       // we only score games that have a winner
            }
            // score only valid if all players have voted for the correct number of mafia
            foreach (var p in Players)
            {
                if (!Votes.ContainsKey(p.Value.Id) || Votes[p.Value.Id].Length != mafia.Count)
                {
                    return(false);
                }
            }

            foreach (var player in Players.Values)
            {
                int  score   = 0;
                bool wonGame = player.Team == WinningTeam.Value;

                if (player.Type == PlayerType.Mafia)
                {
                    int guessedMe = Votes.Where(x => x.Key != player.Id && x.Value.Contains(player.Id)).Count();

                    score += !wonGame ? ScoringConstants.LosingAsMafia : 0;
                    score += ScoringConstants.MafiaNobodyGuessedMe - guessedMe;  // two points minus number of guesses as mafia
                }
                else if (player.Type == PlayerType.Joker)
                {
                    int guessedMe = Votes.Where(x => x.Key != player.Id && x.Value.Contains(player.Id)).Count();

                    score += OvertimeReached ? ScoringConstants.ReachedOvertime : 0;
                    score += Math.Min(ScoringConstants.JokerGuessedAsMafiaMax, guessedMe);
                }
                else
                {
                    int correctVotes = Votes.ContainsKey(player.Id) ? mafia.Where(x => Votes[player.Id].Contains(x.Id)).Count() : 0;

                    score += wonGame ? ScoringConstants.WinningGame : 0;
                    score += correctVotes * ScoringConstants.GuessedMafia;
                }

                player.Score = Math.Max(0, score);
            }

            return(true);
        }
Ejemplo n.º 5
0
        public void Vote(string topic)
        {
            AssertOnGoingVoting();
            AssertValidTopic();

            Votes[topic] = ++Votes[topic];

            void AssertValidTopic()
            {
                topic = topic ?? throw new ArgumentNullException(nameof(topic));
                if (!Votes.ContainsKey(topic))
                {
                    throw new InvalidOperationException("Topic doesn't exist");
                }
            }
        }
Ejemplo n.º 6
0
 public CustomsGroup(string definition)
 {
     Value     = definition;
     NumGuests = definition.Count(c => c == '\n');
     foreach (char c in definition)
     {
         if (c == '\r' || c == '\n')
         {
             continue;
         }
         if (!Votes.ContainsKey(c))
         {
             Votes.Add(c, 0);
         }
         Votes[c]++;
     }
 }
Ejemplo n.º 7
0
 public bool RemoveVote(ulong userId, ulong mafiaId)
 {
     if (!Players.ContainsKey(userId))
     {
         return(false);                              // filter out people voting who aren't in the game
     }
     if (!Players.ContainsKey(mafiaId))
     {
         return(false);                               // filter out votes for users not in the game
     }
     if (!Votes.ContainsKey(userId))
     {
         return(false);                            // user hasn't voted return
     }
     if (!Votes[userId].Contains(mafiaId))
     {
         return(false);                                  // we don't have this vote anyways
     }
     Votes[userId] = Votes[userId].Where(u => u != mafiaId).ToArray();
     return(true);
 }
Ejemplo n.º 8
0
        public bool CastVote(Client voter, int option)
        {
            if (AlreadyVoted.Contains(voter))
            {
                return(false);
            }
            AlreadyVoted.Add(voter);

            lock (Votes)
            {
                if (Votes.ContainsKey(option))
                {
                    Votes[option]++;
                }
                else
                {
                    Votes.Add(option, 1);
                }
            }

            return(true);
        }