public static void Main() { // Build a collection of all vehicles that fly // With a single `foreach`, have each vehicle Fly() var airplane = new KingJet(200, "White", 9); var helecopter = new BlackHawk(150, "Black", 5); List <Aircraft> aircrafts = new List <Aircraft>(); aircrafts.Add(airplane); aircrafts.Add(helecopter); foreach (var aircraft in aircrafts) { aircraft.Fly(); } // Build a collection of all vehicles that operate on roads // With a single `foreach`, have each road vehicle Drive() var audi = new Audi("Snow White", 32, 5); var tesla = new Tesla("Black", 0, 5); List <CarBase> cars = new List <CarBase>(); cars.Add(audi); cars.Add(tesla); foreach (var car in cars) { car.Drive(); } // Build a collection of all vehicles that operate on water // With a single `foreach`, have each water vehicle Drive() var speed = new Speedboat(100, "Blue", 7); var jetski = new Jetski(20, "Yellow", 2); List <Watercraft> boats = new List <Watercraft>(); boats.Add(speed); boats.Add(jetski); foreach (var boat in boats) { boat.Driving(); } Console.ReadLine(); }
public static void Main() { // Build a collection of all vehicles that fly List <IAir> aircrafts = new List <IAir>(); C5 galaxy = new C5(); aircrafts.Add(galaxy); Cessna bird = new Cessna(); aircrafts.Add(bird); Boieng747 southwest = new Boieng747(); aircrafts.Add(southwest); // With a single `foreach`, have each vehicle Fly() foreach (var air in aircrafts) { air.Fly(); } // Build a collection of all vehicles that operate on roads List <ILand> rovers = new List <ILand>(); Motorcycle motorcycle = new Motorcycle(); StationWagon leBaron = new StationWagon(); Lancer lancer = new Lancer(); rovers.Add(motorcycle); rovers.Add(leBaron); rovers.Add(lancer); // With a single `foreach`, have each road vehicle Drive() foreach (var rover in rovers) { rover.Drive(); } // Build a collection of all vehicles that operate on water List <IWater> floats = new List <IWater>(); JetSki yamaha = new JetSki(); Speedboat smuggler = new Speedboat(); Yacht money = new Yacht(); floats.Add(yamaha); floats.Add(smuggler); floats.Add(money); // With a single `foreach`, have each water vehicle Drive() foreach (var floaties in floats) { floaties.Drive(); } }
public static Unit BuildUnitHMI(TypeEntite type, Case position, Joueur j) { Unit unit = null; switch (type) { case TypeEntite.ASTRONEF: unit = new Spaceship((Unite)FabriqueUnite.CreeUnite(type, position, j), _map); unit.Image = new Image() { Source = new BitmapImage(fileLoader.GetUri("astronef.png")), }; break; case TypeEntite.BARGE: unit = new BargeHMI((Unite)FabriqueUnite.CreeUnite(type, position, j)); unit.Image = new Image() { Source = new BitmapImage(fileLoader.GetUri("barge.png")) }; break; case TypeEntite.TANK: unit = new TankHMI((Unite)FabriqueUnite.CreeUnite(type, position, j)); unit.Image = new Image() { Source = new BitmapImage(fileLoader.GetUri("tank.png")) }; break; case TypeEntite.CRABE: unit = new Crab((Unite)FabriqueUnite.CreeUnite(type, position, j)); unit.Image = new Image() { Source = new BitmapImage(fileLoader.GetUri("Crab3.png")) }; break; case TypeEntite.GROS_TAS: unit = new T99((Unite)FabriqueUnite.CreeUnite(type, position, j)); unit.Image = new Image() { Source = new BitmapImage(fileLoader.GetUri("big_tank.png")) }; break; case TypeEntite.PONDEUSE: unit = new WeatherLayerHMI((Unite)FabriqueUnite.CreeUnite(type, position, j)); unit.Image = new Image() { Source = new BitmapImage(fileLoader.GetUri("weather_layer.png")) }; break; case TypeEntite.VEDETTE: unit = new Speedboat((Unite)FabriqueUnite.CreeUnite(type, position, j)); unit.Image = new Image() { Source = new BitmapImage(fileLoader.GetUri("boat.png")), }; break; } unit.Image.Height = unit.Height; unit.Image.Width = unit.Width; unit.AddHandler(); return(unit); }