Example #1
0
 //
 // Check function to see if Morg should hunt potential prey.
 //
 public bool toHunt(Morg hunter, Morg prey)
 {
     if (hunter.getMorgtype() == 'A' && (prey.getMorgtype() == 'B' || prey.getMorgtype() == 'C') && prey.getLiving())
         return true;
     if (hunter.getMorgtype() == 'B' && prey.getMorgtype() == 'A' && prey.getLiving())
         return true;
     if (hunter.getMorgtype() == 'C' && (prey.getMorgtype() == 'A' || prey.getMorgtype() == 'B') &&  prey.getLiving())
         return true;
     else
         return false;
 }
Example #2
0
        //
        //Assigns prey to Morg if non null value prey passed in
        //
        public void setPrey(Morg newPrey)
        {
            prey = newPrey;
            if (newPrey != null)
            {
                isfollowing = true;
                prey.registerObserver(this);
            }

            else
                isfollowing = false;
        }
Example #3
0
        //
        //Simulator constructor
        //
        public Simulator(Morg morg1, Morg morg2, Morg morg3)
        {
            morgList = new List<Morg>();
            morgList.Add(morg1);
            morgList.Add(morg2);
            morgList.Add(morg3);
            Random rnd = new Random();
            foreach ( Morg element in morgList)
            {
                int locX = rnd.Next(0, 9);
                int locY = rnd.Next(0, 9);

                element.setLocation(locX, locY);
            }
        }
Example #4
0
 //
 //feed behaviour for morg class
 //
 public void feed(Morg prey)
 {
     Console.WriteLine( name + " will" );
     feedBehavior.feed();
     Console.WriteLine(prey.name + "!");
 }