static Tile[,] RandomFillMap() { for (int row = 0; row < MapHeight; row++) { for (int column = 0; column < MapWidth; column++) { if (column == 0) { map[column, row] = new Tile(column, row, true); } else if (row == 0) { map[column, row] = new Tile(column, row, true); } else if (column == MapWidth - 1) { map[column, row] = new Tile(column, row, true); } else if (row == MapHeight - 1) { map[column, row] = new Tile(column, row, true); } else { map[column, row] = new Tile(column, row, RandomizationFunctions.Chance(PercentAreWalls)); } } } return(map); }
public Coords PlaceGold(IEnumerable <Client> clients) { var coords = GetRandomFreeCoords(clients); GameMap[coords.X, coords.Y].Gold = RandomizationFunctions.GetRandomNumber(10, 50); return(coords); }
public Coords CreatePotion(IEnumerable <Client> clients) { var coords = GetRandomFreeCoords(clients); var health = RandomizationFunctions.GetRandomNumber(1, 100); GameMap[coords.X, coords.Y].Health = health; return(coords); }
private static void UpdateMap(WorldMap world, List <Client> clients, Queue <Response> responseQueue, bool json) { if (RandomizationFunctions.Chance(15)) { var coords = world.PlaceGold(clients); responseQueue.Enqueue(new Response { ResponseType = Response.MessageType.UPDATETILE, StringParam = EncodeTile(world, coords, json) }); } if (RandomizationFunctions.Chance(95)) { var coords = world.CreatePotion(clients); responseQueue.Enqueue(new Response { ResponseType = Response.MessageType.UPDATETILE, StringParam = EncodeTile(world, coords, json) }); } }
public Coords GetRandomFreeCoords(IEnumerable <Client> clients) { Coords coords = null; var tileIsFree = false; do { coords = new Coords( RandomizationFunctions.GetRandomNumber(0, GameMap.GetLength(0) - 1), RandomizationFunctions.GetRandomNumber(0, GameMap.GetLength(1) - 1) ); if (GameMap[coords.X, coords.Y].HasGold || GameMap[coords.X, coords.Y].IsCaveWall || GameMap[coords.X, coords.Y].HasHealth) { continue; } tileIsFree = true; foreach (var client in clients) { var player = client.Player; if (player == null) { continue; } if (player.Coordinates.X == coords.X && player.Coordinates.Y == coords.Y) { tileIsFree = false; break; } } } while (!tileIsFree); return(coords); }