示例#1
0
        public static void Main(string[] args)
        {
            var EntryAssembly = Assembly.Load("Crucifere");

            VegetableFactory factory        = new VegetableFactory();
            ProxyGenerator   proxyGenerator = new ProxyGenerator();

            while (true)
            {
                try
                {
                    IVegetable legume = factory.Provide();

                    //Exemple avec Classe
                    //legume = proxyGenerator.CreateClassProxy(legume.GetType(), new BasicInterceptor()) as IVegetable;
                    //legume = proxyGenerator.CreateInterfaceProxyWithTarget(legume, new MaskInterceptor()) as IVegetable;

                    //Exemple avec interface seule
                    //legume = proxyGenerator.CreateInterfaceProxyWithoutTarget(typeof(IVegetable),new BasicInterceptor()) as IVegetable;

                    Console.WriteLine("Legume:" + legume.GetNom());
                    legume.Prix = 12;

                    Console.WriteLine("\n");
                }
                catch (Exception e)
                {
                    Console.WriteLine("GROSS ERROR:" + e.Message);
                    Console.WriteLine(e.ToString());
                }
                Thread.Sleep(2000);
            }
        }
示例#2
0
        public void Cook(IVegetable firstVegetable, IVegetable secondVegetable, Bowl bowl)
        {
            var areIngridientsAvaliable = (firstVegetable != null) && (secondVegetable != null) && (bowl != null);

            if (!areIngridientsAvaliable)
            {
                this.speachLogger.Say("Oops, something went wrong with the ingridients, lets try again!");
                return;
            }

            this.PrepareVegetables(firstVegetable, secondVegetable);

            // Task 2
            var isPreparationComplete = this.CheckIfVegetableIsReadyToCook(firstVegetable) &&
                                        this.CheckIfVegetableIsReadyToCook(secondVegetable);

            if (isPreparationComplete)
            {
                bowl.Contents.Add(secondVegetable);
                bowl.Contents.Add(firstVegetable);

                this.speachLogger.Say("Awesome we got ourselves vegetables in a bowl!");
            }
            else
            {
                this.speachLogger.Say("Oops, I messed up the preparation of the products..");
            }
        }
 public static void Main()
 {
     //All we get here is a string representing the class
     string     className = "Tomato";
     Type       type      = this.GetType().Assembly.GetType(className); //reflection method to get a type that's called "Tomato"
     IVegetable veg       = (IVegetable)Activator.CreateInstance(type);
 }
 public void SetVegitable(IVegetable vegitable)
 {
     for (int i = 0; i < spriteRenderers.Length; i++)
     {
         spriteRenderers[i].sprite = vegitable.stateSpriteDictionary[ProcessingState.RAW];
     }
 }
示例#5
0
        private void Eat(IVegetable vegetable)
        {
            this.Power += vegetable.PowerEffect;
            this.Stamina += vegetable.StaminaEffect;

            // Console.WriteLine(this.Name + " ate a " + vegetable.GetType().Name);
        }
示例#6
0
        public void Cook(IVegetable firstVegetable, IVegetable secondVegetable, IContainable bowl)
        {
            var areIngridientsAvaliable = (firstVegetable != null) && (secondVegetable != null) && (bowl != null);

            if (!areIngridientsAvaliable)
            {
                this.speachLog.Say("Oops, bad stuff happened with the ingredients!");
                return;
            }

            this.PrepareVegetables(firstVegetable, secondVegetable);

            var isPreparationComplete = this.CheckIfVegetableIsReadyToCook(firstVegetable) &&
                                        this.CheckIfVegetableIsReadyToCook(secondVegetable);

            if (isPreparationComplete)
            {
                bowl.Contents.Add(secondVegetable);
                bowl.Contents.Add(firstVegetable);

                this.speachLog.Say("Awesome we got ourselves vegetables in a bowl!");
            }
            else
            {
                this.speachLog.Say("Oops, We Messed Up Brah!");
            }
        }
