Exemplo n.º 1
0
 /// <summary>
 /// IdeaTournament constructor
 /// </summary>
 /// <param name="ideaManager">Accepts an IdeaManager that it will make a copy of</param>
 ///
 /// <param name="userManager">Accepts a UserManager to track which users have voted</param>
 ///
 /// <param name="breakTies">Accepts a boolean of whether to
 /// break ties with a coin flip</param>
 public IdeaTournament(IdeaManager ideaManager, UserManager userManager, bool breakTies)
 {
     IdeaManager     = new IdeaManager(ideaManager);
     UserManager     = userManager;
     BreakTies       = breakTies;
     MaxVotesPerUser = IdeaManager.Ideas.Count / 3;
     RoundNumber     = 0;
     //MinVotes = 1;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Copy Constructor
 /// </summary>
 /// <param name="ideaManager">IdeaManager to copy</param>
 public IdeaManager(IdeaManager ideaManager)
 {
     Ideas = new List <Idea>(ideaManager.Ideas);
 }
Exemplo n.º 3
0
        // warning: this does not append, it deletes previous content
        // overloaded function that reads Idea data from text into objects
        public void GetData(IdeaManager anIdeaManager)
        {
            // deletes the old contents of the referenced IdeaManager
            anIdeaManager.Ideas.Clear();

            // reads the associated file from the working directory to an array of strings
            string[] fileData = ReadFile("Ideas.txt");

            // creates and reads in a local UserManager for adding owner data to the ideas
            UserManager aUserManager = new UserManager();

            GetData(aUserManager);

            // for the length of the string array
            for (int i = 0; i < fileData.Length; i++)
            {
                // these variables store data to later be compiled into an Idea object
                string ideaName;
                string ideaDescription;
                string ownerUsername;

                // skips the first lines to bypass the file header info
                // more lines may be added to the file header by raising this number
                if (i > 5)
                {
                    // reads lines from the file into the storage variables
                    ideaName = fileData[i];
                    i++;
                    ideaDescription = fileData[i];
                    i++;
                    ownerUsername = fileData[i];

                    // searches the UserManager for a user with the matching name of the idea owner
                    // might be better to eventually use a unique ID or something instead
                    bool foundUser = false;
                    int  userIterator;
                    for (userIterator = 0;
                         userIterator < aUserManager.UserList.Count; userIterator++)
                    {
                        if (aUserManager.UserList[userIterator].UserName == ownerUsername)
                        {
                            foundUser = true;
                            break;
                        }
                    }

                    // if an idea has an owner that doesn't exist, this is a problem
                    if (foundUser == false)
                    {
                        throw new Exception("The owner of an idea could not be found in users");
                    }

                    // compiles all of the read data into a single Idea object
                    Idea anIdea = new Idea(ideaName, ideaDescription,
                                           aUserManager.UserList[userIterator]);

                    // adds the Idea object to the IdeaManager
                    anIdeaManager.Ideas.Add(anIdea);
                }
            }
        }