示例#1
0
 //constructor
 public Goby(string nm, Random rand) : base(rand)
 {
     name    = nm;
     partner = null;
     shape   = " ౨><o))}D> ";
     price   = rand.Next(34, 70);
 }
示例#2
0
        //static methods
        //fills a fish array with random fish types
        static Fish[] StockAquarium(int numfish, Random rand)
        {
            Fish[] fishies = new Fish[numfish];
            int    gene;

            Console.WriteLine("*****Stocking the aquariumS!*****");
            for (int i = 0; i < fishies.Length; i++)
            {
                gene = rand.Next(0, 4);
                switch (gene)
                {
                case 0:
                    fishies[i] = new PShrimp(rand);
                    break;

                case 1:
                    fishies[i] = new Goby("Goby " + i, rand);
                    break;

                case 2:
                    fishies[i] = new Knifefish("Ghost Knife " + i, rand);
                    break;

                case 3:
                    fishies[i] = new Fish(rand);
                    break;
                }
            }
            return(fishies);
        }
示例#3
0
 //methods
 //partners with a pshrimp
 public void ChoosePShrimp(Fish[] fi)
 {
     while (partner == null)
     {
         for (int i = 0; i < fi.Length; i++)
         {
             if (fi[i] is PShrimp)
             {
                 PShrimp ps = (PShrimp)fi[i];
                 if (ps.Partner == null)
                 {
                     this.partner = ps;
                     ps.Partner   = this;
                     fi[i]        = ps;
                     Console.WriteLine($"{name} partnered with shrimp {ps.Name}");
                     break;
                 }
             }
         }
         break;
     }
 }