当前位置: 首页>>代码示例>>C#>>正文


C# Cell.GetLength方法代码示例

本文整理汇总了C#中Cell.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Cell.GetLength方法的具体用法?C# Cell.GetLength怎么用?C# Cell.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cell的用法示例。


在下文中一共展示了Cell.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CountSurroundingMines

        /// <summary>
        /// Method which calculates the number of mines, in the cells surrounding the current cell.
        /// </summary>
        /// <param name="field">The playing field.</param>
        /// <param name="row">The row of the cell which was clicked.</param>
        /// <param name="column">The column of the cell which was clicked.</param>
        /// <returns>An integer showing the number of mines in the surrounding cells.</returns>
        internal static int CountSurroundingMines(Cell[,] field, int row, int column)
        {
            int minesCount = 0;

            int minX = 0;
            int maxX = field.GetLength(0) - 1;
            int minY = 0;
            int maxY = field.GetLength(1) - 1;

            int startPosX = (row - 1 < minX) ? row : row - 1;
            int startPosY = (column - 1 < minY) ? column : column - 1;
            int endPosX = (row + 1 > maxX) ? row : row + 1;
            int endPosY = (column + 1 > maxY) ? column : column + 1;

            for (int rowNum = startPosX; rowNum <= endPosX; rowNum++)
            {
                for (int colNum = startPosY; colNum <= endPosY; colNum++)
                {
                    if (field[rowNum, colNum].IsMine)
                    {
                        minesCount++;
                    }
                }
            }

            return minesCount;
        }
开发者ID:HQC-Team-Minesweeper-5,项目名称:Minesweeper,代码行数:34,代码来源:Calculator.cs

示例2: GetAliveCells

        public static int GetAliveCells(Cell[,] cells)
        {
            int alivecount = 0;

            for (int i = 0; i < cells.GetLength(0); i++)
            {
                for (int j = 0; j < cells.GetLength(1); j++)
                {
                    alivecount += cells[i, j].IsAlive ? 1 : 0;
                }
            }
               return alivecount;
        }
开发者ID:narunaram,项目名称:GameOfLife,代码行数:13,代码来源:Utility.cs

示例3: CalculateFieldValues

        /// <summary>
        /// Calculates the values of all fields without mines in the beginning of the minesweeper game.
        /// </summary>
        /// <param name="field">Method accepts the newly constructed playing field, with mines already set in their places.</param>
        internal static void CalculateFieldValues(Cell[,] field)
        {
            int row = field.GetLength(0);
            int col = field.GetLength(1);

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    if (!field[i, j].IsMine)
                    {
                        field[i, j].Value = CountSurroundingMines(field, i, j);
                    }
                }
            }
        }
开发者ID:HQC-Team-Minesweeper-5,项目名称:Minesweeper,代码行数:20,代码来源:Calculator.cs

示例4: MakeMaze

	void MakeMaze(Cell[,] cells)
	{
		ClearOld();
		for(int x =0; x<cells.GetLength(0); x++)
		{
			for(int y=0; y<cells.GetLength(1); y++)
			{
				if(cells[x,y].isWall)
				{
					GameObject newObj = (GameObject)Instantiate(WallPrefab);
					newObj.transform.position = new Vector3(x*1.5f, 0, y*1.5f);
					newObj.transform.SetParent(transform);
					WallObjects.Add(newObj);
				}
			}
		}
	}
开发者ID:Blueteak,项目名称:MazeWar,代码行数:17,代码来源:MazeGenerator.cs

示例5: FillAngleUl

    /// <summary>
    /// Find(recursively) the shortest empty place for the new figure angleUL and save it corrdinates in global field
    /// bestRow and bestCol
    /// </summary>
    /// <param name="matrix">the matrix field where the figures are placed</param>
    /// <param name="startRow">row cordinates of the new figure</param>
    /// <param name="startCol">col cordinates of the new figure</param>
    public static void FillAngleUl(Cell[,] matrix, int startRow, int startCol)
    {
        if ((startRow < 1) || (startRow > matrix.GetLength(0) - 1) || (startCol < 1) || (startCol > matrix.GetLength(1) - 1)) //borders of the matrix for angleUL
        {
            return;
        }

        if (matrix[startRow, startCol].isVisited) //if cell is visited return
        {
            return;
        }
        else
        {
            matrix[startRow, startCol].isVisited = true;

            currentVisitedCells.Add(new KeyValuePair<int, int>(startRow, startCol));
        }

        if (matrix[startRow, startCol].isFree && matrix[startRow, startCol - 1].isFree && matrix[startRow - 1, startCol].isFree)//if empty place found
        {
            int currenrBestRow = startRow;
            int currentBestCol = startCol;

            int currentLength = Math.Abs(startRow - rowToPlace) + Math.Abs(startCol - colToPlace);

            if (currentLength < bestLength) //fix only if current length is shorter than the shortest(bestLength)
            {
                bestLength = currentLength;
                bestRow = currenrBestRow;
                bestCol = currentBestCol;
            }
            return;
        }

        FillAngleUl(matrix, startRow + 1, startCol); //down direction

        FillAngleUl(matrix, startRow - 1, startCol); //up direction

        FillAngleUl(matrix, startRow, startCol - 1); //left direction

        FillAngleUl(matrix, startRow, startCol + 1); //right direction
    }
