本文整理汇总了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);
}
}
}
}
示例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);