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


C# GameState.Save方法代码示例

本文整理汇总了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");
        }
开发者ID:bennidhamma,项目名称:TerrainGen,代码行数:91,代码来源:Genner.cs


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