Пример #1
0
        //method stock aquarium
        //int parameter and random object parameter
        //return fish array
        static public Fish[] StockAquarium(int numFish, Random rand)
        {
            //declare fish array
            Fish[] fishes = new Fish[numFish];
            //print infor
            Console.WriteLine("*****Stocking the aquariums!*****");
            //for loop to create random fishes
            for (int i = 0; i < numFish; i++)
            {
                int gene;               //create a viable to hold random number
                gene = rand.Next(0, 4); //assign random number
                //sweitch to create random fishes
                switch (gene)
                {
                case 0:
                    fishes[i] = new PShrimp(rand);
                    break;

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

                case 2:
                    fishes[i] = new KnifeFish("Ghost Knife", rand);
                    break;

                default:
                    fishes[i] = new Fish(rand);
                    break;
                }
            }
            return(fishes);    //return fishes array
        }
Пример #2
0
 //constructor
 public Goby(string _name, Random _myRand) : base(_myRand)
 {
     partner = null;
     name    = _name + " " + name;
     shape   = " ౨><o))}D> ";
     price   = (double)myRand.Next(37, 71);
 }
Пример #3
0
 //method to choose pshrimp
 //fish array parameter
 //no return
 public void ChoosePShrimp(Fish[] fish)
 {
     for (int i = 0; i < fish.Length; i++)
     {
         //condition if fish is shrimp, goby and shrimp does not have partner
         if ((fish[i] is PShrimp) && (((PShrimp)fish[i]).Partner == null) && (partner == null))
         {
             //assign shrimp object to partner
             partner = new PShrimp(myRand);
             //assign shrimp's partner to goby
             ((PShrimp)fish[i]).Partner = this;
             //display partner information
             Console.WriteLine("     {0} partnered with shrimp {1}", name, partner.Name);
         }
     }
 }