static void Main(string[] args) { using (FishTank ft = new FishTank("Aquarium")) //using "using" will call dispose for us when done. { System.Console.WriteLine("Hello world!"); System.Console.WriteLine("... and we have a FishTank: " + ft.Name); ft.add(new Trout("Billy1")); ft.add(new Trout("Billy2")); ft.add(new Trout("Billy3")); ft.add(new Trout("Billy4")); ft.add(new Pirhana("Jimmy1")); ft.add(new Pirhana("Jimmy2")); ft.add(new Pirhana("Jimmy3")); ft.add(new Rock("Lumpy1")); ft.add(new Reticulata("Slurpy1")); for (int i = 0; i < NUM_TIMES_TO_RUN; i++) { ft.run(); System.Threading.Thread.Sleep(HOW_LONG_BETWEEN_RUNS); } } Console.ReadKey(); //by the time we get here, the tank is disposed. }
private const int HOW_LONG_BETWEEN_RUNS = 1000; //ms static void Main(string[] args) { using (FishTank ft = new FishTank("Aquarium")) //using "using" will call dispose for us when done. { System.Console.WriteLine("Hello world!"); System.Console.WriteLine("... and we have a FishTank: " + ft.Name); ft.add(new Trout("Billy1")); ft.add(new Trout("Billy2")); ft.add(new Trout("Billy3")); ft.add(new Trout("Billy4")); ft.add(new Pirhana("Jimmy1")); ft.add(new Pirhana("Jimmy2")); ft.add(new Pirhana("Jimmy3")); ft.add(new Rock("Lumpy1")); ft.add(new Reticulata("Slurpy1")); for (int i = 0; i < NUM_TIMES_TO_RUN; i++) { ft.run(); System.Threading.Thread.Sleep(HOW_LONG_BETWEEN_RUNS); } } Console.ReadKey(); //by the time we get here, the tank is disposed. }
/** * Make sure we don't have too many pirhana's! we can only be with one other. */ public override bool isCompatibleFishTank(FishTank fishTank) { int num_pirhanas = 0; bool is_compatible = true; foreach (var item in fishTank.items) { if (item is Pirhana) { num_pirhanas++; } } if (num_pirhanas >= MAX_NUM_PIRHANAS_PER_TANK) { is_compatible = false; log(" NOOOOOOOOOOOOOO! don't put me in there with those other Pirhanas! Only 2 allowed."); } else { is_compatible = base.isCompatibleFishTank(fishTank); } return(is_compatible); }
/** * Is this a compatible fishtank for this AqO? */ public virtual bool isCompatibleFishTank(FishTank fishTank) { //to start out with, all fishtanks are good. log("Cool, I like this aquarium."); return(true); }
/** * Make sure we don't have too many pirhana's! we can only be with one other. */ public override bool isCompatibleFishTank(FishTank fishTank) { int num_pirhanas = 0; bool is_compatible = true; foreach (var item in fishTank.items) { if (item is Pirhana) num_pirhanas++; } if (num_pirhanas >= MAX_NUM_PIRHANAS_PER_TANK) { is_compatible = false; log(" NOOOOOOOOOOOOOO! don't put me in there with those other Pirhanas! Only 2 allowed."); } else is_compatible = base.isCompatibleFishTank(fishTank); return is_compatible; }
/** * Is this a compatible fishtank for this AqO? */ public virtual bool isCompatibleFishTank(FishTank fishTank) { //to start out with, all fishtanks are good. log("Cool, I like this aquarium."); return true; }