コード例 #1
0
ファイル: NailsMap.cs プロジェクト: 1upD/Nails
        /**
         * <summary>
         * Applies a style to the location at the given x, y, and z coordinates.
         * <author>1upD</author>
         * </summary>
         */
        public void MarkLocation(string styleName, int x, int y, int z)
        {
            // TODO Does GetCube pass by reference or by value? What should it?
            var cube = GetCube(x, y, z);

            // If there is no cube at this location, create one.
            if (cube == null)
            {
                cube = new NailsCube(x, y, z);
                this.NailsCubes.Add(cube);
                cube.ApplyStyle(styleName);
                this.rebuildAdjacent(x, y, z);
            }
            else
            {
                // Apply the given style to the cube
                cube.ApplyStyle(styleName);
            }
        }
コード例 #2
0
ファイル: NailsMap.cs プロジェクト: 1upD/Nails
        /**
         * <summary>
         * Gets the cube at a given location given by an x, y, or z coordinate. Coordinates can be negative.
         * <author>1upD</author>
         * </summary>
         */
        public NailsCube GetCube(int x, int y, int z)
        {
            // Return value
            NailsCube cube = null;

            // Use Linq to query the list
            var cubesList = NailsCubes.Where(i => i.X == x && i.Y == y && i.Z == z).ToList();

            // If there is a cube at this location, return it
            if (cubesList != null && cubesList.Count > 0)
            {
                cube = cubesList[0];
            }

            // If more than one cube is found, log an error
            if (cubesList.Count > 1)
            {
                log.Error(string.Format("NailsCube.GetCube(): Multiple cubes found at one location: x {0} y {1} z {2}", x.ToString(), y.ToString(), z.ToString()));
            }

            // If there is no cube at this location, return null
            return(cube);
        }