Exemplo n.º 1
0
        /// Walk the Map and Find the Location that is close to the target based on attacker's speed.
        /// </summary>
        /// <param name="Target"></param>
        /// <returns></returns>
        public MapModelLocation ReturnClosestEmptyLocationBasedOnSpeed(MapModelLocation Attacker, MapModelLocation Target)
        {
            MapModelLocation Result = null;

            int LowestDistance       = int.MaxValue;
            int MaxTravelForAttacker = Attacker.Player.Speed;

            if (Attacker.Player.Speed <= 0)
            {
                MaxTravelForAttacker = 0;
                // don't move
                Result = new MapModelLocation {
                    Column = Attacker.Column, Row = Attacker.Row
                };
            }

            foreach (var data in GetEmptyLocations())
            {
                var distanceToTarget     = CalculateDistance(data, Target);
                var distanceFromAttacker = CalculateDistance(data, Attacker);
                if (distanceToTarget < LowestDistance && distanceFromAttacker <= MaxTravelForAttacker)
                {
                    Result         = data;
                    LowestDistance = distanceToTarget;
                }
            }

            return(Result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Changes the Row and Column for the Player
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool MovePlayerOnMap(MapModelLocation data, MapModelLocation target)
        {
            if (target.Column < 0)
            {
                return(false);
            }

            if (target.Row < 0)
            {
                return(false);
            }

            if (target.Column >= MapXAxiesCount)
            {
                return(false);
            }

            if (target.Row >= MapYAxiesCount)
            {
                return(false);
            }

            MapGridLocation[target.Column, target.Row].Player = data.Player;

            // Clear out the old location
            MapGridLocation[data.Column, data.Row].Player = EmptySquare;

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Walk the Map and Find the Location that is reachable based on the range or closest to the target
        /// </summary>
        /// <param name="Target"></param>
        /// <returns></returns>
        public MapModelLocation ReturnClosestEmptyLocation(MapModelLocation Target, int Range)
        {
            MapModelLocation Result = null;

            int LowestDistance = int.MaxValue;

            foreach (var data in GetEmptyLocations())
            {
                var distance = CalculateDistance(data, Target);

                // Target can be reached with this Range
                if (distance <= Range)
                {
                    return(data);
                }

                if (distance < LowestDistance)
                {
                    Result         = data;
                    LowestDistance = distance;
                }
            }


            return(Result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculate distance between two map locations
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public int CalculateDistance(MapModelLocation start, MapModelLocation end)
        {
            if (start == null)
            {
                return(int.MaxValue);
            }

            if (end == null)
            {
                return(int.MaxValue);
            }

            return(Distance(start.Column, start.Row, end.Column, end.Row));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Changes the Row and Column for the Player
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool MovePlayerOnMap(MapModelLocation data, MapModelLocation target)
        {
            if (!IsValidCoordinate(target))
            {
                return(false);
            }

            MapGridLocation[target.Column, target.Row].Player = data.Player;

            // Clear out the old location
            MapGridLocation[data.Column, data.Row].Player = EmptySquare;

            return(true);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Create an Empty Map
 /// </summary>
 /// <returns></returns>
 public bool ClearMapGrid()
 {
     //Populate Map with Empty Values
     for (var x = 0; x < MapXAxiesCount; x++)
     {
         for (var y = 0; y < MapYAxiesCount; y++)
         {
             // Populate the entire map with blank
             MapGridLocation[x, y] = new MapModelLocation {
                 Row = y, Column = x, Player = EmptySquare
             };
         }
     }
     return(true);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Walk the Map and Find the Location that is close to the target
        /// </summary>
        /// <param name="Target"></param>
        /// <returns></returns>
        public MapModelLocation ReturnClosestEmptyLocation(MapModelLocation Target)
        {
            MapModelLocation Result = null;

            int LowestDistance = int.MaxValue;

            foreach (var data in GetEmptyLocations())
            {
                var distance = CalculateDistance(data, Target);
                if (distance < LowestDistance)
                {
                    Result         = data;
                    LowestDistance = distance;
                }
            }

            return(Result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Remove the Player from the Map
        /// Replaces with Empty Square
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool RemovePlayerFromMap(BattleEntityModel data)
        {
            for (var x = 0; x < MapXAxesCount; x++)
            {
                for (var y = 0; y < MapYAxesCount; y++)
                {
                    if (MapGridLocation[x, y].Player.Id.Equals(data.Id))
                    {
                        MapGridLocation[x, y] = new MapModelLocation {
                            Column = x, Row = y, Player = EmptySquare
                        };
                        return(true);
                    }
                }
            }

            // Not found
            return(false);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Swap the players on the map in the given squares
        /// </summary>
        /// <param name="data1"></param>
        /// <param name="data2"></param>
        /// <returns></returns>
        public bool SwapPlayersOnMap(MapModelLocation data1, MapModelLocation data2)
        {
            if (!IsValidCoordinate(data1))
            {
                return(false);
            }

            if (!IsValidCoordinate(data2))
            {
                return(false);
            }

            // swap the players
            var temp = data2.Player;

            MapGridLocation[data2.Column, data2.Row].Player = data1.Player;
            MapGridLocation[data1.Column, data1.Row].Player = temp;
            return(true);
        }
Exemplo n.º 10
0
        /// Walk the Map and Find the Location that is close to the target based on attacker's travel distance.
        /// </summary>
        /// <param name="Target"></param>
        /// <returns></returns>
        public MapModelLocation ReturnClosestEmptyLocationBasedOnRange(MapModelLocation Attacker, MapModelLocation Target)
        {
            MapModelLocation Result = null;

            int LowestDistance       = int.MaxValue;
            int MaxTravelForAttacker = Attacker.Player.Range;

            foreach (var data in GetEmptyLocations())
            {
                var distanceToTarget     = CalculateDistance(data, Target);
                var distanceFromAttacker = CalculateDistance(data, Attacker);
                if (distanceToTarget < LowestDistance && distanceFromAttacker <= MaxTravelForAttacker)
                {
                    Result         = data;
                    LowestDistance = distanceToTarget;
                }
            }

            return(Result);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Verifies that the given coordinate is a valid location on this Map
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public bool IsValidCoordinate(MapModelLocation target)
        {
            if (target.Column < 0)
            {
                return(false);
            }

            if (target.Row < 0)
            {
                return(false);
            }

            if (target.Column >= MapXAxesCount)
            {
                return(false);
            }

            if (target.Row >= MapYAxesCount)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Remove the Player from the Map
        /// Replaces with Empty Square
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool RemovePlayerFromMap(PlayerInfoModel data)
        {
            if (data == null)
            {
                return(false);
            }

            for (var x = 0; x < MapXAxiesCount; x++)
            {
                for (var y = 0; y < MapYAxiesCount; y++)
                {
                    if (MapGridLocation[x, y].Player.Guid.Equals(data.Guid))
                    {
                        MapGridLocation[x, y] = new MapModelLocation {
                            Column = x, Row = y, Player = EmptySquare
                        };
                        return(true);
                    }
                }
            }

            // Not found
            return(false);
        }