Beispiel #1
0
        /// <summary>
        /// Extracts a sub array from the array passed as a parameter
        /// </summary>
        /// <param name="xMin">The "top left" x bound of the array to extract</param>
        /// <param name="xMax">The "top left" y bound of the array to extract</param>
        /// <param name="yMin">The "bottom right" x bound of the array to extract</param>
        /// <param name="yMax">The "bottom right" y bound of the array to extract</param>
        /// <returns>The sub 2D array</returns>
        private MapTile[,] GetSubArray(Int16 xMin, Int16 xMax, Int16 yMin, Int16 yMax)
        {
            ICoordinates cMin = new Coordinates();
            cMin.SetCoordinates(xMin, yMin);
            ICoordinates cMax = new Coordinates();
            cMax.SetCoordinates(xMax, yMax);

            if (CoordinatesAreValid(cMin) && CoordinatesAreValid(cMax))
            {
                // Create a new map (add +1 to the dimention since it is a 0 based array)
                var newMap = new MapTile[(Int16)(xMax - xMin +1), (Int16)(yMax - yMin + 1)];
                for (int i = xMin; i <= xMax; i++)
                    for (int j = yMin; j <= yMax; j++)
                        newMap[i - xMin, j - yMin] = Grid[i, j];
                return newMap;
            }
            else
                throw new Exception();
        }
Beispiel #2
0
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <returns></returns>
        //internal ICoordinates GetClosestRessourcePool()
        //{
        //    IList<ICoordinates> ressources = this._view.GetRessourcesList();
        //    ICoordinates closestRessource = null;
        //    Int16? minDistance = null;
        //    foreach(ICoordinates spot in ressources)
        //    {
        //        if (closestRessource == null)
        //        {
        //            closestRessource = spot;
        //            minDistance = this._centerOfView.DistanceTo(spot);
        //        }
        //        if (spot.DistanceTo(closestRessource) < minDistance)
        //        {
        //            closestRessource = spot;
        //            minDistance = this._centerOfView.DistanceTo(spot);
        //        }
        //    }
        //    return null;
        //}

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        internal IOffsetVector GetClosestRessourcePool(ICoordinates coordinatesFrom, ICell cell)
        {
            ICoordinates coordinatesTo = null;
            Int16? minDistanceSofar = (Int16)this.View.Grid.GetLength(0);

            for (int i = 0; i < this.View.Grid.GetLength(0); i++)
            {
                for (int j = 0; j < this.View.Grid.GetLength(1); j++)
                {
                    if (this.View.Grid[i, j].RessourceLevel > 0)
                    {
                        var coord = new Coordinates();
                        coord.SetCoordinates((Int16)i, (Int16)j);
                        Int16? distTo = this.CellPositionInView.DistanceTo(coord);
                        if (distTo < minDistanceSofar)
                        {
                            minDistanceSofar = distTo;
                            coordinatesTo = coord;
                        }
                    }
                }
            }

            return coordinatesTo == null ? null : new OffsetVector(coordinatesFrom, coordinatesTo);
        }