//constructor public Goby(string nm, Random rand) : base(rand) { name = nm; partner = null; shape = " ౨><o))}D> "; price = rand.Next(34, 70); }
//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); }
//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; } }