예제 #1
0
        //=======================================================================
        // Reads in and parses the text file.
        // Creates a Critter instance for each entry, and loads them into the
        // class member List<Critter> critterList
        //=======================================================================
        private void loadCritterList()
        {
            StreamReader sr = null;

            try
            {
                sr = new StreamReader(inputFileName);
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Can't find the input file!");
            }

            if (sr != null)
            {
                String   currentLine = "";
                String[] currentAnimal;


                while ((currentLine = sr.ReadLine()) != null)
                {
                    currentAnimal = currentLine.Split(',');

                    ESpecies currentSpecies = (ESpecies)System.Enum.Parse(typeof(ESpecies), currentAnimal[1]);
                    critterList.Add(new Critter(currentAnimal[0], currentSpecies));
                } // end for each line
            }     // end if sr != null
        }         // end loadCritterList
예제 #2
0
        public void LoadFromFile()
        {
            StreamReader sr = null;

            try
            {
                sr = new StreamReader(FileName);
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Cant find the input file");
            }

            if (sr != null)
            {
                String   currentLine = "";
                String[] currentAnimal;

                while ((currentLine = sr.ReadLine()) != null)
                {
                    currentAnimal = currentLine.Split(',');

                    ESpecies currentSpecies = (ESpecies)System.Enum.Parse(typeof(ESpecies), currentAnimal[1]);
                    animals.Add(new Animal(currentAnimal[0], currentSpecies));
                }
            }
        }
예제 #3
0
        public void MakeSpeciesList(String speciesName)
        {
            speciesList = new List <Animal>();
            ESpecies currentSpecies = (ESpecies)System.Enum.Parse(typeof(ESpecies), speciesName);

            foreach (Animal a in animals)
            {
                if (a.Species == currentSpecies)
                {
                    speciesList.Add(a);
                }
            }
        }
예제 #4
0
        //=======================================================================
        // Returns a List<Critter> containing all Critters in class member
        // critterList whose species is equal to the passed in argument.
        // NB: Critter.species is an enum; the passed in argument is a string.
        // Explore System.Enum.Parse for solution.
        //=======================================================================
        public List <Critter> CritterQuery(string speciesName)
        {
            //make a new list to be passed back
            List <Critter> queryList = new List <Critter>();

            // the enum type
            ESpecies chosenSpecies = (ESpecies)Enum.Parse(typeof(ESpecies), speciesName);

            //loop through the critterList adding each critter that matches the chosenSpecies
            for (int i = 0; i < critterList.Count; i++)
            {
                if (critterList[i].Species == chosenSpecies)
                {
                    queryList.Add(critterList[i]);
                }
            }

            return(queryList);
        }
        //=======================================================================
        // Returns a List<Critter> containing all Critters in class member
        // critterList whose species is equal to the passed in argument.
        // NB: Critter.species is an enum; the passed in argument is a string.
        // Explore System.Enum.Parse for solution.
        //=======================================================================
        public List <Critter> CritterQuery(string speciesName)
        {
            //creates empty list
            List <Critter> sameSpecies = new List <Critter>();

            //casts string to enum
            ESpecies specie = (ESpecies)Enum.Parse(typeof(ESpecies), speciesName, true);

            //compares each critters enum with the input and adds to sameSpecies
            foreach (Critter animal in critterList)
            {
                if (animal.Species == specie)
                {
                    sameSpecies.Add(animal);
                }
            }

            return(sameSpecies);
        }
        //=======================================================================
        // Returns a List<Critter> containing all Critters in class member
        // critterList whose species is equal to the passed in argument.
        // NB: Critter.species is an enum; the passed in argument is a string.
        // Explore System.Enum.Parse for solution.
        //=======================================================================
        public List <Critter> CritterQuery(string speciesName)
        {
            // Declare and initialise a new Critter List
            List <Critter> cL = new List <Critter>();

            // Parse string speciesName into an enum
            ESpecies currentSpecies = (ESpecies)System.Enum.Parse(typeof(ESpecies), speciesName);

            // foreach through each critter in critterList and if the species in critter matches the currentSpecies
            // then add critter into cL list
            foreach (Critter c in critterList)
            {
                if (c.Species == currentSpecies)
                {
                    cL.Add(c);
                }
            }

            //return the list
            return(cL);
        }
예제 #7
0
 public Critter(string name, ESpecies species)
 {
     this.name = name;
     Species = species;
     imageFileName = "images/" + name + ".jpg";
 }
예제 #8
0
 public Fish(Fish p)
     : this(p._ocean, p._position, p._currentTimeToReproduce, p._timeToReproduce)
 {
     _kind = ESpecies.Fish;
 }
예제 #9
0
 public Fish(IOcean ocean, Coordinate pos, int curTimeToReproduce, int timeToReproduce)
     : base(ocean, pos, curTimeToReproduce, timeToReproduce)
 {
     _kind = ESpecies.Fish;
 }
예제 #10
0
 public Animal(string name, ESpecies species)
 {
     this.name     = name;
     Species       = species;
     imageFileName = "../../../images/" + name + ".jpg";
 }
예제 #11
0
 public Shark(Shark sh)
     : base(sh)
 {
     _kind = ESpecies.Shark;
 }
예제 #12
0
 public Shark(IOcean ocean, Coordinate pos, int curTimeToReproduce, int curTimeToFeed, int timeToReproduce, int timeToFeed)
     : base(ocean, pos, curTimeToReproduce, curTimeToFeed, timeToReproduce, timeToFeed)
 {
     _kind = ESpecies.Shark;
 }
예제 #13
0
 public Tuna(Tuna sh)
     : base(sh)
 {
     _kind = ESpecies.Tuna;
 }
예제 #14
0
 public Critter(string name, ESpecies species)
 {
     this.name     = name;
     Species       = species;
     imageFileName = "images/" + name + ".jpg";
 }