示例#1
0
 public void ThinkAloud()
 {
     Console.WriteLine("Three injection methods!");
     if (PAnimal != null)
     {
         PAnimal.Say();
     }
     if (CAnimal != null)
     {
         CAnimal.Say();
     }
     if (MAnimal != null)
     {
         MAnimal.Say();
     }
     Console.WriteLine("Injiection array");
     if (Animals != null && Animals.Length > 0)
     {
         Animals.ToList().ForEach(it => it.Say());
     }
     Console.WriteLine("Injiection array with diferent methods");
     if (FeederNames != null && FeederNames.Length > 0)
     {
         FeederNames.ToList().ForEach(it => Console.WriteLine(it));
     }
     Console.WriteLine("Injection array null");
     if (PetNames != null && PetNames.Length > 0)
     {
         PetNames.ToList().ForEach(it => Console.WriteLine(it));
     }
 }
示例#2
0
        public void newWolf()
        {
            int x = rnd.Next(0, field.Width);
            int y = rnd.Next(0, field.Height);

            if (x <= 0)
            {
                x = 0;
            }
            if (x >= field.Width - sizeAnimal)
            {
                x = field.Width - sizeAnimal;
            }
            if (y <= 0)
            {
                y = 0;
            }
            if (y >= field.Height - sizeAnimal)
            {
                y = field.Height - sizeAnimal;
            }

            var wolf = new CAnimal();

            wolf.BackgroundImage = Properties.Resources.wolf;

            wolf.Width  = 48;
            wolf.Height = 48;
            wolf.Left   = x;
            wolf.Top    = y;
            wolfs.Add(wolf);
            // field.Controls.Add(wolf);
            countAllWolfs++;
            wolfCount.Text = "x" + countAllWolfs.ToString();
        }
示例#3
0
        public void newSheep()
        {
            int x = rnd.Next(0, field.Width);
            int y = rnd.Next(0, field.Height);

            if (x <= 0)
            {
                x = 0;
            }
            if (x >= field.Width - sizeAnimal)
            {
                x = field.Width - sizeAnimal;
            }
            if (y <= 0)
            {
                y = 0;
            }
            if (y >= field.Height - sizeAnimal)
            {
                y = field.Height - sizeAnimal;
            }

            var sheep = new CAnimal();

            sheep.BackgroundImage = Properties.Resources.sheep;

            sheep.Width  = 48;
            sheep.Height = 48;
            sheep.Left   = x;
            sheep.Top    = y;
            sheeps.Add(sheep);
            //field.Controls.Add(sheep);
            countAllSheeps++;
            sheepCount.Text = "x" + countAllSheeps.ToString();
        }
示例#4
0
 public bool isIntersect(CAnimal a1, CAnimal a2)
 {
     return((a2.Left < a1.Left + a1.Width) &&
            (a1.Left < (a2.Left + a2.Width)) &&
            (a2.Top < a1.Top + a1.Height) &&
            (a1.Top < a2.Top + a2.Height));
 }
示例#5
0
    static void Main()
    {
        int opcion = 0;

        Console.WriteLine("Elige que animal");

        Console.WriteLine("1.-Uno para perro");
        Console.WriteLine("2.-Dos para gato");
        opcion = Convert.ToInt32(Console.ReadLine());

        CAnimal animal = null;

        if (opcion == 1)
        {
            animal = new CPerro("perro");
        }
        if (opcion == 2)
        {
            animal = new CGato("gato");
        }

        animal.Moverse();
    }
示例#6
0
        public void calcPosition(CAnimal animal, int dir, int step)
        {
            switch (dir)
            {
            case 1:
            {
                animal.Top -= step;
                if (animal.Top <= 0)
                {
                    animal.Top = 0;
                }
                break;
            }

            case 2:
            {
                animal.Top -= step;
                if (animal.Top <= 0)
                {
                    animal.Top = 0;
                }
                animal.Left += step;
                if (animal.Left >= field.Width - sizeAnimal)
                {
                    animal.Left = field.Width - sizeAnimal;
                }
                break;
            }

            case 3:
            {
                animal.Left += step;
                if (animal.Left >= field.Width - sizeAnimal)
                {
                    animal.Left = field.Width - sizeAnimal;
                }
                break;
            }

            case 4:
            {
                animal.Top += step;
                if (animal.Top >= field.Height - sizeAnimal)
                {
                    animal.Top = field.Height - sizeAnimal;
                }
                animal.Left += step;
                if (animal.Left >= field.Width - sizeAnimal)
                {
                    animal.Left = field.Width - sizeAnimal;
                }
                break;
            }

            case 5:
            {
                animal.Top += step;
                if (animal.Top >= field.Height - sizeAnimal)
                {
                    animal.Top = field.Height - sizeAnimal;
                }
                break;
            }

            case 6:
            {
                animal.Top += step;
                if (animal.Top >= field.Height - sizeAnimal)
                {
                    animal.Top = field.Height - sizeAnimal;
                }
                animal.Left -= step;
                if (animal.Left <= 0)
                {
                    animal.Left = 0;
                }
                break;
            }

            case 7:
            {
                animal.Left -= step;
                if (animal.Left <= 0)
                {
                    animal.Left = 0;
                }
                break;
            }

            case 8:
            {
                animal.Top -= step;
                if (animal.Top <= 0)
                {
                    animal.Top = 0;
                }
                animal.Left -= step;
                if (animal.Left <= 0)
                {
                    animal.Left = 0;
                }
                break;
            }
            }
        }