示例#7
0
        public void Cook(IVegetable vegetable)
        {
            this.Peel(vegetable);
            this.Cut(vegetable);
            var bowl = this.dishFactory.GetBowl();

            bowl.Add(vegetable);
        }
示例#8
0
        private void PrepareVegetables(IVegetable firstVegetable, IVegetable secondVegetable)
        {
            this.Peel(firstVegetable);
            this.Peel(firstVegetable);

            this.Cut(secondVegetable);
            this.Cut(secondVegetable);
        }
示例#9
0
        public void Add(IVegetable veggie)
        {
            if (veggie == null)
            {
                throw new ArgumentNullException("Invalid argument");
            }

            this.veggies.Add(veggie);
        }
示例#10
0
        public void Add(IVegetable vegetable)
        {
            if (this.vegetablesInBowl.Count > this.Capacity)
            {
                throw new ArgumentOutOfRangeException("The bowl has reached it's capacity!");
            }

            this.vegetablesInBowl.Add(vegetable);
        }
示例#11
0
        public static bool CheckWhetherVegetableIsReadyForCooking(IVegetable vegetable)
        {
            bool result = false;

            if (vegetable != null && vegetable.IsCut && vegetable.IsFreesh)
            {
                result = true;
            }

            return(result);
        }
示例#12
0
        public static IVegetable[] CloneObjectsToArray <T>(this ICloneCollection <T> source) where T : ICloneable
        {
            IVegetable[] copy = new IVegetable[source.Count];
            int          ind  = 0;

            foreach (var veg in source)
            {
                copy[ind] = (IVegetable)veg.Clone();
                ind++;
            }

            return(copy);
        }
        public static void CookPeeledVegetable(IChef chef, IVegetable vegetable, IOven oven)
        {
            if (vegetable == null)
            {
                return;
            }

            IMeal preparedMeal;

            if (vegetable.IsPealed && !vegetable.IsRotten)
            {
                preparedMeal = chef.Cook(oven);
            }
        }
示例#14
0
        private void MovePlayer(string command)
        {
            this.player.Move(command);

            IPlayer enemy =
                this.characters.Cast <IPlayer>()
                .FirstOrDefault(
                    x => x.Position.X == this.player.Position.X && x.Position.Y == this.player.Position.Y);

            IVegetable vegetable =
                this.vegetables.Cast <Vegetable>()
                .FirstOrDefault(
                    x => x.Position.X == this.player.Position.X && x.Position.Y == this.player.Position.Y);
        }
示例#15
0
        private void UpdateSprite(IItem item)
        {
            IVegetable vegetable = (IVegetable)item;

            if (vegetable != null)
            {
                this.vegetableSpriteRenderer.sprite  = vegetable.stateSpriteDictionary[ProcessingState.RAW];
                this.vegetableSpriteRenderer.enabled = true;
            }
            else
            {
                this.vegetableSpriteRenderer.enabled = false;
            }
        }
示例#16
0
        public static void CookPeeledVegetable(IChef chef, IVegetable vegetable)
        {
            if (vegetable == null)
            {
                return;
            }

            IContainable preparedMeal;

            if (vegetable.IsPeeled && !vegetable.IsRotten)
            {
                preparedMeal = chef.GetBowl();
            }
        }
示例#17
0
        public void Cook(IVegetable veggie)
        {
            if (veggie == null)
            {
                throw new ArgumentNullException();
            }

            Peel(veggie);
            Cut(veggie);

            IBowl bowl = GetBowl();

            bowl.Add(veggie);
        }
        public void Cook(IVegetable vegitable)
        {
            Potato potato = this.GetPotato();
            Carrot carrot = this.GetCarrot();

            this.Peel(potato);
            this.Peel(carrot);
            this.Cut(potato);
            this.Cut(carrot);

            Bowl bowl;

            bowl = this.GetBowl();
            bowl.Add(carrot);
            bowl.Add(potato);
        }
