public string ToFactionData(MongoGameState.Terrain terrain) { StringBuilder sb = new StringBuilder(terrain.BoardStr.Length); int curZ = 0; foreach (var gridHexagon in HexList) { if (gridHexagon.Z != curZ) { sb.Append("|"); curZ = gridHexagon.Z; } sb.Append(gridHexagon.Faction.ToString()); } return(sb.ToString()); }
public static MongoGameState.Terrain GenerateTerrain(int width, int height) { var board = new MongoGameState.Terrain(); StringBuilder sb = new StringBuilder(board.Height * (board.Width + 1)); board.Width = width; board.Height = height; var random = new Random(); Noise.Seed = random.Next(); for (var y = 0; y < board.Height; y++) { for (var x = 0; x < board.Width; x++) { var value = Math.Abs(Noise.Generate(x / 90f, y / 90f)) * 90f; sb.Append(Math.Round(value / 15f)); } sb.Append("|"); } board.BoardStr = sb.ToString(); return(board); }
private static void GenerateFaction(MongoGameState.Terrain terrain, List <MongoGameState.GameEntity> entities, GameBoard board, Vector2 center, int faction) { var centerHex = board.GetHexagon(center.X, center.Z); entities.Add(MongoGameState.GameEntity.CreateMainBase(centerHex.X, centerHex.Z, faction)); var spots = board.FindAvailableSpots(terrain.Width / 6, centerHex); foreach (var h in spots) { h.Faction = faction; } entities.AddRange(Enumerable.Range(0, 30 * 2).Select(_ => { var random = spots.Random(); return(MongoGameState.GameEntity.CreateHeli(random.X, random.Z, faction)); })); entities.AddRange(Enumerable.Range(0, 30 * 2).Select(_ => { var random = spots.Random(); return(MongoGameState.GameEntity.CreateTank(random.X, random.Z, faction)); })); }