开发者ID:RumenTonev,项目名称:BaiIvanFinalProjectSlnAndExe,代码行数:49,代码来源:bottoms.cs

示例6: Astar

    int[,] whichList; //2 dimensional array used to record

    #endregion Fields

    #region Constructors

    //-----------------------------------------------------------------------------
    // Name: AstarLibrary
    // Desc: Initializes/Redimensionates all required vars and generates walkability map.
    //-----------------------------------------------------------------------------
    public Astar(Cell[,] arr)
    {
        instance = this;

        //get map dimensions
        mapWidth = arr.GetLength(0);
        mapHeight = arr.Length / arr.GetLength(0);
        //Redimensionate needed arrays
        openList = new int[mapWidth * mapHeight + 2]; //1 dimensional array holding ID# of open list items
        whichList = new int[mapWidth + 1, mapHeight + 1];  //2 dimensional array used to record
        //whether a cell is on the open list or on the closed list.
        openX = new int[mapWidth * mapHeight + 2]; //1d array stores the x location of an item on the open list
        openY = new int[mapWidth * mapHeight + 2]; //1d array stores the y location of an item on the open list
        parentX = new int[mapWidth + 1, mapHeight + 1]; //2d array to store parent of each cell (x)
        parentY = new int[mapWidth + 1, mapHeight + 1]; //2d array to store parent of each cell (y)
        Fcost = new int[mapWidth * mapHeight + 2];	//1d array to store F cost of a cell on the open list
        Gcost = new int[mapWidth + 1, mapHeight + 1]; 	//2d array to store G cost for each cell.
        Hcost = new int[mapWidth * mapHeight + 2];	//1d array to store H cost of a cell on the open list

        // walkability array:
        // is a bidimensional int-array of ones and zeros that we generate from cells walkable states.

        // TODO: Would be nice to be able to get walkability at real time from a given external function,
        //       Right now, we have to refresh astar walkability from external grid

        walkability = new int[mapWidth, mapHeight];
        for (int y = 0; y < mapHeight; y++) {
            for (int x = 0; x < mapWidth; x++) {
                if (arr[x, y].walkable) {
                    walkability[x, y] = walkable;
                } else {
                    walkability[x, y] = unwalkable;
                }
            }
        }
    }
开发者ID:snaptothegrid,项目名称:Tiler,代码行数:46,代码来源:Astar.cs

示例7: DetonateMineBase

        internal void DetonateMineBase(Cell[,] fieldPositions, Coordinates currentCoordinates, int mineSpan, List<Coordinates> toEmpty = null)
        {
            int row = currentCoordinates.Row;
            int col = currentCoordinates.Col;
            int currentfieldsize = fieldPositions.GetLength(0);

            for (int i = row - mineSpan; i <= row + mineSpan; i++)
            {
                for (int j = col - mineSpan; j <= col + mineSpan; j++)
                {
                    bool noEmpty = (toEmpty == null) || (toEmpty.IndexOf(new Coordinates(i, j)) == -1);
                    bool isValid = IsValid(i, j, currentfieldsize);

                    if (isValid && noEmpty)
                    {
                        fieldPositions[i, j] = new DetonatedCell();
                    }
                }
            }
        }
开发者ID:BattleFieldTwo,项目名称:Teamwork,代码行数:20,代码来源:Mine.cs

