예제 #1
0
        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;
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        private void GameElement_OnRemove(object sender, IGameElement e)
        {
            GameElements.Remove(e);
            e.OnRemoving -= GameElement_OnRemove;

            if (GameElements.Count == 0)
            {
                Remove();
            }
        }
예제 #4
0
        /// <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));
        }
예제 #5
0
 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;
 }
예제 #7
0
        /// <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)));
        }
예제 #8
0
 public ClearMarker(IGameElement creator)
     : base(creator)
 {
     this.markerName  = "Clear";
     this.terrainType = TerrainType.Clear;
 }
예제 #9
0
 public SmokeMarker(IGameElement creator)
     : base(creator)
 {
     this.markerName  = "Smoke";
     this.terrainType = TerrainType.Hindering;
 }
예제 #10
0
 public WaterMarker(IGameElement creator)
     : base(creator)
 {
     this.markerName  = "Water";
     this.terrainType = TerrainType.Water;
 }
예제 #11
0
        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));
        }
예제 #12
0
 public void AddChild(IGameElement element) => gameElements.Add(element);
예제 #13
0
 public virtual void AddObject(IGameElement gameElement)
 {
     GameElements.Add(gameElement);
     gameElement.OnRemoving += GameElement_OnRemove;
 }
예제 #14
0
 protected Marker(IGameElement _creator)
 {
     creator = _creator;
 }
예제 #15
0
 public void AddEffect(IGameElement effect)
 {
     _effects.
 }
예제 #16
0
 public MovementAction(IGameElement gameElement, int deltaX, int deltaY)
 {
     GameElement = gameElement;
     DeltaX      = deltaX;
     DeltaY      = deltaY;
 }
예제 #17
0
 public void RemoveChild(IGameElement element) => gameElements.Remove(element);
예제 #18
0
 public BarrierMarker(IGameElement creator)
     : base(creator)
 {
     this.markerName  = "Barrier";
     this.terrainType = TerrainType.Blocking;
 }
예제 #19
0
		private void Effect_OnRemove(object sender, IGameElement e)
		{
			_effects.Remove(e);
			e.OnRemoving -= Effect_OnRemove;
		}
예제 #20
0
 protected Marker()
 {
     creator = new HeroClixCharacter();
 }
예제 #21
0
 public DebrisMarker(IGameElement creator)
     : base(creator)
 {
     this.markerName  = "Debris";
     this.terrainType = TerrainType.Hindering;
 }
예제 #22
0
 /// <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));
 }
예제 #23
0
 public bool SpriteCollide(IGameElement gameElement)
 {
     return false;
 }
예제 #24
0
 public FireMarker(IGameElement creator)
     : base(creator)
 {
     this.markerName  = "Fire";
     this.terrainType = TerrainType.Blocking;
 }
예제 #25
0
		public void AddEffect(IGameElement effect)
		{
			_effects.Add(effect);
			effect.OnRemoving += Effect_OnRemove;
		}