public static void Run() { Console.WriteLine("*FACTORY METHOD*"); Console.WriteLine(); var knightFactory = new KnightFactory(); var archerFactory = new ArcherFactory(); var army = new List <IFighter> { GetFighter(knightFactory), GetFighter(archerFactory) }; army.ForEach(f => f.Attack()); Console.WriteLine(); Console.WriteLine("*ABSTRACT FACTORY*"); Console.WriteLine(); var humanBarracks = new HumanBarracks(); var orcBarracks = new OrcBarracks(); var humanCommander = new Commander(humanBarracks); var orcCommander = new Commander(orcBarracks); humanCommander.RecruitArmy(); orcCommander.RecruitArmy(); humanCommander.LaunchAttack(); orcCommander.LaunchAttack(); }
public Archer() { Name = "Лучник №1"; Hp = 80; AbstractFactory = ArcherFactory.Create(); Weapon = AbstractFactory.CreateWeapon("PlasticBow"); Armor = AbstractFactory.CreateArmor("WoodenChainMail"); }
public static void Main() { PlayerFactory archerFactory = new ArcherFactory(); var archerClient = new Client(archerFactory); archerClient.Run(); PlayerFactory healerFactory = new HealerFactory(); var healerClient = new Client(healerFactory); healerClient.Run(); Console.ReadKey(); }
static void Main(string[] args) { ICharacterFactory factory; Character character; //// Create archer factory = new ArcherFactory(); character = factory.Create(); //// Create warrior factory = new WarriorFactory(); character = factory.Create(); //// Create wizard factory = new WizardFactory(); character = factory.Create(); }
public void Initialize(int archers, int firemen, int icemen) { var archerFactory = new ArcherFactory(); var fireFactory = new FireFactory(); var iceFactory = new IceFactory(); for (int i = 0; i < archers; i++) { Add(archerFactory.CreateUnit(this)); } for (int i = 0; i < firemen; i++) { Add(fireFactory.CreateUnit(this)); } for (int i = 0; i < icemen; i++) { Add(iceFactory.CreateUnit(this)); } }
public IGame BuildGame() { // This composition of the game using poor man's DI does not support automatic registration. // To give a fairer view in the benchmark, it invokes the reflection used for automatic registration, // though it discards the results. var cityTypes = TypeConstraints.Cities; var cityFactoryTypes = TypeConstraints.CityFactories; var terrainTypes = TypeConstraints.Terrains; var terrainFactoryTypes = TypeConstraints.TerrainFactories; var unitTypes = TypeConstraints.Units; var unitFactoryTypes = TypeConstraints.UnitFactories; var productionProjectTypes = TypeConstraints.ProductionProjects; // :::: TURN-TAKING :::: var players = new[] { new Player("Red"), new Player("Blue") }; var turnTaking = new RoundRobinTurns(players); // :::: UNIT COMBAT :::: var unitCombat = new AttackerIsAlwaysVictorious(); // :::: WORLD MAP COLLECTIONS :::: var cities = new HashSet<ICity>(new CityEqualityComparer()); var terrains = new HashSet<ITerrain>(new TerrainEqualityComparer()); var units = new HashSet<IUnit>(new UnitEqualityComparer()); // :::: CITIES :::: var cityFactory = new CityFactory( () => new FriendlyCityManagementOnly<City>( new ProductionAccumulation<City>( new FixedGeneratedProduction<City>( new NoCityGrowth<City>(new City()) ), units, turnTaking ), turnTaking )); // :::: TERRAINS :::: var forestsFactory = new ForestsFactory(() => new Forests()); var hillsFactory = new HillsFactory(() => new Hills()); var mountainsFactory = new MountainsFactory(() => new Mountains()); var oceansFactory = new OceansFactory(() => new Oceans()); var plainsFactory = new PlainsFactory(() => new Plains()); // :::: UNITS :::: var archerFactory = new ArcherFactory( () => new FriendlyUnitManagementOnly<Archer>( new FortificationAction<Archer>( new NoEntranceToImpassableTerrain<Archer>( new NoFriendlyUnitStacking<Archer>( new LimitedMoveRange<Archer>( new OneToOneCombatEngagement<Archer>( new CityConquest<Archer>( new RestorationOfMoves<Archer>( new MoveCosts<Archer>( new Movability<Archer>(new Archer()) ), turnTaking ), cities ), units, unitCombat ) ), units ), terrains ) ), turnTaking )); var chariotFactory = new ChariotFactory( () => new FriendlyUnitManagementOnly<Chariot>( new FortificationAction<Chariot>( new NoEntranceToImpassableTerrain<Chariot>( new NoFriendlyUnitStacking<Chariot>( new LimitedMoveRange<Chariot>( new OneToOneCombatEngagement<Chariot>( new CityConquest<Chariot>( new RestorationOfMoves<Chariot>( new MoveCosts<Chariot>( new Movability<Chariot>(new Chariot()) ), turnTaking ), cities ), units, unitCombat ) ), units ), terrains ) ), turnTaking )); var legionFactory = new LegionFactory( () => new FriendlyUnitManagementOnly<Legion>( new NoEntranceToImpassableTerrain<Legion>( new NoFriendlyUnitStacking<Legion>( new LimitedMoveRange<Legion>( new OneToOneCombatEngagement<Legion>( new CityConquest<Legion>( new RestorationOfMoves<Legion>( new MoveCosts<Legion>( new Movability<Legion>(new Legion()) ), turnTaking ), cities ), units, unitCombat ) ), units ), terrains ), turnTaking )); var settlerFactory = new SettlerFactory( () => new FriendlyUnitManagementOnly<Settler>( new CityBuildingAction<Settler>( new NoEntranceToImpassableTerrain<Settler>( new NoFriendlyUnitStacking<Settler>( new LimitedMoveRange<Settler>( new OneToOneCombatEngagement<Settler>( new RestorationOfMoves<Settler>( new MoveCosts<Settler>( new Movability<Settler>(new Settler()) ), turnTaking ), units, unitCombat ) ), units ), terrains ), units, cities, cityFactory ), turnTaking )); // :::: WORLD MAP LAYERS :::: var cityLayer = new SimpleFixedCityLayer(cities, cityFactory); var terrainLayer = new SimpleFixedTerrainLayer(terrains, hillsFactory, mountainsFactory, oceansFactory, plainsFactory); var unitLayer = new SimpleFixedUnitLayer(units, archerFactory, legionFactory, settlerFactory); // :::: WORLD AGE :::: var worldAge = new DeceleratingWorldAge(turnTaking); // :::: WINNER STRATEGY :::: var winnerStrategy = new CityConquerorWins(cities); // :::: PRODUCTION PROJECTS :::: var productionProjects = new Dictionary<string, IProductionProject> { ["Archer"] = new ArcherProject(archerFactory), ["Chariot"] = new ChariotProject(chariotFactory), ["Legion"] = new LegionProject(legionFactory), ["Settler"] = new SettlerProject(settlerFactory), }; // :::: GAME :::: var game = new ExtenCivGame(cityLayer, terrainLayer, unitLayer, turnTaking, worldAge, winnerStrategy, productionProjects) { ContainerName = "Manual/SemiCiv" }; return game; }