Пример #1
0
        public void ReadByesFromFile(int nextRound)
        {
            //read players file
            //if player already registered
            //check if his participation changed

            string tLn = "";
            string fin = workDirectory + "players.txt";
            using (StreamReader reader = new StreamReader (fin)) {
                for (int i = 0; i < 6; i++)
                    tLn = reader.ReadLine(); //trip through headers
                while ((tLn = reader.ReadLine ()) != null) {
                    String[] split = tLn.Split(new char[] {',','\t'});
                    try {
                        int pine = int.Parse (split [0]);
                        int rats = int.Parse (split [2]);
                        bool[] bull = new bool[nRounds]; //not set via input file
                        for(int k=0; k<bull.Length; k++)
                            bull[k]=true;
                        if(split.Length > 6)
                            for (int i = 6; i < split.Length; i++) {
                                if (split [i].Equals ("") == false) {
                                    try{
                                        int byeRound = int.Parse(split[i].Trim());
                                        if(byeRound > nRounds){
                                            Console.WriteLine("A bye cannot be allocated for a round which does not exist");
                                            Console.WriteLine(tLn);
                                        }
                                        else
                                            bull[byeRound-1]=false; //0 based
                                    }
                                    catch(Exception e){Console.WriteLine(e.Message);}
                                }
                            }
                        Player j = new Player (pine, split [1], rats, split [3], split [4],  bull, split[5]);
                        if (AllPlayers.Contains (j) == true) {
                            for(int ap = 0; ap<AllPlayers.Count; ap++)
                                if(j.Equals(AllPlayers[ap]))
                                    for(int i2=nextRound-1; i2<nRounds; i2++) //0 based
                                        AllPlayers[ap].SetParticipation(i2, bull[i2]);
                        }
                    } catch (Exception e) {
                        Console.WriteLine ("An exception was encountered in ReadByesFromFile" + e.Message);
                        Console.WriteLine (tLn);
                    }
                }
            }
        }