Esempio n. 1
0
 private static void CovarianceTest()
 {
     //covariance allows you to use a derived class where a base class is expected (rule: can accept big if small is expected).
     Small s1 = new Small();
     Small s2 = new Big();
     Small s3 = new Bigger();
     Big   b1 = new Big();
     Big   b2 = new Bigger();
     //Big b3 = new Small();
 }
 public static void Execute()
 {
     Small sm1  = new Small();
     Small sm2  = new Big();
     Small sm3  = new Bigger();
     Big   big1 = new Big();
     Big   big2 = new Bigger();
     //IMyInterface2 imyint1 = new Bigger();
     //Huge h1 = new Big();
     //Big big3 = new Huge();
     //Big big3 = new Small();
 }
        private static void Example1()
        {

            //Covariance : an instance of more derived type object/class to be assign to less derived type object or class.
            //Pass derive type where base type expected
            Small sm1 = new Small();
            Small sm2 = new Big();
            Small sm3 = new Bigger();

            Big b1 = new Big();
            Big b2 = new Bigger();
            //Contravarience
            //Big b3 = new Small();
        }
        //public int SumToMaxInTree(int current, int max)
        //{
        //}


        public List <NumberNode> GetAll()
        {
            List <NumberNode> nodes = new List <NumberNode>();

            nodes.Add(this);
            if (Smaller != null)
            {
                nodes.AddRange(Smaller.GetAll());
            }
            if (Bigger != null)
            {
                nodes.AddRange(Bigger.GetAll());
            }
            return(nodes);
        }
 public int SumToMax(int current, int max)
 {
     if (Bigger != null)
     {
         current += Bigger.SumToMax(0, max - current);
     }
     if (Value <= max - current)
     {
         current  += Value;
         NodeColor = Microsoft.Glee.Drawing.Color.Red;
     }
     if (Smaller != null)
     {
         current += Smaller.SumToMax(0, max - current);
     }
     return(current);
 }
Esempio n. 6
0
 public PowerUp getPowerUp(PowerUpList chosenPowerUpID)
 {
     PowerUp chosenPowerUp = null;
     switch (chosenPowerUpID) {
     case PowerUpList.SlowDown:
         chosenPowerUp = new SlowDown(10);
         break;
     case PowerUpList.SpeedUp:
         chosenPowerUp = new SpeedUp(10);
         break;
     case PowerUpList.Warp:
         chosenPowerUp = new Warp(10);
         break;
     case PowerUpList.IceyPlayer:
         chosenPowerUp = new IceyPlayer(10);
         break;
     case PowerUpList.ObjectSpawnPowerUp:
         chosenPowerUp = new ObjectSpawnPowerUp(10);
         break;
     case PowerUpList.Pull:
         chosenPowerUp = new Pull(10);
         break;
     case PowerUpList.Push:
         chosenPowerUp = new Push(10);
         break;
     case PowerUpList.Bigger:
         chosenPowerUp = new Bigger(10);
         break;
     case PowerUpList.Smaller:
         chosenPowerUp = new Smaller(10);
         break;
     case PowerUpList.OrbitingShield:
         chosenPowerUp = new OrbitingShield(10);
         break;
     }
     return chosenPowerUp;
 }