private Entity CreateEntity(EntityType type, XElement xEntity = null) { Entity entity = null; Position position = null; int id; if (xEntity == null) { id = GetNewEntityId(type); } else { id = (int)xEntity.Attribute("Id"); position = new Position((int)xEntity.Attribute("Row"), (int)xEntity.Attribute("Col")); } switch (type) { case EntityType.Player: entity = new Player(id, this, position, xEntity); _playerId = entity.Id; break; case EntityType.Enemy: entity = new Enemy(id, this, position, xEntity); break; case EntityType.Obstacle: entity = new Obstacle(id, this, position, xEntity); break; case EntityType.Other: break; default: break; } if (entity != null) { _entities.Add(entity.Id, entity); NewEntityCreated?.Invoke(entity, EventArgs.Empty); } return(entity); }
public void Handle(NewEntityCreated message) { _log.Info("Entity {0}/{1:n} created.", message.Entity.GetType().Name, message.Key); }