//--------------------------------
        protected override void seed()
        {
            //loads the swmrs array and sorts it
            sortUpwards();

            int lastHeat = count % numLanes;

            if (lastHeat < 3)
            {
                lastHeat = 3;                   //last heat must have 3 or more
            }
            int lastLanes = count - lastHeat;

            numHeats = count / numLanes;
            if (lastLanes > 0)
            {
                numHeats++;
            }
            int heats = numHeats;

            //place heat and lane in each swimmer's object
            int j = 0;

            for (int i = 0; i < lastLanes; i++)
            {
                Swimmer sw = swmrs[i];
                sw.setLane(lanes[j++]);
                sw.setHeat(heats);
                if (j >= numLanes)
                {
                    heats--;
                    j = 0;
                }
            }
            //Add in last partial heat
            if (j < numLanes)
            {
                heats--;
            }
            j = 0;
            for (int i = lastLanes - 1; i < count; i++)
            {
                Swimmer sw = swmrs[i];
                sw.setLane(lanes[j++]);
                sw.setHeat(heats);
            }
            //copy from array back into ArrayList
            swimmers = new ArrayList();
            for (int i = 0; i < count; i++)
            {
                swimmers.Add(swmrs[i]);
            }
        }
        private void lsEvents_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            int index = lsEvents.SelectedIndex;
            EventCreatorAbstract   ev = (EventCreatorAbstract)events[index];
            SeedingProductAbstract sd = ev.getSeeding();
            IEnumerator            en = sd.getSwimmers();

            lsSwimmers.Items.Clear();
            while (en.MoveNext())
            {
                Swimmer sw = (Swimmer)en.Current;
                lsSwimmers.Items.Add(sw.getHeat() + " " + sw.getLane() + " " + sw.getName() + " " + sw.getTime());
            }
        }
Пример #3
0
        public EventCreatorAbstract(string filename, int lanes)
        {
            numLanes = lanes;
            swimmers = new ArrayList();
            //read in swimmers from file
            FileOperate f = new FileOperate(filename);

            f.OpenForRead();
            string s = f.readLine();

            while (s != null)
            {
                Swimmer sw = new Swimmer(s);
                swimmers.Add(sw);
                s = f.readLine();
            }
            f.close();
        }
 //--------------------------------
 protected void sortUpwards()
 {
     swmrs = new Swimmer[count];
     for (int i = 0; i < count; i++)
     {
         swmrs[i] = (Swimmer)swimmers[i];
     }
     for (int i = 0; i < count; i++)
     {
         for (int j = i; j < count; j++)
         {
             if (swmrs[i].getTime() > swmrs[j].getTime())
             {
                 Swimmer swtemp = swmrs[i];
                 swmrs[i] = swmrs[j];
                 swmrs[j] = swtemp;
             }
         }
     }
 }