示例#1
0
        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.
        }
示例#2
0
        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.
        }
示例#3
0
        /**
         * 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);
        }
示例#4
0
 /**
  * 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);
 }
示例#5
0
        /**
         * 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;
        }
示例#6
0
 /**
  * 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;
 }