Esempio n. 1
0
        public IYearBook PassYearBook()
        {
            IYearBook yearBook = GetYearBookToPass();

            YearBookToPass = null;
            return(yearBook);
        }
Esempio n. 2
0
        public void Sign()
        {
            IYearBook yearBook = GetRecievedYearBook();

            if (yearBook != null)
            {
                yearBook.Sign(this);
                YearBookToPass   = yearBook;
                YearBookRecieved = null;
            }
        }
Esempio n. 3
0
        public void RecieveYearBook(IYearBook yearBook)
        {
            if (yearBook.GetOwner().GetParticipantIdentifier().Equals(StudentIdentifier))
            {
                Participant = false;
            }

            if (!Participant)
            {
                return;
            }

            YearBookRecieved = yearBook;
        }
Esempio n. 4
0
        static int[] findSignatureCounts(int[] masterPassItToStudent)
        {
            if (masterPassItToStudent == null || masterPassItToStudent.Length == 0)
            {
                throw new ArgumentException("Invalid Parameter");
            }

            IGameBuilder gameBuilder = new GameBuilder();
            Dictionary <IIdentifier, IParticipant> studentDictionary = new Dictionary <IIdentifier, IParticipant>(masterPassItToStudent.Length);
            List <int> signCount = new List <int>(masterPassItToStudent.Length);

            int[] passItToStudent = masterPassItToStudent;
            int   nonParticpantCount;

            do
            {
                List <int> nextPassItToStudent = new List <int>(passItToStudent.Length);
                signCount.Clear();
                nonParticpantCount = 0;

                for (int index = 0; index < passItToStudent.Length; index++)
                {
                    IIdentifier studentIdentifierPassFrom = gameBuilder.CreateIdentifier(index + 1);
                    IIdentifier studentIdentifierPassTo   = gameBuilder.CreateIdentifier(passItToStudent[index]);

                    if (Convert.ToInt32(studentIdentifierPassTo.GetIdentifier()) < 1)
                    {
                        throw new Exception("Value less than zero not allowed.");
                    }

                    //If new Student then add to dictionary and sign their yearbook
                    IParticipant studentPassFrom = GetOrAddParticipantIfMissing(gameBuilder, studentDictionary, studentIdentifierPassFrom);                    //If new Student then add to dictionary and sign their yearbook
                    IParticipant studentPassTo   = GetOrAddParticipantIfMissing(gameBuilder, studentDictionary, studentIdentifierPassTo);

                    if (!studentPassFrom.Equals(studentPassTo))
                    {
                        IYearBook yearBook = studentPassFrom.PassYearBook();
                        studentPassTo.RecieveYearBook(yearBook);
                    }
                    else
                    {
                        studentPassFrom.NoLongerAllowedToParticipate();
                    }

                    nextPassItToStudent.Add(masterPassItToStudent[passItToStudent[index] - 1]);
                }

                for (int index = 0; index < passItToStudent.Length; index++)
                {
                    IIdentifier  studentIdentifier = gameBuilder.CreateIdentifier(index + 1);
                    IParticipant student           = studentDictionary[studentIdentifier];
                    student.Sign();
                    signCount.Add(student.GetMyYearBook().GetSignedStudents().Count);

                    if (!student.IsParticipant())
                    {
                        nonParticpantCount++;
                    }
                }

                passItToStudent = nextPassItToStudent.ToArray();
            } while (nonParticpantCount != masterPassItToStudent.Length);

            return(signCount.ToArray());
        }
Esempio n. 5
0
 public Student(IGameBuilder gameBuilder, IIdentifier studentIdentifier)
 {
     StudentIdentifier = studentIdentifier;
     MyYearBook        = gameBuilder.CreateYearBook(this);
     YearBookRecieved  = MyYearBook;
 }