コード例 #1
0
ファイル: exeptions.cs プロジェクト: TMAI42/lub4
        public void GameStart()
        {
            EventArgs e = new EventArgs();

            Goal?.Invoke(this, e);
            Cheating?.Invoke(this, e);
            throw new gameEx("мяч лопнул!");
        }
コード例 #2
0
        public Dictionary <Participant, Participant> Generate(List <Participant> participants, List <Cheating> cheatings)
        {
            var participantsAmount = participants.Count;
            var tryAssign          = 0;

            var generated = new Dictionary <Participant, Participant>();

            foreach (var participant in participants)
            {
                var assigned = false;
                tryAssign = 0;

                while (!assigned)
                {
                    Participant addressee;

                    tryAssign++;

                    Cheating cheatedAddressee = cheatings.FirstOrDefault(ch => ch.For == participant.Email);

                    if (cheatedAddressee != null)
                    {
                        addressee = participants.First(p => p.Email == cheatedAddressee.To);
                    }
                    else
                    {
                        var randomIndex = _random.Next(0, participantsAmount);
                        addressee = participants[randomIndex];

                        if (cheatings.FirstOrDefault(ch => ch.To == addressee.Email) != null)
                        {
                            continue;
                        }
                    }

                    if (tryAssign > participantsAmount)
                    {
                        return(Generate(participants, cheatings));
                    }

                    if (generated.Values.FirstOrDefault(p => p.Email == addressee.Email) != null || participant.Email == addressee.Email)
                    {
                        continue;
                    }

                    generated.Add(participant, addressee);

                    assigned = true;
                }
            }

            return(generated);
        }
コード例 #3
0
        /// <summary>
        /// Adds the number already tried by any of the players.
        /// </summary>
        /// <param name="id">The player identifier.</param>
        /// <param name="number">The number already tried by the player.</param>
        public void AddNumber(int id, int number)
        {
            Cheating?.Invoke(number);

            Numbers.Add(new KeyValuePair <int, int>(id, number));
        }