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


C# Country.addNeighbor方法代码示例

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


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

示例1: CreateGrid

        public void CreateGrid()
        {
            float x = (screenWidth - country.Width * COLS) / 2;
            float y = (screenHeight - country.Height * ROWS) / 2;
            offset = new Vector2(x, y);
            territories = new Dictionary<string, Country>();

            for (int r = 0; r < ROWS; ++r)
            {
                for (int c = 0; c < COLS; ++c)
                {
                    x = country.Width / 2 + country.Width * c;
                    y = country.Height / 2 + country.Height * r;
                    Vector2 loc = new Vector2(x, y);
                    Country ctry = new Country(loc, country, noone, 4);
                    territories.Add(rcIdx(r, c), ctry);
                }
            }

            for (int r = 0; r < ROWS; ++r)
            {
                for (int c = 0; c < COLS; ++c)
                {
                    Country ctry, nbr;
                    territories.TryGetValue(rcIdx(r, c), out ctry);
                    if (c - 1 >= 0)
                    {
                        territories.TryGetValue(rcIdx(r, c - 1), out nbr);
                        ctry.addNeighbor(nbr);
                    }
                    if (c + 1 < COLS)
                    {
                        territories.TryGetValue(rcIdx(r, c + 1), out nbr);
                        ctry.addNeighbor(nbr);
                    }
                    if (r - 1 >= 0)
                    {
                        territories.TryGetValue(rcIdx(r - 1, c), out nbr);
                        ctry.addNeighbor(nbr);
                    }
                    if (r + 1 < ROWS)
                    {
                        territories.TryGetValue(rcIdx(r + 1, c), out nbr);
                        ctry.addNeighbor(nbr);
                    }
                }
            }
        }
开发者ID:kzielnicki,项目名称:Brisk,代码行数:48,代码来源:GameplayScreen.cs

示例2: CreateWorld


//.........这里部分代码省略.........
            cont.Add(c);
            territories.TryGetValue("middleEast", out c);
            cont.Add(c);
            territories.TryGetValue("afghanistan", out c);
            cont.Add(c);
            territories.TryGetValue("siberia", out c);
            cont.Add(c);
            territories.TryGetValue("moreSiberia", out c);
            cont.Add(c);
            territories.TryGetValue("kamchatka", out c);
            cont.Add(c);
            territories.TryGetValue("india", out c);
            cont.Add(c);
            territories.TryGetValue("china", out c);
            cont.Add(c);
            continents.Add(cont);

            cont = new Continent("Australia", 1);
            territories.TryGetValue("indonesia", out c);
            cont.Add(c);
            territories.TryGetValue("easternAustralia", out c);
            cont.Add(c);
            territories.TryGetValue("westernAustralia", out c);
            cont.Add(c);
            continents.Add(cont);
            #endregion

            // Adjacency lists
            Country n;

            #region NorthAmericaNeighbors
            territories.TryGetValue("alaska", out c);
            territories.TryGetValue("northwest", out n);
            c.addNeighbor(n);
            territories.TryGetValue("kamchatka", out n);
            c.addNeighbor(n);

            territories.TryGetValue("northwest", out c);
            territories.TryGetValue("alaska", out n);
            c.addNeighbor(n);
            territories.TryGetValue("montreal", out n);
            c.addNeighbor(n);
            territories.TryGetValue("westernUS", out n);
            c.addNeighbor(n);

            territories.TryGetValue("montreal", out c);
            territories.TryGetValue("northwest", out n);
            c.addNeighbor(n);
            territories.TryGetValue("greenland", out n);
            c.addNeighbor(n);
            territories.TryGetValue("westernUS", out n);
            c.addNeighbor(n);
            territories.TryGetValue("easternUS", out n);
            c.addNeighbor(n);

            territories.TryGetValue("greenland", out c);
            territories.TryGetValue("montreal", out n);
            c.addNeighbor(n);
            territories.TryGetValue("westernEurope", out n);
            c.addNeighbor(n);

            territories.TryGetValue("westernUS", out c);
            territories.TryGetValue("northwest", out n);
            c.addNeighbor(n);
            territories.TryGetValue("montreal", out n);
            c.addNeighbor(n);
开发者ID:kzielnicki,项目名称:Brisk,代码行数:67,代码来源:GameplayScreen.cs


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