示例#19
0
        public override void Run(IVegetable target)
        {
            // Exécution avec génération du proxy
            var swGeneration = new Stopwatch();

            swGeneration.Start();

            var proxy = _proxyGenerator.CreateInterfaceProxyWithTarget <IVegetable>(target, new PerfInterceptor());

            proxy.GetNom();

            swGeneration.Stop();
            // ----------------------------------

            // Exécution avec proxy déjà généré
            var swDejaGenere = new Stopwatch();

            swDejaGenere.Start();

            proxy.GetNom();

            swDejaGenere.Stop();
            // ----------------------------------

            // Exécution sans proxy
            var swNoProxy = new Stopwatch();

            swNoProxy.Start();

            target.GetNom();

            swNoProxy.Stop();
            // ----------------------------------


            Console.WriteLine("| {0, -11} " +
                              "| {1,11} | {2,11} | {3,11} |",
                              target.GetNom(),
                              swGeneration.Elapsed.Ticks.ToMilliseconds(),
                              swDejaGenere.Elapsed.Ticks.ToMilliseconds(),
                              swNoProxy.Elapsed.Ticks.ToMilliseconds());
            WriteSeparatorLine();

            _ticksGeneration.Add(swGeneration.Elapsed.Ticks);
            _ticksdejaGenere.Add(swDejaGenere.Elapsed.Ticks);
            _ticksNoProxy.Add(swNoProxy.Elapsed.Ticks);
        }
示例#20
0
        public override void Run(IVegetable target)
        {
            var sw = new Stopwatch();

            sw.Start();

            target.GetNom();

            sw.Stop();

            Console.WriteLine("| {0, -11} | {1,11} |",
                              target.GetNom(),
                              sw.ElapsedTicks.ToMilliseconds());
            WriteSeparatorLine();

            _ticks.Add(sw.ElapsedTicks);
        }
示例#21
0
        private void GrowVegetable()
        {
            foreach (var growingVegetable in this.Database.GrowingVegetables)
            {
                if (!this.Database.Ninjas.Any(ninja =>
                                              ninja.Position.Equals(growingVegetable.Position)))
                {
                    growingVegetable.Grow();
                }

                if (growingVegetable.GrowthTime == 0)
                {
                    IVegetable      newVegetable = null;
                    IMatrixPosition position     = growingVegetable.Position;

                    switch (growingVegetable.VegetableHolder)
                    {
                    case VegetableType.Asparagus:
                        newVegetable = new Asparagus(position);
                        break;

                    case VegetableType.Broccoli:
                        newVegetable = new Broccoli(position);
                        break;

                    case VegetableType.CherryBerry:
                        newVegetable = new CherryBerry(position);
                        break;

                    case VegetableType.Mushroom:
                        newVegetable = new Mushroom(position);
                        break;

                    case VegetableType.Royal:
                        newVegetable = new Royal(position);
                        break;
                    }

                    this.Database.AddVegetable(newVegetable);
                    this.Database.SetGameFieldObject(growingVegetable.Position, newVegetable);
                }
            }
        }
示例#22
0
        public override void Run(IVegetable target)
        {
            var sw = new Stopwatch();

            sw.Start();

            var proxy = _proxyGenerator.CreateInterfaceProxyWithTarget <IVegetable>(target, new PerfInterceptor());

            proxy.GetNom();

            sw.Stop();

            Console.WriteLine("| {0, -11} | {1,11} |",
                              target.GetNom(),
                              sw.ElapsedTicks.ToMilliseconds());
            WriteSeparatorLine();

            _ticks.Add(sw.ElapsedTicks);
        }
