public void SpawnBasicAK() { factory = FactoryProducer.GetFactory(FactoryType.AK); m_Basic = factory.GetAK(AttachmentType.Basic); Debug.Log("Accuracy: " + m_Basic.GetAccuracy()); Debug.Log("Ammo: " + m_Basic.GetAmmo()); }
public void SpawnLarge(ProduceRequirements requirements) { factory = FactoryProducer.GetFactory(FactoryType.Large); if (requirements.green) { GameObject produce = Instantiate(cabbagePrefab); outputText.text = "Created cabbage."; m_Cabbage = factory.GetLarge(LargeType.Cabbage); m_Cabbage.Enlarge(); } else if (requirements.yellow) { GameObject produce = Instantiate(pineapplePrefab); outputText.text = "Created a pineapple."; m_Pineapple = factory.GetLarge(LargeType.Pineapple); m_Pineapple.Enlarge(); } else { GameObject produce = Instantiate(pumpkinPrefab); outputText.text = "Created a pumpkin."; m_Pumpkin = factory.GetLarge(LargeType.Pumpkin); m_Pumpkin.Enlarge(); } }
public void SpawnAnimals() { factory = FactoryProducer.GetFactory(FactoryType.Animal); m_Cat = factory.GetAnimal(AnimalType.Cat); m_Bird = factory.GetAnimal(AnimalType.Bird); m_Cat.Voice(); m_Bird.Voice(); }
public static void Main(string[] args) { FactoryProducer producer = new FactoryProducer(); // producing set of red widgets AbstractShapeFactory redFactory = producer.GetFactory("Red"); IShape shape1 = redFactory.GetShape("CIRCLE"); IShape shape2 = redFactory.GetShape("RECTANGLE"); IShape shape3 = redFactory.GetShape("SQUARE"); shape1.draw(); shape2.draw(); shape3.draw(); // producing set of green widgets AbstractShapeFactory greenFactory = producer.GetFactory("Green"); IShape shape4 = greenFactory.GetShape("CIRCLE"); IShape shape5 = greenFactory.GetShape("RECTANGLE"); IShape shape6 = greenFactory.GetShape("SQUARE"); shape4.draw(); shape5.draw(); shape6.draw(); // producing set of blue widgets AbstractShapeFactory blueFactory = producer.GetFactory("Blue"); IShape shape7 = blueFactory.GetShape("CIRCLE"); IShape shape8 = blueFactory.GetShape("RECTANGLE"); IShape shape9 = blueFactory.GetShape("SQUARE"); shape7.draw(); shape8.draw(); shape9.draw(); }
static void Main(string[] args) { AbstractFactory shapeFactory = FactoryProducer.getFactory("SHAPE"); Shape shape1 = shapeFactory.getShape("Circle"); shape1.draw(); Shape shape2 = shapeFactory.getShape("Square"); shape2.draw(); Shape shape3 = shapeFactory.getShape("Rectangle"); shape3.draw(); var line = Console.ReadLine(); AbstractFactory colorFactory = FactoryProducer.getFactory("COLOR"); Color col1 = colorFactory.getColor("Red"); col1.fill(); Color col2 = colorFactory.getColor("Blue"); col2.fill(); Color col3 = colorFactory.getColor("Green"); col3.fill(); line = Console.ReadLine(); }
private void SpawnIndestructible() { AbstractFactory indestrFactory = FactoryProducer.GetFactory("Indestructible"); List <Sprite> indestructables = new List <Sprite>(); Sprite barbWireObj = indestrFactory.GetIndestructible("BarbWire").SpawnObject(); Sprite wallObj = indestrFactory.GetIndestructible("Wall").SpawnObject(); Sprite bushObj = indestrFactory.GetIndestructible("Bush").SpawnObject(); indestructables.Add(barbWireObj); indestructables.Add(wallObj); indestructables.Add(bushObj); foreach (Sprite indestructable in indestructables) { bool isSpawned = ForceSpawnObject(indestructable); if (isSpawned) { if (indestructable != bushObj) { GameState.Collidables.Add(indestructable); } else { GameState.NonCollidableRep.GetIterator().Add(indestructable); } //GameState.NonCollidables.Add(indestructable); } } }
static void Main(string[] args) { AbstractFactory shapefactory = FactoryProducer.GetFactory("Shape"); Ishape shape1 = shapefactory.GetIshape("Rectangle"); shape1.draw(); Ishape shape2 = shapefactory.GetIshape("Square"); shape2.draw(); AbstractFactory colorfactory = FactoryProducer.GetFactory("Color"); Icolor color1 = colorfactory.GetIcolor("red"); color1.fill(); Icolor color2 = colorfactory.GetIcolor("green"); color2.fill(); //单例 danli newclass = danli.GetDanli(); danli newclass2 = danli.GetDanli(); //建造者模式 Customer customer1 = new Customer(); customer1.BuyComputer(); Console.Read(); }
public void SpawnAnimals() { factory = FactoryProducer.GetFactory(FactoryType.Animal); m_Cat = factory.GetAnimal(AnimalType.Cat); m_Dog = factory.GetAnimal(AnimalType.Dog); m_Cat.Voice(); m_Dog.Voice(); }
private DialogManager() { main = Application.Current.MainWindow as MainWindow; instructionFactory = FactoryProducer.GetFactory("instruction"); string username = string.Empty; }
static void Main(string[] args) { var factory = FactoryProducer.GetFactory("ShapeFactory"); factory.GetShape("Circle").Draw(); factory = FactoryProducer.GetFactory("ColorFactory"); factory.GetColor("Red").Fill(); }
static void Main(string[] args) { AbstractHandlerFactory factory = FactoryProducer.GetFactory("Entity"); factory.GetEntityHandlerFactory("A").DoOperation("Read", "Dest"); factory.GetEntityHandlerFactory("B").DoOperation("Copy", "Dest"); factory.GetEntityHandlerFactory("C").DoOperation("Delete", "Src"); Console.ReadLine(); }
public void SpawnHumans() { factory = FactoryProducer.GetFactory(FactoryType.Human); m_FratBoi = factory.GetHuman(HumanType.FratBoi); m_Farmer = factory.GetHuman(HumanType.Farmer); m_Shopowner = factory.GetHuman(HumanType.Shopowner); m_FratBoi.Speak(); m_Farmer.Speak(); m_Shopowner.Speak(); }
public void SpawnHumans() { factory = FactoryProducer.GetFactory(FactoryType.Human); m_Beggar = factory.GetHuman(HumanType.Beggar); m_Farmer = factory.GetHuman(HumanType.Farmer); m_Shopowner = factory.GetHuman(HumanType.Shopowner); //m_Beggar.Speak(); //m_Farmer.Speak(); //m_Shopowner.Speak(); }
public void FactoryTest() { IAbstractItemFactory f = FactoryProducer.GetFactory("shape"); IName s = f.GetItem("Rectangle"); Assert.Equal("Rectangle", s.Name()); f = FactoryProducer.GetFactory("beam"); s = f.GetItem("Rectangle"); Assert.Equal("RectangleBeam", s.Name()); }
public void Run() { AbstractFactory shapeFactory = FactoryProducer.GetFactory(FactoryType.Shape); Shape shape = shapeFactory.GetShape(ShapeType.Circle); shape.Draw(); AbstractFactory engineFactory = FactoryProducer.GetFactory(FactoryType.Engine); Engine engine = engineFactory.GetEngine(EngineType.Diesel); engine.Start(); }
public int CreateBA(int playerId) { //BattleArena tempBA = new BattleArena(); AbstractFactory abstractFactory = FactoryProducer.getFactory(false); BattleArena tempBA = abstractFactory.getBattleArena("basic"); tempBA.PlayerId = playerId; _context.BattleArenas.Add(tempBA); _context.SaveChanges(); return(GetBAId(playerId)); }
private void initGame() { board = new Board(); shapeFactory = FactoryProducer.getFactory(); shape = shapeFactory.getShape(rnd.Next(1, 6)); shapesInTheBottom = new List <IShape>(); timerAni.Enabled = false; if (context.getState() == gameReset) { pictureBox1.Invalidate(); } }
public void Test_For_When_Given_A_Different_Shape() { // Arrange var myFactory = FactoryProducer.getFactory("Shape"); // Act 1 var shape1 = myFactory.getShape("Triangle"); // Assert Assert.AreEqual(shape1, null); }
public void NewLevel(int level) { FactoryProducer factoryProducer = new FactoryProducer(); levelFactory = factoryProducer.getFactory(level); //Get the factory for the level library = levelFactory.createLibrary(); //Creates Library Associated with LevelLibrary String word = library.generateWord(); //Generates a word from LevelLibrary shape = levelFactory.createShape(); //Creates the Shape and color of shape for level delaytime = levelFactory.getDelay(); this.level = levelFactory.getLevel(); //Only needed for if dynamic linkage doesnt work, makes sure to get the true level IntLevelLabel.Text = this.level.ToString(); }
static void FactoryPattern() { Console.WriteLine("工厂模式"); IShape myShape = new ShapeFactory().GetShape(Shapes.SQUARE); myShape.Draw(); Console.WriteLine("抽象工厂模式"); var shapeFactory = FactoryProducer.GetFactory(Factorys.SHAPE); shapeFactory.GetShape(Shapes.CIRCLE).Draw(); shapeFactory.GetColor(Colors.YELLOW).Fill();//图形工厂是不可以调用颜色工厂的方法的 }
/// <summary> /// 得到一个RedisClient /// </summary> /// <returns></returns> private void GetClient() { try { ICacheFactory cacheFactory = FactoryProducer.GetFactory("Redis"); RedisClient redisClients = ((RedisManage)cacheFactory.GetRedisInstance()).GetRedisClient(); redisClients.ChangeDb(Convert.ToInt64(4)); redisClient = redisClients; } catch (Exception) { throw; } }
public Ally SpawnAlly(AllyType allyType) { switch (_creationalPatternToUse) { case CreationalPatterns.Singleton: return(AllyFactory.Instance.GetAlly(allyType) as Ally); case CreationalPatterns.Factory: if (_allyFactory == null) { _allyFactory = FactoryProducer.GetFactory(FactoryType.Ally); } return(_allyFactory?.GetAlly(allyType) as Ally); } return(null); }
public Enemy SpawnEnemy(EnemyType enemyType) { switch (_creationalPatternToUse) { case CreationalPatterns.Singleton: return(EnemyFactory.Instance.GetEnemy(enemyType) as Enemy); case CreationalPatterns.Factory: if (_enemyFactory == null) { _enemyFactory = FactoryProducer.GetFactory(FactoryType.Enemy); } return(_enemyFactory?.GetEnemy(enemyType) as Enemy); } return(null); }
public Verdict RunTest() { //create factory based on the file extension var factory = FactoryProducer.GetFactory(Path.GetExtension(_inputFilePath)); //construct transformer and apply transformations var transformer = factory.CreateTransformer(); WriteLine($"Starting transformation of {_inputFilePath}"); var transformations = transformer.Transform(InputFileContent, Policy); if (!ValidateTransformations(transformations)) { var errorVerdict = new Verdict(); errorVerdict.TransformationResult = transformations; return(errorVerdict); } WriteLine($"Transformation completed. Generated {transformations.CodeTransformations.Count} code versions."); //persist transformed code if (_saveTransformations) { transformations.SaveTransformations(_inputFilePath); WriteLine($"Saved the transformed code versions to {Path.GetDirectoryName(_inputFilePath)}"); } //construct scheduler and schedule the code for execution WriteLine($"Starting scheduler."); var scheduler = factory.CreateScheduler(); try { scheduler.Schedule(transformations.CodeTransformations, _arguments); } catch (Exception ex) { var errorVerdict = new Verdict(); transformations.Errors.Add(ex.ToString()); errorVerdict.TransformationResult = transformations; return(errorVerdict); } WriteLine($"Scheduler completed."); //determine verdict after execution return(scheduler.GetVerdict(transformations.OutputChannels)); }
public void SpawnAnimals() { factory = FactoryProducer.GetFactory(FactoryType.Animal); if (!(env.time.text == "9:00 AM") && (env.isRaining == false)) { m_Cat = factory.GetAnimal(AnimalType.Cat); m_Cat.Voice(); GameObject catInstance = Instantiate(Resources.Load("Cat", typeof(GameObject))) as GameObject; catInstance.transform.position = new Vector3((Random.Range(-10f, 10f)), 0, 0); } else { m_Dog = factory.GetAnimal(AnimalType.Dog); m_Dog.Voice(); GameObject dogInstance = Instantiate(Resources.Load("Dog", typeof(GameObject))) as GameObject; dogInstance.transform.position = new Vector3((Random.Range(-10f, 10f)), 0, 0); } }
public void Test() { //获取形状工厂 AbstractFactory shapeFactory = FactoryProducer.getFactory <ShapeFactory>(); //获取形状为 Circle 的对象 Shape shape1 = shapeFactory.getShape <Circle>(); //调用 Circle 的 draw 方法 shape1.draw(); //获取形状为 Rectangle 的对象 Shape shape2 = shapeFactory.getShape <Rectangle>(); //调用 Rectangle 的 draw 方法 shape2.draw(); //获取形状为 Square 的对象 Shape shape3 = shapeFactory.getShape <Square>(); //调用 Square 的 draw 方法 shape3.draw(); //获取颜色工厂 AbstractFactory colorFactory = FactoryProducer.getFactory <ColorFactory>(); //获取颜色为 Red 的对象 Color color1 = colorFactory.getColor <Red>(); //调用 Red 的 fill 方法 color1.fill(); //获取颜色为 Green 的对象 Color color2 = colorFactory.getColor <Green>(); //调用 Green 的 fill 方法 color2.fill(); //获取颜色为 Blue 的对象 Color color3 = colorFactory.getColor <Blue>(); //调用 Blue 的 fill 方法 color3.fill(); }
static void Main(string[] args) { //获取形状工厂 AbstractFactory shapeFactory = FactoryProducer.GetFactory("SHAPE"); //获取形状为 Circle 的对象 IShape shape1 = shapeFactory.GetShape("CIRCLE"); //调用 Circle 的 Draw 方法 shape1.Draw(); //获取形状为 Rectangle 的对象 IShape shape2 = shapeFactory.GetShape("RECTANGLE"); //调用 Rectangle 的 Draw 方法 shape2.Draw(); //获取形状为 Square 的对象 IShape shape3 = shapeFactory.GetShape("SQUARE"); //调用 Square 的 Draw 方法 shape3.Draw(); //获取颜色工厂 AbstractFactory colorFactory = FactoryProducer.GetFactory("COLOR"); //获取颜色为 Red 的对象 IColor color1 = colorFactory.GetColor("RED"); //调用 Red 的 Fill 方法 color1.Fill(); //获取颜色为 Green 的对象 IColor color2 = colorFactory.GetColor("GREEN"); //调用 Green 的 Fill 方法 color2.Fill(); //获取颜色为 Blue 的对象 IColor color3 = colorFactory.GetColor("BLUE"); //调用 Blue 的 Fill 方法 color3.Fill(); }
static void AbstructFactory() { //get shape factory AbstructFactory.AbstructFactory shapeFactory = FactoryProducer.getFactory("SHAPE"); //get an object of Shape Circle AbstructFactory.Shape shape1 = shapeFactory.GetShape("CIRCLE"); //call draw method of Shape Circle shape1.Drow(); //get an object of Shape Rectangle AbstructFactory.Shape shape2 = shapeFactory.GetShape("RECTANGLE"); //call draw method of Shape Rectangle shape2.Drow(); //get an object of Shape Square AbstructFactory.Shape shape3 = shapeFactory.GetShape("SQUARE"); //call draw method of Shape Square shape3.Drow(); //get color factory AbstructFactory.AbstructFactory colorFactory = FactoryProducer.getFactory("COLOR"); //get an object of Color Red AbstructFactory.Color color1 = colorFactory.GetColor("RED"); //call fill method of Red color1.Fill(); //get an object of Color Green AbstructFactory.Color color2 = colorFactory.GetColor("Green"); //call fill method of Green color2.Fill(); //get an object of Color Blue AbstructFactory.Color color3 = colorFactory.GetColor("BLUE"); //call fill method of Color Blue color3.Fill(); }
public void SpawnVeggies(ProduceRequirements requirements) { factory = FactoryProducer.GetFactory(FactoryType.Veggie); if (requirements.green) // If it's a green vegetable, spawn Broccoli { GameObject produce = Instantiate(broccoliPrefab); outputText.text = "Created broccoli."; m_Broccoli = factory.GetVeggie(VeggieType.Broccoli); m_Broccoli.Vegetate(); } else if (requirements.yellow) // If it's a yellow vegetable, spawn a Potato { GameObject produce = Instantiate(potatoPrefab); outputText.text = "Created a potato."; m_Potato = factory.GetVeggie(VeggieType.Potato); m_Potato.Vegetate(); } else if (requirements == null) // if no requirements are given, spawn all vegetables //This is the case for when the user presses the vegetable key { m_Carrot = factory.GetVeggie(VeggieType.Carrot); m_Broccoli = factory.GetVeggie(VeggieType.Broccoli); m_Potato = factory.GetVeggie(VeggieType.Potato); m_Carrot.Vegetate(); m_Broccoli.Vegetate(); m_Potato.Vegetate(); } else // Otherwise spawn a carrot { GameObject produce = Instantiate(carrotPrefab); outputText.text = "Created a carrot."; m_Carrot = factory.GetVeggie(VeggieType.Carrot); m_Carrot.Vegetate(); } }
private void SpawnDestructible() { AbstractFactory destrFactory = FactoryProducer.GetFactory("Destructible"); List <Sprite> destructables = new List <Sprite>(); Sprite healthCrateObj = destrFactory.GetDestructible("HealthCrate").SpawnObject(); Sprite itemCrateObj = destrFactory.GetDestructible("ItemCrate").SpawnObject(); destructables.Add(healthCrateObj); destructables.Add(itemCrateObj); foreach (Sprite destructable in destructables) { bool isSpawned = ForceSpawnObject(destructable); if (isSpawned) { GameState.Collidables.Add(destructable); } } }
public void SpawnFruit(ProduceRequirements requirements) { factory = FactoryProducer.GetFactory(FactoryType.Fruit); if (requirements.green) // If it is a green fruit, spawn an avocado { GameObject produce = Instantiate(avocadoPrefab); outputText.text = "Created an avocado."; m_Avocado = factory.GetFruit(FruitType.Avocado); m_Avocado.Fruitify(); } else if (requirements.yellow) // if it is a yellow fruit, spawn a banana { GameObject produce = Instantiate(bananaPrefab); outputText.text = "Created a banana."; m_Banana = factory.GetFruit(FruitType.Banana); m_Banana.Fruitify(); } else if (requirements == null) // if no requirements are given, spawn all fruits // This is for the case when the user presses the fruit key { m_Apple = factory.GetFruit(FruitType.Apple); m_Banana = factory.GetFruit(FruitType.Banana); m_Avocado = factory.GetFruit(FruitType.Avocado); m_Apple.Fruitify(); m_Banana.Fruitify(); m_Avocado.Fruitify(); } else // Otherwise spawn an apple { GameObject produce = Instantiate(applePrefab); outputText.text = "Created an apple."; m_Apple = factory.GetFruit(FruitType.Apple); m_Apple.Fruitify(); } }