Exemplo n.º 1
0
        public GameBoard(MongoGameState.GameState gameState)
        {
            GameState = gameState;
            BoardSize = new Size();
            HexList   = new List <GridHexagon>();
            HexBoard  = new Dictionary <int, GridHexagon>();
            var str = GameState.Terrain.BoardStr;

            SetSize(GameState.Terrain.Width, GameState.Terrain.Height);

            foreach (var vectorHex in str.ToHexMap())
            {
                var gridHexagon = new GridHexagon();
                gridHexagon.X      = vectorHex.X;
                gridHexagon.Z      = vectorHex.Z;
                gridHexagon.Height = vectorHex.Item;
                Add(gridHexagon);
            }

            if (GameState.FactionData != null)
            {
                foreach (var vectorHex in GameState.FactionData.ToHexMap())
                {
                    GetHexagon(vectorHex.X, vectorHex.Z).Faction = vectorHex.Item;
                }
            }
        }
Exemplo n.º 2
0
        public static void startNewGame()
        {
            MongoGameState.Collection.DeleteMany(FilterDefinition <MongoGameState.GameState> .Empty);
            MongoGameVote.Collection.DeleteMany(FilterDefinition <MongoGameVote.GameVote> .Empty);
            MongoTickResult.Collection.DeleteMany(FilterDefinition <MongoTickResult.TickResult> .Empty);
            MongoServerLog.Collection.DeleteMany(FilterDefinition <MongoServerLog.ServerLog> .Empty);

            MongoGameVote.Collection.Indexes.CreateOne(Builders <MongoGameVote.GameVote> .IndexKeys.Ascending(_ => _.Generation));

            var terrain = GenerateTerrain(84 * 3, 84 * 3);
            var board   = new GameBoard(new MongoGameState.GameState()
            {
                Terrain = terrain
            });
            var entities = new List <MongoGameState.GameEntity>();

            GenerateFaction(terrain, entities, board, new Vector2(terrain.Width / 4, terrain.Height / 3), 1);
            GenerateFaction(terrain, entities, board, new Vector2(terrain.Width / 4 * 3, terrain.Height / 3), 2);
            GenerateFaction(terrain, entities, board, new Vector2(terrain.Width / 4 * 2, terrain.Height / 3 * 2), 3);


            StringBuilder sb   = new StringBuilder(terrain.BoardStr.Length);
            int           curZ = 0;

            foreach (var gridHexagon in board.HexList)
            {
                if (gridHexagon.Z != curZ)
                {
                    sb.Append("|");
                    curZ = gridHexagon.Z;
                }
                sb.Append(gridHexagon.Faction.ToString());
            }

            var state = new MongoGameState.GameState
            {
                Generation          = 0,
                LastGeneration      = DateTime.UtcNow,
                TickIntervalSeconds = 60,
                Terrain             = terrain,
                FactionData         = sb.ToString(),
                Entities            = entities,
                Initial             = false
            }.InsertSync();

            state.Id      = ObjectId.Empty;
            state.Initial = true;
            state.InsertSync();
        }