public void Scramble(Field field) { List<TilePair> reversed = new List<TilePair>(); while (field.Tiles.Count > 0) { // Find two or more random outer tiles, remove them and store the coords List<Tile> removables = new List<Tile>(); removables.AddRange(ExtractRemovableTiles(field)); // Continue until no more removable tile pairs are left in the list while (removables.Count > 1) reversed.Add(TilePair.FetchPair(removables)); // Add remaing tile to the field foreach (Tile tile in removables) field.Add(tile); } // Read the list from behind and and get random a random tile type for each pair to build the game Random random = new Random(); for (int i = reversed.Count - 1; i >= 0; i--) { int typeIndex = random.Next() % field.Types.Length; reversed[i].Tile1.Type = field.Types[typeIndex]; reversed[i].Tile2.Type = field.Types[typeIndex]; field.Add(reversed[i].Tile1); field.Add(reversed[i].Tile2); } }
private void LoadStructure(Field field, TileType type, string path) { string[] lines = File.ReadAllLines(path); if (lines.Length % 2 != 0) throw new Exception("Invalid odd tile count!"); foreach (string line in lines) { string[] splitted = line.Split(' '); if (splitted.Length != 3) continue; Tile tile = new Tile(int.Parse(splitted[0]), int.Parse(splitted[1]), int.Parse(splitted[2]), type); field.Add(tile); } }