示例#23
0
        private void ProcessMove(IMatrixPosition newPosition)
        {
            IMatrixPosition oldNinjaPosition = this.currentNinja.Position;

            this.currentNinja.Move(newPosition);

            if (this.Database.Vegetables.Any(veg => veg.Position.Equals(newPosition)))
            {
                IVegetable currentVegetable = this.Database.Vegetables.First(veg => veg.Position.Equals(newPosition));

                this.Database.RemoveVegetable(currentVegetable);
                this.currentNinja.CollectVegetable(currentVegetable);

                IBlankSpace newBlankSpace = new BlankSpace(this.currentNinja.Position,
                                                           currentVegetable.TimeToGrow,
                                                           (VegetableType)Enum.Parse(typeof(VegetableType), currentVegetable.GetType().Name));

                this.Database.AddGrowingVegetable(newBlankSpace);

                IBlankSpace oldFieldPositionElement = new BlankSpace(oldNinjaPosition, -1, VegetableType.Blank);

                if (this.Database.GrowingVegetables.Any(growingVegetable => growingVegetable.Position.Equals(oldNinjaPosition)))
                {
                    oldFieldPositionElement = this.Database.GrowingVegetables.First(growingVegetable =>
                                                                                    growingVegetable.Position.Equals(oldNinjaPosition));
                }

                this.Database.SetGameFieldObject(oldNinjaPosition, oldFieldPositionElement);
                this.Database.SetGameFieldObject(this.currentNinja.Position, this.currentNinja);
                return;
            }

            INinja otherNinja = this.Database.GetOtherPlayer(this.currentNinja.Name);

            if (this.currentNinja.Position.Equals(otherNinja.Position))
            {
                this.Fight();
            }
        }
示例#24
0
 public void Cut(IVegetable potato)
 {
     //...
 }
 public void Add(IVegetable vegetable)
 {
     this.vegetables.Add(vegetable);
 }
 public void CollectVegetable(IVegetable vegetable)
 {
     this.collectedVegetables.Add(vegetable);
 }
示例#27
0
 public void Add(IVegetable veg)
 {
     this.Vegetables.Add(veg);
 }
示例#28
0
 internal void Add(IVegetable vegetable)
 {
 }
示例#29
0
        private bool CheckIfVegetableIsReadyToCook(IVegetable vegetable)
        {
            var isReady = vegetable.IsPeeled && vegetable.IsCut && !vegetable.IsRotten;

            return(isReady);
        }
示例#30
0
 public virtual void Run(IVegetable target)
 {
 }
示例#31
0
 public void Add(IVegetable vegetable)
 {
 }
示例#32
0
 public void CollectVegetable(IVegetable vegetable)
 {
     this.collectedVeggies.Add(vegetable);
     vegetable.HasBeenCollected = true;
 }
示例#33
0
 private IVegetable Peel(IVegetable vegetable)
 {
     throw new NotImplementedException();
 }
 private static void Cook(IVegetable potato)
 {
     Console.WriteLine("Cooking");
 }
示例#35
0
 protected Vegetable(IVegetable vegetable)
 {
     this.Name = vegetable.Name;
     this.Weight = vegetable.Weight;
     this.Calories = vegetable.Calories;
 }
示例#36
0
 private void Peel(IVegetable vegitable)
 {
     //some logic
 }
示例#37
0
 public void Peel(IVegetable vegetable)
 {
     vegetable.IsPeeled = true;
     this.speachLog.Say("Peeling Done Young Awesome One!!!");
 }
示例#38
0
 internal void Add(IVegetable vegetable)
 {
 }
 public void RemoveVegetable(IVegetable vegetable)
 {
     this.vegetables.Remove(vegetable);
 }
示例#40
0
 private void Cut(IVegetable potato)
 {
 }
示例#41
0
 private void Cook(IVegetable potato)
 {
     throw new NotImplementedException();
 }
示例#42
0
 private void Peel(IVegetable cookingProduct)
 {
     Console.WriteLine("Peeling");
 }
 private void Cut(IVegetable vegetable)
 {
     //...
 }
示例#44
0
 private void Peel(IVegetable vegetable)
 {
 }
示例#45
0
 private void Cut(IVegetable cookingProduct)
 {
     Console.WriteLine("Cutting");
 }