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); } }
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]; } }
private void Eat(IVegetable vegetable) { this.Power += vegetable.PowerEffect; this.Stamina += vegetable.StaminaEffect; // Console.WriteLine(this.Name + " ate a " + vegetable.GetType().Name); }
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!"); } }
public void Cook(IVegetable vegetable) { this.Peel(vegetable); this.Cut(vegetable); var bowl = this.dishFactory.GetBowl(); bowl.Add(vegetable); }
private void PrepareVegetables(IVegetable firstVegetable, IVegetable secondVegetable) { this.Peel(firstVegetable); this.Peel(firstVegetable); this.Cut(secondVegetable); this.Cut(secondVegetable); }
public void Add(IVegetable veggie) { if (veggie == null) { throw new ArgumentNullException("Invalid argument"); } this.veggies.Add(veggie); }
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); }
public static bool CheckWhetherVegetableIsReadyForCooking(IVegetable vegetable) { bool result = false; if (vegetable != null && vegetable.IsCut && vegetable.IsFreesh) { result = true; } return(result); }
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); } }
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); }
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; } }
public static void CookPeeledVegetable(IChef chef, IVegetable vegetable) { if (vegetable == null) { return; } IContainable preparedMeal; if (vegetable.IsPeeled && !vegetable.IsRotten) { preparedMeal = chef.GetBowl(); } }
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); }
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); }
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); }
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); } } }
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); }
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(); } }
public void Cut(IVegetable potato) { //... }
public void Add(IVegetable vegetable) { this.vegetables.Add(vegetable); }
public void CollectVegetable(IVegetable vegetable) { this.collectedVegetables.Add(vegetable); }
public void Add(IVegetable veg) { this.Vegetables.Add(veg); }
internal void Add(IVegetable vegetable) { }
private bool CheckIfVegetableIsReadyToCook(IVegetable vegetable) { var isReady = vegetable.IsPeeled && vegetable.IsCut && !vegetable.IsRotten; return(isReady); }
public virtual void Run(IVegetable target) { }
public void Add(IVegetable vegetable) { }
public void CollectVegetable(IVegetable vegetable) { this.collectedVeggies.Add(vegetable); vegetable.HasBeenCollected = true; }
private IVegetable Peel(IVegetable vegetable) { throw new NotImplementedException(); }
private static void Cook(IVegetable potato) { Console.WriteLine("Cooking"); }
protected Vegetable(IVegetable vegetable) { this.Name = vegetable.Name; this.Weight = vegetable.Weight; this.Calories = vegetable.Calories; }
private void Peel(IVegetable vegitable) { //some logic }
public void Peel(IVegetable vegetable) { vegetable.IsPeeled = true; this.speachLog.Say("Peeling Done Young Awesome One!!!"); }
internal void Add(IVegetable vegetable) { }
public void RemoveVegetable(IVegetable vegetable) { this.vegetables.Remove(vegetable); }
private void Cut(IVegetable potato) { }
private void Cook(IVegetable potato) { throw new NotImplementedException(); }
private void Peel(IVegetable cookingProduct) { Console.WriteLine("Peeling"); }
private void Cut(IVegetable vegetable) { //... }
private void Peel(IVegetable vegetable) { }
private void Cut(IVegetable cookingProduct) { Console.WriteLine("Cutting"); }