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


C# Char.GetLength方法代码示例

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


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

示例1: ShortestDistance

 Int32 ShortestDistance(Char[,] map)
 {
     Int32 i, j, sh, shi, shj, n = map.GetLength(0), m = map.GetLength(1);
     Int32[,] dist = new Int32[n, m];
     for (i = 0; i < n; ++i) {
         for (j = 0; j < m; ++j) {
             dist[i, j] = -1;
         }
     }
     dist[0, 0] = 0;
     Queue<Int32> qu = new Queue<Int32>();
     qu.Enqueue(0);
     qu.Enqueue(0);
     while (qu.Count != 0) {
         i = qu.Dequeue();
         j = qu.Dequeue();
         if (map[i, j] == 'x') {
             return dist[i, j];
         }
         for (sh = 0; sh < 4; ++sh) {
             shi = i + shift[sh, 0];
             shj = j + shift[sh, 1];
             if (shi >= 0 && shj >= 0 && shi < n && shj < m && map[shi, shj] != '#' && dist[shi, shj] < 0) {
                 dist[shi, shj] = dist[i, j] + 1;
                 qu.Enqueue(shi);
                 qu.Enqueue(shj);
             }
         }
     }
     return -1;
 }
开发者ID:dibrov4bor,项目名称:Sumy-Jam,代码行数:31,代码来源:Gen+2C.cs

示例2: DrawMap

 public void DrawMap(Char[,]AiMap,GameObject[,]VisualMap)
 {
     if (!Initialised)
         PrevMap = new char[AiMap.GetLength(0),AiMap.GetLength(1)];
     //will need to be updated to reflect changes i.e building, tree cutting
     int height = 512; // map height
     int width = 512;
     for (int i = 0; i < height; ++i)
     {
         for (int j = 0; j < width; ++j)
         {
            if(PrevMap[i,j] != AiMap[i,j])
            {
                GameObject.DestroyImmediate(VisualMap[i, j]);
                switch (AiMap[i, j])
                {
                    case '.':
                        VisualMap[i, j] = GameObject.Instantiate(Walkable, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        // walkable tile NOT GRASS
                        break;
                    case 'G':
                        VisualMap[i, j] = GameObject.Instantiate(Grass, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        // walkable tile IS GRASS
                        break;
                    case '@':
                        VisualMap[i, j] = GameObject.Instantiate(OutOfBounds, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        // OUT OF BOUNDS
                        break;
                    case 'O':
                        VisualMap[i, j] = GameObject.Instantiate(OutOfBounds, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        // OUT OF BOUNDS
                        break;
                    case 'T':
                        VisualMap[i, j] = GameObject.Instantiate(Trees, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        // TREES
                        break;
                    case 'S':
                        VisualMap[i, j] = GameObject.Instantiate(Swamp, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        // SWAMP
                        break;
                    case 'W':
                        VisualMap[i, j] = GameObject.Instantiate(Water, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        // WATER
                        break;
                    case 'E':
                        VisualMap[i, j] = GameObject.Instantiate(Entrance, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //Building Entrance Universal and Walkable
                        break;
                    case '1':
                        VisualMap[i, j] = GameObject.Instantiate(Barracks, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        // Barracks
                        break;
                    case '2':
                        VisualMap[i, j] = GameObject.Instantiate(School, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //School
                        break;
                    case '3':
                        VisualMap[i, j] = GameObject.Instantiate(Storage, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //Storage
                        break;
                    case '4':
                        VisualMap[i, j] = GameObject.Instantiate(Sawmill, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //sawmill
                        break;
                    case '5':
                        VisualMap[i, j] = GameObject.Instantiate(Blacksmith, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //blacksmith
                        break;
                    case '6':
                        VisualMap[i, j] = GameObject.Instantiate(Turf, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //Turf
                        break;
                    case '7':
                        VisualMap[i, j] = GameObject.Instantiate(Smelter, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //Smelter
                        break;
                    case '8':
                        VisualMap[i, j] = GameObject.Instantiate(House, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //HOuse
                        break;
                    case '9':
                        VisualMap[i, j] = GameObject.Instantiate(Mine, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //Mine
                        break;
                    case '0':
                        VisualMap[i, j] = GameObject.Instantiate(Quarry, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //Quarry
                        break;
                    case '-':
                        VisualMap[i, j] = GameObject.Instantiate(Market, new Vector3(i, j, -1), Quaternion.identity) as GameObject;//sprite goes here
                        //Market
                        break;
                }
             }
         }
     }
     if (!Initialised)
     {
         Initialised = true;
         PrevMap = AiMap;
//.........这里部分代码省略.........
开发者ID:nathn123,项目名称:Ai-RTS-Game,代码行数:101,代码来源:MapGen.cs


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