本文整理匯總了C#中GameState.Save方法的典型用法代碼示例。如果您正苦於以下問題:C# GameState.Save方法的具體用法?C# GameState.Save怎麽用?C# GameState.Save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類GameState
的用法示例。
在下文中一共展示了GameState.Save方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SaveToDb
public void SaveToDb(string name)
{
Console.WriteLine ("Saving to db");
Map map = new Map () {
Height = this.h,
Width = this.w
};
GameState game = new GameState () {
Name = name,
Map = map,
};
string[] deleteTables = new string[] {
"gamestate",
"map",
"hex",
"hexresource",
"map_cities",
"map_rivers",
"map_hexes",
"hex_edges",
"hex_effects",
"kingdom"
};
foreach (string deleteTable in deleteTables)
MySqlProvider.Provider.ExecuteNonQuery ("truncate " + deleteTable + ";");
map.Game = game;
map.Save ();
game.Save ();
RecordList<Hex> hexes = new RecordList<Hex> ();
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
Hex hex = new Hex ();
hex.EnsureId ();
hex.X = x;
hex.Y = y;
Color c = b.GetPixel (x, y);
if (c == blue)
hex.Terrain = TerrainType.Sea;
else if (c == white)
hex.Terrain = TerrainType.Mountains;
else if (c == darkGreen)
hex.Terrain = TerrainType.Forest;
else if (c == town)
{
hex.Terrain = TerrainType.Plains;
}
else
hex.Terrain = TerrainType.Plains;
hexes.Add (hex);
hexMap[x,y] = hex;
}
}
//cities have to be done in a separate pass to account for growth.
map.Hexes = hexes;
map.EnsureMapIsBuilt (true);
//check coastals
foreach (Hex h in hexes)
if (h.Terrain == TerrainType.Sea)
CheckCoastal (h);
hexes.Save ();
foreach (var kvp in riverPaths)
{
River r = new River();
int z = 0;
foreach(Point p in kvp.Value)
{
r.Path.Add (new Triple<int> () {
X = p.X,
Y = p.Y,
Z = z++
});
}
r.Save ();
r.Path.Save ();
r.SaveRelations("Path");
map.Rivers.Add (r);
}
map.SaveRelations ("Rivers");
map.SaveRelations ("Hexes");
}