コード例 #1
0
ファイル: TileHelper.cs プロジェクト: ronaldme/Triumph
        /// <summary>
        /// Returns the Tile with via the given TileCoordinates from the tiles dictionary. Or an KeyNotFoundException if either of the keys is not found.
        /// </summary>
        /// <param Name="coor"></param>
        /// <returns></returns>
        public static Tile GetTile(TileCoordinates coor)
        {
            if (levelManager.CurrentLevel.Tiles.ContainsKey(coor.ColumnId) && levelManager.CurrentLevel.Tiles[coor.ColumnId].ContainsKey(coor.RowId))
            {
                return(levelManager.CurrentLevel.Tiles[coor.ColumnId][coor.RowId]);
            }

            return(null);
        }
コード例 #2
0
ファイル: Tile.cs プロジェクト: ronaldme/Triumph
        private void Awake()
        {
            // The world starts at 0,0 and goes in the x in the positive and the y in the negative. It always needs to be this way other wise the calculation will not work.
            int cId = (((int)gameObject.transform.position.x) / 2) + 1;
            int rId = Mathf.Abs((((int)gameObject.transform.position.y) / 2) - 1);

            Coordinate = new TileCoordinates(cId, rId);
            Vector2    = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y);
            TileHelper.AddTile(this);
            //AddTile();
            IsFogShown = false;
            InitHighlights();
        }
コード例 #3
0
ファイル: TileHelper.cs プロジェクト: ronaldme/Triumph
        /// <summary>
        /// This method returns all the tiles that are within a certain range calculated from the Tile which you specify.
        /// It takes into account out of bounds and doesn't add the Tile the which has the same coordinates as the given center point.
        /// The return type is the same as the Tile collection in the GameManager for consistancy.
        /// The movement and attack classes / implementations should be responsible for further calculations.
        /// So if you want to Highlight possible attack locations the attack class / method should loop through all tiles in range
        /// and only hightlight the tiles on which an enemy unit is placed.
        /// </summary>
        /// <param Name="centerPointTileCoordinate">The tilecoordinate from which the calculation is done. </param>
        /// <param Name="range">The range from which tiles get returned</param>
        public static Dictionary <int, Dictionary <int, Tile> > GetAllTilesWithinRange(
            TileCoordinates centerPointTileCoordinate, int range)
        {
            // Check if the range is 0 or smaller.
            if (range <= 0)
            {
                throw new ArgumentOutOfRangeException("range",
                                                      "The entered range is 0 or smaller. Please use a correct range");
            }

            if (!levelManager.CurrentLevel.Tiles.ContainsKey(centerPointTileCoordinate.ColumnId) ||
                !levelManager.CurrentLevel.Tiles[centerPointTileCoordinate.ColumnId].ContainsKey(centerPointTileCoordinate.RowId))
            {
                throw new ArgumentOutOfRangeException("centerPointTileCoordinate",
                                                      "The given center Tile does not exist. Please give a valid TileCoordinate");
            }

            // collection for holding the possible tiles that are within range.
            var possibleLocations = new Dictionary <int, Dictionary <int, Tile> >();

            int columnId = centerPointTileCoordinate.ColumnId;
            int rowId    = centerPointTileCoordinate.RowId;

            // The row size in which it goes up and down.
            int size = 0;

            int beginColumnId   = columnId - range;
            int endColumnId     = columnId + range;
            int currentColumnId = beginColumnId;

            while (currentColumnId <= endColumnId)
            {
                // If the current tilecoordinate falls outside the level dont bother getting it.
                if (!levelManager.CurrentLevel.Tiles.ContainsKey(currentColumnId))
                {
                    currentColumnId++;
                    size++;
                    continue;
                }

                int beginRowId   = rowId - size;
                int endRowId     = rowId + size;
                int currentRowid = beginRowId;

                while (currentRowid <= endRowId)
                {
                    // If the current tilecoordinate falls outside the level dont bother getting it.
                    // And if the current tilecoordinate is on the same place as the original coordinate dont get it.
                    if (!levelManager.CurrentLevel.Tiles[currentColumnId].ContainsKey(currentRowid) ||
                        (currentColumnId == centerPointTileCoordinate.ColumnId &&
                         currentRowid == centerPointTileCoordinate.RowId))
                    {
                        currentRowid++;
                        continue;
                    }
                    // Get the Tile from the Tile list and add it to the return list.
                    Tile t = GetTile(new TileCoordinates(currentColumnId, currentRowid));
                    if (!possibleLocations.ContainsKey(currentColumnId))
                    {
                        possibleLocations.Add(currentColumnId, new Dictionary <int, Tile>());
                    }
                    possibleLocations[currentColumnId].Add(currentRowid, t);
                    currentRowid++;
                }
                currentColumnId++;
                // Determine if the currentColumnId has reached the center Tile columnid, ifso start making the size smaller.
                size = currentColumnId <= columnId ? size += 1 : size -= 1;
            }
            return(possibleLocations);
        }