public override void Update(IList <Entity> entities, double elapsedTime) { //Entities var entitiesToProcess = entities.Where(x => !x.ToRemove && x.HasComponent(6) && ((TypeComponent)x.GetComponent(5)).Type == Enums.EnumTypeEntity.ENEMY) .Select(x => new { Entity = x, Transform = ((TransformComponent)x.GetComponent(0)) }) .OrderByDescending(x => x.Transform.Y) .GroupBy(x => x.Transform.X) .Select(x => x.FirstOrDefault()); foreach (var e in entitiesToProcess) { ShootComponent shootComponent = (ShootComponent)e.Entity.GetComponent(6); var transformComponent = (TransformComponent)e.Entity.GetComponent(0); var typeComponent = (TypeComponent)e.Entity.GetComponent(5); shootComponent.LastShootTime += elapsedTime; if (shootComponent.LastShootTime > shootComponent.IntervalBetweenShoot * 1000) { var shoot = MyGame.Instance.World.EntityManager.CreateEntity(); FactoryEntity.CreateShoot(shoot, transformComponent.X, transformComponent.Y, 0, 1, 33, Enums.EnumTypeEntity.SHOOT_ENEMY); shootComponent.LastShootTime = 0; } } }
static void Main(string[] args) { AbstractDatabase objDAL = FactoryBD.StringConexao(); List <ProdutosVenda> produtos = new List <ProdutosVenda>() { new ProdutosVenda(1, 1, 1000) }; double valor = 0; produtos.ForEach(x => valor += x.PrecoUnitario); Venda venda = new Venda(valor, FormaPagamento.Dinheiro, new ClienteJuridico { Codigo = 20, Nome = "Ernane", Email = "ernane1", Nascimento = DateTime.Now, CNPJ = "123" }, produtos); venda.Descontar(); IVenda vendas = FactoryEntity.Venda(); vendas.RegistrarVenda(venda); }
public Generator(int timeToProduce, Ressource ressource, FactoryEntity parent) { this.timeToProduce = timeToProduce; this.ressource = ressource; this.parent = parent; timeSinceLastProduction = 0; }
public void AssignWorkerInventory(FactoryEntity factoryEntity) { this.mode = "assign"; gameObject.SetActive(true); this.factoryEntity = factoryEntity; DisplayInventory(); }
public void SetWorker(string mode, string name, string colorStr, int spriteNum, List <string> workstations, List <int> workstationStats, FactoryEntity factoryEntity = null) { this.mode = mode; if (mode == "assign") { this.factoryEntity = factoryEntity; } _image = gameObject.transform.Find("Image").GetComponent <Image>(); _name = gameObject.transform.Find("Name").GetComponent <Text>(); m_name = name; m_colorStr = colorStr; m_spriteNum = spriteNum; m_workstations = workstations; m_workstationStats = workstationStats; _proficiencies.Add(gameObject.transform.Find("Proficiency1").GetComponent <Text>()); _proficiencies.Add(gameObject.transform.Find("Proficiency2").GetComponent <Text>()); _stars0 = new List <GameObject> { _proficiencies[0].gameObject.transform.Find("Star img").gameObject, _proficiencies[0].gameObject.transform.Find("Star img (1)").gameObject, _proficiencies[0].gameObject.transform.Find("Star img (2)").gameObject }; _stars1 = new List <GameObject> { _proficiencies[1].gameObject.transform.Find("Star img").gameObject, _proficiencies[1].gameObject.transform.Find("Star img (1)").gameObject, _proficiencies[1].gameObject.transform.Find("Star img (2)").gameObject }; assignImage = gameObject.transform.Find("Assign img").gameObject; assignImage.SetActive(false); _name.text = name; _image.sprite = WorkerShopMasterController.sprites[spriteNum]; _image.color = ToColor(colorStr); _proficiencies[0].text = workstations[0]; _proficiencies[1].text = workstations[1]; for (int i = 0; i < _stars0.Count; i++) { _stars0[i].SetActive(false); _stars1[i].SetActive(false); } for (int i = 0; i < workstationStats[0]; i++) { _stars0[i].SetActive(true); } for (int i = 0; i < workstationStats[1]; i++) { _stars1[i].SetActive(true); } if (mode == "assign") { HighlightProficiencyText(); } else if (mode == "inspect") { DehighlightProficiencyText(); } }
public Grabber(string name, int amountToGrab, int delayUntilNextMove, FactoryEntity parent) { this.Ressource = new Ressource(name); this.ressource.Quantity = amountToGrab; this.delayUntilNextMove = delayUntilNextMove; this.parent = parent; this.timeSinceLastMove = 0; }
public void AddFactoryEntity(FactoryEntity factoryEntity) { factoryEntity.Owner = this; factoryLayer.AddFactoryEntity(factoryEntity); if (World.Instance.Terrain.Cells[factoryEntity.Position.X, factoryEntity.Position.Y] != null) { World.Instance.Terrain.Cells[factoryEntity.Position.X, factoryEntity.Position.Y].FactoryEntity = factoryEntity; } }
public void TestMethod6() { Triangle triangle = FactoryEntity.GetTriangle(); triangle.PointOne = new Point(60, 60); triangle.PointTwo = new Point(100, 300); triangle.PointThree = new Point(30, 200); ITriangleOperation triangleOperation = FactoryService.GetTriangleOperationObject(); triangleOperation.DrawingTriangle(triangle); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); FontManager.Instance.LoadFonts(this); var spriteSheet = Content.Load <Texture2D>("Textures/spritesheet"); TextureManager = new TextureManager(spriteSheet, 32, 32); World = new World(); var player = World.EntityManager.CreateEntity(); FactoryEntity.CreatePlayer(player); for (int i = 0; i < 10; i++) { var ennemy = World.EntityManager.CreateEntity(); FactoryEntity.CreateEnnemy3(ennemy, 100 + (i * 38), 100, Color.White); ennemy = World.EntityManager.CreateEntity(); FactoryEntity.CreateEnnemy1(ennemy, 100 + (i * 38), 125, Color.White); ennemy = World.EntityManager.CreateEntity(); FactoryEntity.CreateEnnemy1(ennemy, 100 + (i * 38), 150, Color.White); ennemy = World.EntityManager.CreateEntity(); FactoryEntity.CreateEnnemy2(ennemy, 100 + (i * 38), 175, Color.White); ennemy = World.EntityManager.CreateEntity(); FactoryEntity.CreateEnnemy2(ennemy, 100 + (i * 38), 200, Color.White); } //var soucoupe = World.EntityManager.CreateEntity(); //FactoryEntity.CreateEnnemy4(soucoupe, 30, 20, Color.Red); World.SystemManager.AddSystem(new InputSystem()); World.SystemManager.AddSystem(new DrawEntitySystem()); World.SystemManager.AddSystem(new DrawEntityDeathSystem()); World.SystemManager.AddSystem(new MoveToSystem()); World.SystemManager.AddSystem(new MoveEnemiesSystem()); World.SystemManager.AddSystem(new ShootPlayerSystem()); World.SystemManager.AddSystem(new ShootEnemiesSystem()); World.SystemManager.AddSystem(new MoveShootsSystem()); World.SystemManager.AddSystem(new CollisionShootSystem()); World.SystemManager.AddSystem(new EndGameSystem()); _stopwatch = new Stopwatch(); _stopwatch.Start(); }
public override void Update(IList <Entity> entities, double elapsedTime) { //Entities var player = entities.Where(x => !x.ToRemove && ((TypeComponent)x.GetComponent(5)).Type == Enums.EnumTypeEntity.PLAYER).First(); ShootComponent shootComponent = (ShootComponent)player.GetComponent(6); var transformComponent = (TransformComponent)player.GetComponent(0); shootComponent.LastShootTime += elapsedTime; if (shootComponent.ShootAsked && shootComponent.LastShootTime > shootComponent.IntervalBetweenShoot * 1000) { var shoot = MyGame.Instance.World.EntityManager.CreateEntity(); FactoryEntity.CreateShoot(shoot, transformComponent.X, transformComponent.Y, 0, -1, 32, Enums.EnumTypeEntity.SHOOT_PLAYER); shootComponent.LastShootTime = 0; } }
private static StringBuilder DisplayFactoryEntityDetails(FactoryEntity factoryEntity, int i, int width) { var line = new StringBuilder(); if (factoryEntity == null) { return(line); } var details = FactoryEntityDetails.GetDetails(factoryEntity); if (details.Count > i) { line.Append(details[i]); } return(PadRight(line.ToString(), EMPTY_CELL, width, BORDER_VERTICAL)); }
public void ReadXml(XmlReader reader) { position = new Vector2Int(Convert.ToInt32(reader["X"]), Convert.ToInt32(reader["Y"])); if (position.X == 0 && position.Y == 4) { int i = 0; i++; } elevation = Convert.ToInt32(reader["Z"]); if (reader.ReadToDescendant(typeof(FactoryEntity).Name)) { while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == typeof(FactoryEntity).Name) { factoryEntity = new FactoryEntity("", Vector2Int.Zero, null); factoryEntity.Position = position; factoryEntity.ReadXml(reader); } } reader.Read(); }
/// <summary> /// Execution of the Command /// </summary> /// <param name="param">Id</param> /// <returns>User</returns> public override Entity Execute(string param) { string strClass = "CommandGetUser"; Entity user = FactoryEntity.GetUser(); try { IDaoUser daoUser = FactoryDao.GetDaoUser(); DataSet dsUser = daoUser.GetById(param); Command <DataSet, List <Entity> > commandConvertToJSON = FactoryCommand.GetCommandConvertUserIntoJSON(); user = commandConvertToJSON.Execute(dsUser)[0]; } catch (Exception e) { IDaoUser daoUser = FactoryDao.GetDaoUser(); daoUser.CreateLog(strClass, "There was a problem exectuting the command to get one user", true); throw new Exception("There was a problem exectuting the command to get one user", e); } return(user); }
/// <summary> /// Execution of the Command /// </summary> /// <param name="param">DataSet from DB</param> /// <returns>List of Users</returns> public override List <Entity> Execute(DataSet param) { string strClass = "CommandConvertUserIntoJSON"; List <Entity> list = new List <Entity>(); int result; DateTime resultDT; try { if (param != null) { foreach (DataRow dr in param.Tables["DATA"].Rows) { Entity user = FactoryEntity.GetUser(); ((User)user).Id = (dr["USER_ID"] != null && !String.IsNullOrEmpty(dr["USER_ID"].ToString())) ? (int.TryParse(dr["USER_ID"].ToString(), out result) ? int.Parse(dr["USER_ID"].ToString()) : -1) : -1; ((User)user).Name = (dr["USER_NAME"] != null && !String.IsNullOrEmpty(dr["USER_NAME"].ToString())) ? dr["USER_NAME"].ToString() : ""; ((User)user).Birthdate = (dr["USER_BIRTHDATE"] != null && !String.IsNullOrEmpty(dr["USER_BIRTHDATE"].ToString())) ? (DateTime.TryParse(dr["USER_BIRTHDATE"].ToString(), out resultDT) ? DateTime.Parse(dr["USER_BIRTHDATE"].ToString()).Month.ToString() + "-" + DateTime.Parse(dr["USER_BIRTHDATE"].ToString()).Day.ToString() + "-" + DateTime.Parse(dr["USER_BIRTHDATE"].ToString()).Year.ToString() : "") : ""; list.Add(user); } } } catch (Exception e) { IDaoUser daoUser = FactoryDao.GetDaoUser(); daoUser.CreateLog(strClass, "There was a problem converting the user into a JSON", true); throw new Exception("There was a problem converting the user into a JSON", e); } return(list); }
void CustomInitialize() { if (PooledDontInheritFromThisInstance.AxisAlignedRectangleInstance.RelativeX != 5) { throw new Exception("Pooled values aren't getting proper relative values set."); } this.ContainerOfFactoryEntityListInstance.Destroy(); try { FactoryEntity factoryEntity = FactoryEntityFactory.CreateNew(); } catch (Exception e) { throw new Exception("Destroying Entities also destroys factories if the Entity contains a list of a pooled type. This shouldn't happen."); } FactoryEntityDerivedFactory.Initialize(ContentManagerName); FactoryEntityDerived instance = FactoryEntityDerivedFactory.CreateNew(); if (instance.AxisAlignedRectangleInstance.RelativeX != 5.0f) { throw new Exception("Pooled values aren't getting proper relative values set on derived."); } instance.AxisAlignedRectangleInstance.RelativeX = 10; instance.Destroy(); instance = FactoryEntityDerivedFactory.CreateNew(); if (instance.AxisAlignedRectangleInstance.RelativeX != 5.0f) { throw new Exception("Reset varaibles aren't working"); } instance.Destroy(); // Let's try addition/removal: RecyclableEntity recyclableInstance = new RecyclableEntity(); recyclableInstance.Destroy(); recyclableInstance.ReAddToManagers(null); recyclableInstance.Destroy(); BaseNotPooledFactory.Initialize(ContentManagerName); BaseNotPooled notPooled = BaseNotPooledFactory.CreateNew(); notPooled.Destroy(); // According this bug: // http://www.hostedredmine.com/issues/413966 // This may break: DerivedPooledFromNotPooledFactory.Initialize(ContentManagerName); var pooled = DerivedPooledFromNotPooledFactory.CreateNew(); if (!SpriteManager.ManagedPositionedObjects.Contains(pooled)) { throw new Exception("Derived entities with pooling from base entities without are not being added to the engine on creation"); } // Now try to destroy: pooled.Destroy(); if (SpriteManager.ManagedPositionedObjects.Contains(pooled)) { throw new Exception("Derived entities with pooling from base entities without are not being removed from the engine on destroy"); } BasePooledEntityFactory.CreateNew(); DerivedPooledFromPooledFactory.CreateNew().Destroy(); // If this throws an exception, that means that the derived Destroy method is modifying the base entity factory. // This should run in debug to throw: BasePooledEntityFactory.CreateNew(); TestPooledAttachment(); TestPooledSpriteInheritingCollisionAttachment(); TestBaseChildGrandchildListAdditions(); TestFactoriesNotRequiringInitialize(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new MySpriteBatch(GraphicsDevice); Utils.FontManager.Instance.LoadFonts(this); EmptyKeys.UserInterface.FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(Utils.FontManager.Instance.GetFont(FontEnum.ARIAL_16)); Viewport viewport = GraphicsDevice.Viewport; _basicUI = new EmptyKeys.UserInterface.Generated.BasicUI(); _viewModel = new BasicUIViewModel(); _basicUI.DataContext = _viewModel; EmptyKeys.UserInterface.FontManager.Instance.LoadFonts(Content, "Fonts/"); ImageManager.Instance.LoadImages(Content); SoundManager.Instance.LoadSounds(Content); var spriteSheet = Content.Load <Texture2D>("Textures/spritesheet"); TextureManager = new TextureManager(spriteSheet, 32, 32); Lua = new LuaInterpreter(); _threadLua = new Thread( new ThreadStart(ConsoleThread)); _threadLua.Start(); World = new World(); var drawSystem = new DrawEntitySystem( 1, new List <Type>() { typeof(SpriteComponent), typeof(TransformComponent) }, World ); var random = new Random(); var player = World.CreateGameObject(); FactoryEntity.CreatePlayer(World, player); var bomb = World.CreateGameObject(); FactoryEntity.CreateBomb(World, bomb, 6, 1); var map = new int[MapWidth * MapHeight] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 2, 0, 2, 0, 2, 0, 1, 0, 0, 1, 2, 0, 2, 0, 2, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (var i = 0; i < map.Length; i++) { var e = World.CreateGameObject(); var value = map[i]; switch (value) { case 0: FactoryEntity.CreateHardWall(World, e, i % MapWidth, i / MapHeight); break; case 2: FactoryEntity.CreateSoftWall(World, e, i % MapWidth, i / MapHeight); break; } } World.SystemManager.AddSystem(new UpdateSpriteSystem(0, new List <Type>() { typeof(SpriteComponent), typeof(SpriteAnimationComponent) }, World)); World.SystemManager.AddSystem(new UpdateInputSystem(0, new List <Type>() { typeof(TypeEntityComponent), typeof(TransformComponent), typeof(InputComponent) }, World)); World.SystemManager.AddSystem(new DrawFloorSystem(0, null, World)); World.SystemManager.AddSystem(drawSystem); _stopwatch = new Stopwatch(); _stopwatch.Start(); }
public TerrainCell(Vector2Int position, int elevation) { this.position = position; this.elevation = elevation; factoryEntity = null; }
static void Main(string[] args) { XmlConfigurator.Configure(); try { Console.WriteLine("enter your choice"); Console.WriteLine("1 . line"); Console.WriteLine("2 . rectangle"); Console.WriteLine("3 . circle"); Console.WriteLine("4 . Triangle"); Console.WriteLine("5 . Polygon"); string choice = Console.ReadLine(); switch (choice) { case "1": Line line = FactoryLineObject.GetLine(); Console.WriteLine("Enter values for co-ordinates"); Console.WriteLine("Enter X co-ordinate for point one"); line.PointOneX = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate for point one"); line.PointOneY = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter X co-ordinate for point two"); line.PointTwoX = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate for point two"); line.PointTwoY = Validate.ValidateNumber(Console.ReadLine()); ILineOperation lineOperation = FactoryLineOperationObject.GetLineOperation(); lineOperation.DrawingLine(line); logger.Info("Line with co-ordinate x1 => " + line.PointOneX + " y1 => " + line.PointOneY + " x2 => " + line.PointTwoX + " y2 => " + line.PointTwoY); break; case "2": Entities.Rectangle rectangle = FactoryRectangleObject.GetRectagle(); Console.WriteLine("Enter values for co-ordinates"); Console.WriteLine("Enter X co-ordinate for point one"); rectangle.PointOneX = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate for point one"); rectangle.PointOneY = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter X co-ordinate for point two"); rectangle.PointTwoX = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate for point two"); rectangle.PointTwoY = Validate.ValidateNumber(Console.ReadLine()); IRectangleOperation rectangleOperation = FactoryRectangleOerationObject.GetRectagleOperation(); rectangleOperation.DrawingRectangle(rectangle); logger.Info("Rectangle with co-ordinate x1 => " + rectangle.PointOneX + " y1 => " + rectangle.PointOneY + " x2 => " + rectangle.PointTwoX + " y2 => " + rectangle.PointTwoY); break; case "3": Circle circle = FactoryCircleObject.GetCircle(); Console.WriteLine("Enter values for co-ordinates"); Console.WriteLine("Enter X co-ordinate for centre"); circle.CentreX = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate for centre"); circle.CentreY = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter radius for circle"); circle.Radius = Validate.ValidateNumber(Console.ReadLine()); ICircleOperation circleOperation = FactoryCircleOperationObject.GetCircleOperationObject(); circleOperation.DrawingCircle(circle); logger.Info("Circle with co-ordinate x1 => " + circle.CentreX + " y1 => " + circle.CentreY + " radius => " + circle.Radius); break; case "4": Triangle triangle = FactoryEntity.GetTriangle(); Point point = new Point(); Console.WriteLine("Enter values for point one"); Console.WriteLine("Enter X co-ordinate for centre"); point.X = (int)Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate point one"); point.Y = (int)Validate.ValidateNumber(Console.ReadLine()); triangle.PointOne = point; Console.WriteLine("Enter X co-ordinate point two"); point.X = (int)Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate point two"); point.Y = (int)Validate.ValidateNumber(Console.ReadLine()); triangle.PointTwo = point; Console.WriteLine("Enter X co-ordinate point Three"); point.X = (int)Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate point Three"); point.Y = (int)Validate.ValidateNumber(Console.ReadLine()); triangle.PointThree = point; ITriangleOperation triangleOperation = FactoryService.GetTriangleOperationObject(); triangleOperation.DrawingTriangle(triangle); //Polygon polygon = FactoryEntity.GetPolygon(); //polygon.PointOne = new Point(10, 10); //polygon.PointTwo = new Point(20, 10); //polygon.PointThree = new Point(30, 20); //polygon.PointFour = new Point(20, 30); //polygon.PointFive = new Point(10, 30); //polygon.PointSix = new Point(5, 20); //IPolygonOperation polygonOperation = FactoryService.GetPolygon(); //polygonOperation.DrawingPolygon(polygon); logger.Info("trangle with co-ordinate x1 => " + triangle.PointOne.X + " y1 => " + triangle.PointOne.Y + " X2 => " + triangle.PointTwo.X + " Y2 => " + triangle.PointTwo.Y + " x3=> " + triangle.PointThree.X + " Y3 => " + triangle.PointThree.Y); break; case "5": Circle circlep = FactoryCircleObject.GetCircle(); Console.WriteLine("Enter values for co-ordinates"); Console.WriteLine("Enter X co-ordinate for centre"); circlep.CentreX = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter Y co-ordinate for centre"); circlep.CentreY = Validate.ValidateNumber(Console.ReadLine()); Console.WriteLine("Enter radius for circle"); circlep.Radius = Validate.ValidateNumber(Console.ReadLine()); IPolygonOperation polygonOperation = FactoryService.GetPolygon(); polygonOperation.DrawingPolygon(circlep); logger.Info("polygon with co-ordinate x1 => " + circlep.CentreX + " y1 => " + circlep.CentreY + " radius => " + circlep.Radius); //Circle circle1 = FactoryCircleObject.GetCircle(); //circle1.CentreX = 100.0; //circle1.CentreY = 100.0; //circle1.Radius = 100.0; //IPolygonOperation polygonOperation = FactoryService.GetPolygon(); //polygonOperation.DrawingPolygon(circle1); break; default: Console.WriteLine("please check your Input"); logger.Error("wrong input Enter by user"); break; } }catch (Exception e) { logger.Error(e.Message); } }
public static List <string> GetDetails(FactoryEntity component) { var details = new List <string>(); details.Add(component.Position.ToString()); details.Add(component.Name); details.Add("Owner: " + component.Owner.Name); if (component.GetComponent <Generator>() != null) { var generator = component.GetComponent <Generator>(); details.Add("--- Generator"); details.Add("Harvest: " + generator.Ressource.Name); if (component.GetComponent <Container>() != null) { var container = component.GetComponent <Container>(); details.Add("--- Container"); if (container.Ressource != null) { details.Add("Amount: " + container.Ressource.Quantity); } } } else if (component.GetComponent <Container>() != null) { var container = component.GetComponent <Container>(); details.Add("--- Container"); if (container.Ressource != null) { details.Add("Hold: " + container.Ressource.Name); details.Add("Amount: " + container.Ressource.Quantity); } else { details.Add("Hold: Nothing"); } } if (component.GetComponent <Grabber>() != null) { details.Add("--- Grabber"); var grabber = component.GetComponent <Grabber>(); details.Add("Move: " + grabber.Ressource.Name); details.Add("By: " + grabber.Ressource.Quantity + "/tick"); details.Add("IN: " + Enum.GetName(typeof(Orientation), grabber.Input)); details.Add("OUT: " + Enum.GetName(typeof(Orientation), grabber.Output)); } if (component.GetComponent <PutInto>() != null) { details.Add("--- PutInto"); var putInto = component.GetComponent <PutInto>(); if (putInto.Ressource != null) { details.Add("Move: " + putInto.Ressource.Name); } else { details.Add("Move: Nothing"); } details.Add("To: " + putInto.Target); } if (component.GetComponent <Destructible>() != null) { details.Add("--- Destructible"); var destructible = component.GetComponent <Destructible>(); details.Add("Health: " + destructible.CurrentHealth + "/" + destructible.MaxHealth); } // if(component.GetType() == typeof(Harvester)) { // details.Add(component.Position.ToString()); // details.Add(component.Name); // details.Add("Owner: " + component.Owner.Name); // details.Add("Gather: " + (component as Harvester).Ressource.Name); // } else if(component.GetType() == typeof(Conveyor)) { // details.Add(component.Position.ToString()); // details.Add(component.Name); // details.Add("Owner: " + component.Owner.Name); // if((component as Conveyor).Ressource != null) { // details.Add("Carry: " + (component as Conveyor).Ressource.Name); // } // else // details.Add("Carry: Nothing"); // details.Add("Feeding " + Enum.GetName(typeof(Orientation), (component as Conveyor).Orientation)); // } else if(component.GetType() == typeof(Builder)) { // details.Add(component.Position.ToString()); // details.Add(component.Name); // details.Add("Owner: " + component.Owner.Name); // if((component as Builder).Ressource != null) { // details.Add("Hold: " + (component as Builder).Ressource.Name); // } // else // details.Add("Hold: Empty"); // } return(details); }
void CustomInitialize() { // Just to make sure the syntax works: FactoryEntityFactory.ScreenListReference = FactoryEntityFactory.ScreenListReference; if (PooledDontInheritFromThisInstance.AxisAlignedRectangleInstance.RelativeX != 5) { throw new Exception("Pooled values aren't getting proper relative values set."); } this.ContainerOfFactoryEntityListInstance.Destroy(); try { FactoryEntity factoryEntity = FactoryEntityFactory.CreateNew(); } catch (Exception e) { throw new Exception("Destroying Entities also destroys factories if the Entity contains a list of a pooled type. This shouldn't happen."); } FactoryEntityDerived instance = FactoryEntityDerivedFactory.CreateNew(); if (instance.AxisAlignedRectangleInstance.RelativeX != 5.0f) { throw new Exception("Pooled values aren't getting proper relative values set on derived."); } instance.AxisAlignedRectangleInstance.RelativeX = 10; instance.Destroy(); instance = FactoryEntityDerivedFactory.CreateNew(); if (instance.AxisAlignedRectangleInstance.RelativeX != 5.0f) { throw new Exception("Reset varaibles aren't working"); } // Let's try addition/removal: RecyclableEntity recyclableInstance = new RecyclableEntity(); recyclableInstance.Destroy(); recyclableInstance.ReAddToManagers(null); recyclableInstance.Destroy(); BaseNotPooledFactory.Initialize(null, ContentManagerName); BaseNotPooled notPooled = BaseNotPooledFactory.CreateNew(); notPooled.Destroy(); // According this bug: // http://www.hostedredmine.com/issues/413966 // This may break: DerivedPooledFromNotPooledFactory.Initialize((PositionedObjectList <DerivedPooledFromNotPooled>)null, ContentManagerName); var pooled = DerivedPooledFromNotPooledFactory.CreateNew(); if (!SpriteManager.ManagedPositionedObjects.Contains(pooled)) { throw new Exception("Derived entities with pooling from base entities without are not being added to the engine on creation"); } // Now try to destroy: pooled.Destroy(); if (SpriteManager.ManagedPositionedObjects.Contains(pooled)) { throw new Exception("Derived entities with pooling from base entities without are not being removed from the engine on destroy"); } }
public Turnable(FactoryEntity parent) { this.parent = parent; }
public void RemoveFactoryEntity(FactoryEntity factoryEntity) { factoryLayer.RemoveFactoryEntity(factoryEntity); }
public static void Handle(ConsoleKey input) { if (input == SAVE) { Save.SerializeObject <World>(World.Instance, @"C:\Users\lcourtal\Documents\Games\save.xml"); } else if (input == LOAD) { World.Instance.LoadSave(Save.DeserializeObject <World>(@"C:\Users\lcourtal\Documents\Games\save.xml")); } else if (input == UP) { Move(0, -1); } else if (input == DOWN) { Move(0, 1); } else if (input == LEFT) { Move(-1, 0); } else if (input == RIGHT) { Move(1, 0); } else if (input == ROTATE_INPUT) { var cell = GetFocusedCell(); if (cell.FactoryEntity != null) { var grabber = cell.FactoryEntity.GetComponent <Grabber>(); if (grabber != null) { grabber.Input = grabber.Input.Rotate(true); } } } else if (input == ROTATE_OUTPUT) { var cell = GetFocusedCell(); if (cell.FactoryEntity != null) { var grabber = cell.FactoryEntity.GetComponent <Grabber>(); if (grabber != null) { grabber.Output = grabber.Output.Rotate(true); } } } else if (input == ROTATE) { var cell = GetFocusedCell(); if (cell.FactoryEntity != null && cell.FactoryEntity.GetComponent <PutInto>() != null) { var putInto = cell.FactoryEntity.GetComponent <PutInto>(); putInto.Target = putInto.Target.Rotate(false); } // var cell = GetFocusedCell(); // if(cell.FactoryEntity != null && cell.FactoryEntity.GetType() == typeof(Conveyor)) { // (cell.FactoryEntity as Conveyor).Orientation = (cell.FactoryEntity as Conveyor).Orientation.Rotate(); // } } else if (input == BUILD_HARVESTER) { var faction = World.Instance.FactionList.GetFaction("Player"); var harvester = new FactoryEntity("Harvester", position, faction); harvester.AddComponent(new Generator(2, new Ressource("Iron", 1), harvester)); var container = (Container)harvester.AddComponent(new Container(harvester)); container.Ressource = new Ressource("Iron", 0); harvester.AddComponent(new PutInto("Iron", 1, 1, harvester)); harvester.AddComponent(new Destructible(250)); faction.AddFactoryEntity(harvester); } else if (input == BUILD_GRABBER) { var faction = World.Instance.FactionList.GetFaction("Player"); var grabber = new FactoryEntity("Grabber", position, faction); grabber.AddComponent(new Grabber("Iron", 1, 1, grabber)); grabber.AddComponent(new Destructible(75)); faction.AddFactoryEntity(grabber); } else if (input == BUILD_CONVEYOR) { var faction = World.Instance.FactionList.GetFaction("Player"); var conveyor = new FactoryEntity("Conveyor", position, faction); conveyor.AddComponent(new Container(conveyor)); conveyor.AddComponent(new PutInto("Iron", 1, 2, conveyor)); conveyor.AddComponent(new Destructible(125)); faction.AddFactoryEntity(conveyor); // var neighboors = new Dictionary<Type, List<IFactoryComponent>>(); // foreach (Orientation direction in (Orientation[]) Enum.GetValues(typeof(Orientation))) // { // if(direction == Orientation.CENTER) // continue; // // var cell = direction.GetNeighboor(position); // if(cell != null && cell.FactoryComponent != null) { // if(neighboors.ContainsKey(cell.FactoryComponent.GetType()) == false) { // neighboors.Add(cell.FactoryComponent.GetType(), new List<IFactoryComponent>()); // } // if(neighboors[cell.FactoryComponent.GetType()] == null) // neighboors[cell.FactoryComponent.GetType()] = new List<IFactoryComponent>(); // neighboors[cell.FactoryComponent.GetType()].Add(cell.FactoryComponent); // } // } // // Orientation orientation = Orientation.CENTER; // if(neighboors.ContainsKey(typeof(Harvester))) { // orientation = orientation.SetOrientationFromPosition(neighboors[typeof(Harvester)][0].Position, position); // } else if(neighboors.ContainsKey(typeof(Builder))) { // orientation = orientation.SetOrientationFromPosition(position, neighboors[typeof(Builder)][0].Position); // } else if(neighboors.ContainsKey(typeof(Conveyor))) { // var defaultOrientation = orientation; // foreach (Conveyor conveyor in neighboors[typeof(Conveyor)]) { // var conveyorFeedPosition = conveyor.Orientation.GetPositionOfTarget(position); // if(conveyorFeedPosition.X != position.X && conveyorFeedPosition.Y != position.Y) { // orientation = orientation.SetOrientationFromPosition(position, conveyor.Position); // break; // } else { // defaultOrientation = orientation.SetOrientationFromPosition(conveyor.Position, position); // } // } // if(orientation == Orientation.CENTER) // orientation = defaultOrientation; // } // //World.Instance.FactionList.GetFaction("Player").AddFactoryComponent(new Conveyor(position, orientation)); } else if (input == BUILD_BUILDER) { var faction = World.Instance.FactionList.GetFaction("Player"); var builder = new FactoryEntity("Builder", position, faction); builder.AddComponent(new Container(builder)); builder.AddComponent(new Producer(1, builder)); builder.AddComponent(new Destructible(250)); faction.AddFactoryEntity(builder); } else if (input == DESTROY_BUILDING) { var cell = GetFocusedCell(); if (cell.FactoryEntity != null) { var destructible = cell.FactoryEntity.GetComponent <Destructible>(); if (destructible != null) { destructible.CurrentHealth = 0; } } } else if (input == ConsoleKey.Spacebar) { World.Instance.FactionList.Update(); //FactoryLayers.displayRessources = !FactoryLayers.displayRessources; } }
public Container(FactoryEntity parent) { this.parent = parent; ressource = new Ressource(); }
public Producer(int timeToProduce, FactoryEntity parent) { this.parent = parent; this.timeToProduce = timeToProduce; productionNumber = 2000; }