public void CreateMap(string path) { var result = new IGameElement [Constants.WindowHeight / Constants.FieldCellHeight, Constants.WindowWidth / Constants.FieldCellWidth]; string projectPath = Path.Combine(Environment.CurrentDirectory, path); using (StreamReader sr = new StreamReader(projectPath)) { string line; var row = 0; while ((line = sr.ReadLine()) != null) { var column = 0; foreach (var symbol in line) { CreateElementBySymbol(result, symbol, row, column); column++; } row++; } } Map = result; }
public static void SyncState(IGameElement element, GameState targetState) { if (targetState >= GameState.FINISH) { return; } if (targetState < GameState.PREPARE) { return; } element.OnPrepareGame(); if (targetState >= GameState.READY) { element.OnReadyGame(); } if (targetState >= GameState.PLAY) { element.OnStartGame(); } if (targetState == GameState.PAUSE) { element.OnPauseGame(); } }
private void GameElement_OnRemove(object sender, IGameElement e) { GameElements.Remove(e); e.OnRemoving -= GameElement_OnRemove; if (GameElements.Count == 0) { Remove(); } }
/// <summary> /// Checks collision between two elements. /// </summary> /// <param name="element1">The first element to check.</param> /// <param name="element2">The secund element to check.</param> /// <returns>True if the elements have collision, otherwise false.</returns> public bool CheckCollision(IGameElement element1, IGameElement element2) { if (element1 == null || element2 == null) { return(false); } Rect rect1 = new Rect(new Point(element1.X, element1.Y), new Size(1, 1)); Rect rect2 = new Rect(new Point(element2.X, element2.Y), new Size(1, 1)); return(Intersection(rect1, rect2)); }
public void OnBusyElement(IGameElement busyElement) { if (!busyElements.Contains(busyElement)) { busyElements.Add(busyElement); busyRaycastBlocker.SetActive(true); } else { Debug.LogError("Error: busy element " + busyElement + " was already busy."); } }
/// <summary> /// Initializes a new instance of AStarEnemyMovementAlgorithm object. /// </summary> /// <param name="graph">Graph representing the gameboard.</param> /// <param name="player">An element representing player.</param> /// <param name="width">Width of the board (number of columns).</param> /// <param name="height">Hight of the board (number of rows).</param> public AStarEnemyMovementAlgorithm(IGraph graph, IGameElement player, int width, int height) { if (graph == null) { throw new ArgumentNullException(nameof(graph)); } _graph = graph; if (player == null) { throw new ArgumentNullException(nameof(player)); } _player = player; _width = width; _height = height; }
/// <summary> /// Looks for collisions between the given element and the set of other elements. /// </summary> /// <param name="checker">The IGameMovementChecker instance.</param> /// <param name="element">The element for testing collisions.</param> /// <param name="obstacles">Another elements to test collision with the given element.</param> /// <param name="checkElementInObstacles">Specifies whether the testing element is in the given collection of obstacles. /// If true it wouldn't be testet for collision.</param> /// <returns>True if the element has collision with at least one from the given obstacles, otherwise false.</returns> public static bool CheckCollision(this IGameMovementChecker checker, IGameElement element, IEnumerable <IGameElement> obstacles, bool checkElementInObstacles) { if (checker == null) { throw new NullReferenceException(nameof(checker)); } if (element == null || obstacles == null) { return(false); } IList <IGameElement> obst = obstacles.ToList(); if (obst.Contains(element)) { obst.Remove(element); } return(obst.Aggregate(true, (current, gameElement) => current && checker.CheckCollision(gameElement, element))); }
public ClearMarker(IGameElement creator) : base(creator) { this.markerName = "Clear"; this.terrainType = TerrainType.Clear; }
public SmokeMarker(IGameElement creator) : base(creator) { this.markerName = "Smoke"; this.terrainType = TerrainType.Hindering; }
public WaterMarker(IGameElement creator) : base(creator) { this.markerName = "Water"; this.terrainType = TerrainType.Water; }
private bool CheckCollision(IGameElement element1, Rect rect) { Rect rect1 = new Rect(new Point(element1.X, element1.Y), new Size(1, 1)); return(Intersection(rect1, rect)); }
public void AddChild(IGameElement element) => gameElements.Add(element);
public virtual void AddObject(IGameElement gameElement) { GameElements.Add(gameElement); gameElement.OnRemoving += GameElement_OnRemove; }
protected Marker(IGameElement _creator) { creator = _creator; }
public void AddEffect(IGameElement effect) { _effects. }
public MovementAction(IGameElement gameElement, int deltaX, int deltaY) { GameElement = gameElement; DeltaX = deltaX; DeltaY = deltaY; }
public void RemoveChild(IGameElement element) => gameElements.Remove(element);
public BarrierMarker(IGameElement creator) : base(creator) { this.markerName = "Barrier"; this.terrainType = TerrainType.Blocking; }
private void Effect_OnRemove(object sender, IGameElement e) { _effects.Remove(e); e.OnRemoving -= Effect_OnRemove; }
protected Marker() { creator = new HeroClixCharacter(); }
public DebrisMarker(IGameElement creator) : base(creator) { this.markerName = "Debris"; this.terrainType = TerrainType.Hindering; }
/// <summary> /// Looks for collisions between the given element and the set of other elements. /// </summary> /// <param name="checker">The IGameMovementChecker instance.</param> /// <param name="element">The element for testing collisions.</param> /// <param name="obstacles">Another elements to test collision with the given element.</param> /// <returns>True if the element has collision with at least one from the given obstacles, otherwise false.</returns> public static bool CheckCollision(this IGameMovementChecker checker, IGameElement element, IEnumerable <IGameElement> obstacles) { return(checker.CheckCollision(element, obstacles, false)); }
public bool SpriteCollide(IGameElement gameElement) { return false; }
public FireMarker(IGameElement creator) : base(creator) { this.markerName = "Fire"; this.terrainType = TerrainType.Blocking; }
public void AddEffect(IGameElement effect) { _effects.Add(effect); effect.OnRemoving += Effect_OnRemove; }