示例8: SaveLevel

 public void SaveLevel(int level_nr, Cell[,] cell)
 {
     string[] lines;
     try
     {
         lines = File.ReadAllLines(filename);
     }
     catch
     {
         return;
     }
     int curr = 0;
     int curr_level_nr;
     int width = 0;
     int height = 0;
     while (curr < lines.Length)
     {
         ReadLevelHeader(lines[curr], out curr_level_nr, out width, out height);
         if (level_nr == curr_level_nr)
             break;
         else
             curr = curr + 1 + height;
     }
     int old_lenght = lines.Length;
     int delta = cell.GetLength(1) - height;
     int new_length = old_lenght + delta;
     if (new_length > old_lenght)
     {
         Array.Resize(ref lines, new_length);
         for (int z = new_length - 1; z > curr; z--)
             lines[z] = lines[z - delta];
     }
     if (new_length < old_lenght)
     {
         for (int z = new_length; z < new_length; z++)
             lines[z] = lines[z - delta];
         Array.Resize(ref lines, new_length);
     }
     int w = cell.GetLength(0);
     int h = cell.GetLength(1);
     lines[curr] = level_nr.ToString() + " " + w.ToString() + " " + h.ToString();
     for (int y = 0; y < h; y++)
     {
         lines[curr + 1 + y] = "";
         for (int x = 0; x < w; x++)
             lines[curr + 1 + y] += CellToChar(cell[x, y]);
     }
     try
     {
         File.WriteAllLines(filename, lines);
     }
     catch
     {
         return;
     }
 }
开发者ID:hely80,项目名称:Sokoban,代码行数:56,代码来源:LevelFile.cs

示例9: IsPositionValid

        private bool IsPositionValid(Cell[,] cellMatrix, int xOffset, int yOffset)
        {
            if (xOffset < 0 || yOffset < 0)
                return false;

            for (int x = 0; x < cellMatrix.GetLength(0); x++)
                for (int y = 0; y < cellMatrix.GetLength(1); y++)
                    if (cellMatrix[x, y] != null && EnvironmentShape.Matrix[x + xOffset, y + yOffset] != null)
                        return false;
            return true;
        }
开发者ID:ibratoev,项目名称:MEF.NET35,代码行数:11,代码来源:Shape.cs

示例10: GenerateMesh

    public static Mesh GenerateMesh(Cell[,] grid)
    {
        int width = grid.GetLength(0);
        int height = grid.GetLength(1);

        // Mesh data
        List<Vector3> vertices = new List<Vector3>();
        List<Vector3> normals = new List<Vector3>();
        List<Vector2> UVs = new List<Vector2>();
        List<int> triangles = new List<int>();

        // Generate geometry
        foreach (Cell cell in grid)
        {
            Vector3 cellPosition = new Vector3(cell.position.x, 0, cell.position.y);

            // Generate outer wall
            if (cell.position.x == 0)
            {
                // Create normal for face
                Vector3 normal = new Vector3(1.0f, 0.0f, 0.0f);

                // Add it four times (there are four vertices per face..)
                normals.Add(normal);
                normals.Add(normal);
                normals.Add(normal);
                normals.Add(normal);

                int index = vertices.Count;
                Vector3 wallPosition = cellPosition + new Vector3(-0.5f, 0.5f, 0);

                // Create light on wall
                AddWallToList(wallPosition, normal, true);

                // Generate vertices for wall
                vertices.Add(wallPosition + new Vector3(0,  0.5f,  0.5f));
                vertices.Add(wallPosition + new Vector3(0,  0.5f, -0.5f));
                vertices.Add(wallPosition + new Vector3(0, -0.5f,  0.5f));
                vertices.Add(wallPosition + new Vector3(0, -0.5f, -0.5f));

                // Generate UVs
                UVs.Add(new Vector2(0.5f, 0.5f));
                UVs.Add(new Vector2(1.0f, 0.5f));
                UVs.Add(new Vector2(0.5f, 1.0f));
                UVs.Add(new Vector2(1.0f, 1.0f));

                // Generate polygons
                triangles.Add(index);
                triangles.Add(index+1);
                triangles.Add(index+2);
                triangles.Add(index+2);
                triangles.Add(index+1);
                triangles.Add(index+3);
            }
            else if (cell.position.x == width-1)
            {
                // Create normal for face
                Vector3 normal = new Vector3(-1.0f, 0.0f, 0.0f);

                // Add it four times (there are four vertices per face..)
                normals.Add(normal);
                normals.Add(normal);
                normals.Add(normal);
                normals.Add(normal);

                int index = vertices.Count;
                Vector3 wallPosition = cellPosition + new Vector3(0.5f, 0.5f, 0);

                // Create light on wall
                AddWallToList(wallPosition, normal, true);

                // Generate vertices for wall
                vertices.Add(wallPosition + new Vector3(0,  0.5f,  0.5f));
                vertices.Add(wallPosition + new Vector3(0,  0.5f, -0.5f));
                vertices.Add(wallPosition + new Vector3(0, -0.5f,  0.5f));
                vertices.Add(wallPosition + new Vector3(0, -0.5f, -0.5f));

                // Generate UVs
                UVs.Add(new Vector2(0.5f, 0.5f));
                UVs.Add(new Vector2(1.0f, 0.5f));
                UVs.Add(new Vector2(0.5f, 1.0f));
                UVs.Add(new Vector2(1.0f, 1.0f));

                // Generate polygons
                triangles.Add(index+3);
                triangles.Add(index+1);
                triangles.Add(index+2);
                triangles.Add(index+2);
                triangles.Add(index+1);
                triangles.Add(index);
            }

            if (cell.position.y == 0)
            {
                // Create normal for face
                Vector3 normal = new Vector3(0.0f, 0.0f, 1.0f);

                // Add it four times (there are four vertices per face..)
                normals.Add(normal);
                normals.Add(normal);
//.........这里部分代码省略.........
开发者ID:Catchouli-old,项目名称:SuperShooterGuy3D,代码行数:101,代码来源:MeshGenerator.cs

示例11: InitializeBoard

    /// <summary>
    /// Creates a empty board
    /// </summary>
    /// <param name="matrix">Cell matrix to be filled</param>
    /// <returns>Cell matrix initialized</returns>
    private Cell[,] InitializeBoard(Cell[,] matrix)
    {
        //Initialize matrix
        for (int i = 0; i < matrix.GetLength(0); i++)
            for (int j = 0; j < matrix.GetLength(1); j++)
            {
                matrix[i, j] = new Cell();
                matrix[i, j].overFloor = OverFloorType.NONE;
                matrix[i, j].CellOwner = null;
            }

        return matrix;
    }
开发者ID:SuperGelito,项目名称:DMAI,代码行数:18,代码来源:BoardManager.cs

示例12: ConvertMatrixToVars

 /// <summary>
 /// Generates a list of variable to be used in a CSP
 /// </summary>
 /// <param name="matrix">Cell matrix used as source</param>
 /// <returns>List of variables used with value assigned</returns>
 private List<Variable> ConvertMatrixToVars(Cell[,] matrix)
 {
     List<Variable> vars = new List<Variable>();
     for (int i = 0; i < matrix.GetLength(0); i++)
         for (int j = 0; j < matrix.GetLength(1); j++)
         {
             Cell cell = matrix[i, j];
             var pos = new Vector2(i, j);
             Variable var = cell.overFloor == OverFloorType.NONE ? new Variable(pos) : new Variable(pos, cell.overFloor);
             vars.Add(var);
         }
     return vars;
 }
开发者ID:SuperGelito,项目名称:DMAI,代码行数:18,代码来源:BoardManager.cs

示例13: CheckIsInMatrix

 private void CheckIsInMatrix(string figureType, int rowToPlace, int colToPlace, Cell[,] matrix)
 {
     switch (figureType)
     {
         case "ninetile":
             if ((rowToPlace < 1) || (rowToPlace > matrix.GetLength(0) - 2) || (colToPlace < 1) || (colToPlace > matrix.GetLength(1) - 2))
             {
                 isOutOfTheMatrix = true;
             }
             break;
         case "plus":
             if ((rowToPlace < 1) || (rowToPlace > matrix.GetLength(0) - 2) || (colToPlace < 1) || (colToPlace > matrix.GetLength(1) - 2))
             {
                 isOutOfTheMatrix = true;
             }
             break;
         case "hline":
             if ((rowToPlace < 1) || (rowToPlace > matrix.GetLength(0) - 2) || (colToPlace < 0) || (colToPlace > matrix.GetLength(1) - 1))
             {
                 isOutOfTheMatrix = true;
             }
             break;
         case "vline":
             if ((rowToPlace < 0) || (rowToPlace > matrix.GetLength(0) - 1) || (colToPlace < 1) || (colToPlace > matrix.GetLength(1) - 2))
             {
                 isOutOfTheMatrix = true;
             }
             break;
         case "angle-ur":
             if ((rowToPlace < 1) || (rowToPlace > matrix.GetLength(0) - 1) || (colToPlace < 0) || (colToPlace > matrix.GetLength(1) - 2))
             {
                 isOutOfTheMatrix = true;
             }
             break;
         case "angle-dr":
             if ((rowToPlace < 0) || (rowToPlace > matrix.GetLength(0) - 2) || (colToPlace < 0) || (colToPlace > matrix.GetLength(1) - 2))
             {
                 isOutOfTheMatrix = true;
             }
             break;
         case "angle-dl":
             if ((rowToPlace < 0) || (rowToPlace > matrix.GetLength(0) - 2) || (colToPlace < 1) || (colToPlace > matrix.GetLength(1) - 1))
             {
                 isOutOfTheMatrix = true;
             }
             break;
         case "angle-ul":
             if ((rowToPlace < 1) || (rowToPlace > matrix.GetLength(0) - 1) || (colToPlace < 1) || (colToPlace > matrix.GetLength(1) - 1))
             {
                 isOutOfTheMatrix = true;
             }
             break;
         default:
             isCorrectFigure = false;
             break;
     }
 }
开发者ID:RumenTonev,项目名称:BaiIvanFinalProjectSlnAndExe,代码行数:57,代码来源:bottoms.cs

示例14: FillCellMatrix

 public static void FillCellMatrix(Cell[,] matrix)
 {
     for (int i = 0, len = matrix.GetLength(0); i < len; i += 1)
     {
         for (int j = 0; j < len; j += 1)
         {
             matrix[i, j] = new Cell();
         }
     }
 }
开发者ID:RumenTonev,项目名称:BaiIvanFinalProjectSlnAndExe,代码行数:10,代码来源:bottoms.cs

示例15: Start


//.........这里部分代码省略.........
            foreach (GameObject s in subset)
            {
                int x = Mathf.FloorToInt(s.transform.position.x - lowestX);
                int y = Mathf.FloorToInt(s.transform.position.y - lowestY);
                x = Mathf.Abs(x);
                y = Mathf.Abs(y);
                sObjects.Add(new TwoTuple(x, y), s.GetComponent<Cell>());
            }
        }

        foundGems = GameObject.FindGameObjectsWithTag("gem");
        var gemQuery = from k in foundGems orderby k.transform.position.y select k;
        var gemResult = gemQuery.ToArray();

        for (float i = hResults[0].transform.position.y; i <= hResults[hResults.Length - 1].transform.position.y; i++)
        {
            var set = from s in gemResult where s.transform.position.y == i orderby s.transform.position.x select s;
            var subset = set.ToArray();
            foreach (GameObject s in subset)
            {
                int x = Mathf.FloorToInt(s.transform.position.x - lowestX);
                int y = Mathf.FloorToInt(s.transform.position.y - lowestY);
                x = Mathf.Abs(x);
                y = Mathf.Abs(y);
                sGems.Add(new TwoTuple(x, y), s.GetComponent<Gem>());
            }
        }

        //		puzzle = new Puzzle();
        //		puzzle.sCells = sObjects;
        //		puzzle.sGems = sGems;
        //		puzzle.height = (int)height;
        //		puzzle.width = (int)width;
        //
        //		var file = File.Create("testPuzzle.lel");
        //		Serializer.Serialize(file, puzzle);

        yield return null;


        //EXPAND To ARRAY
        Cell[,] cells = new Cell[(int)width, (int)height];
        var cellKeys = sObjects.Keys.ToArray();
        foreach (TwoTuple t in cellKeys)
        {
            cells[(int)t.x, (int)t.y] = sObjects[t];
        }

        Gem[,] gems = new Gem[(int)width, (int)height];
        var gemKeys = sGems.Keys.ToArray();
        foreach (TwoTuple t in gemKeys)
        {
            gems[(int)t.x, (int)t.y] = sGems[t];
        }


        //TEST RESULTS
        //		foreach(GameObject g in foundCells){
        //			Destroy(g);
        //			yield return new WaitForSeconds(.1f);
        //		}
        //
        //		foreach(GameObject g in foundGems){
        //			Destroy(g);
        //			yield return new WaitForSeconds(.1f);
        //		}

        for (int y = 0; y < cells.GetLength(1); y++)
        {
            for (int x = 0; x < cells.GetLength(0); x++)
            {
                if (cells[x, y] != null)
                {
                    var clone = (GameObject)Instantiate(cellPrefab, new Vector3(x, y, 0), Quaternion.identity);
                }
                else
                {
                    Debug.Log("cell null at cells[" + x + "," + y + "]");
                }
                yield return new WaitForSeconds(0.25f);
            }
        }

        for (int y = 0; y < cells.GetLength(1); y++)
        {
            for (int x = 0; x < cells.GetLength(0); x++)
            {
                if (gems[x, y] != null)
                {
                    var clone = (GameObject)Instantiate(cellPrefab, new Vector3(x, y, 1), Quaternion.identity);
                }
                else
                {
                    Debug.Log("gem null at gems[" + x + "," + y + "]");
                }
                yield return new WaitForSeconds(0.25f);
            }
        }
        yield return null;
    }
开发者ID:SilenceDoGood,项目名称:Sandbox,代码行数:101,代码来源:Sandbox.cs


注:本文中的Cell.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。