Esempio n. 1
0
        /// <summary> Constructor. Creates the board's gridsquares.</summary>
        /// <param name="letterGrid"> A 3D array containing letters for tiles and spaces for holes. </param>
        public Board(char[,,] letterGrid)
        {
            if (letterGrid == null)
            {
                throw new ArgumentNullException("letterGrid cannot be null");
            }

            Rows    = letterGrid.GetLength(0);
            Columns = letterGrid.GetLength(1);
            Layers  = letterGrid.GetLength(2);

            if (Rows <= 0 || Columns <= 0 || Layers <= 0)
            {
                throw new ArgumentException("letterGrid dimensions must be positive");
            }

            for (int x = 0; x < Rows; x++)
            {
                for (int y = 0; y < Columns; y++)
                {
                    for (int z = 0; z < Layers; z++)
                    {
                        var currentLetter = letterGrid[x, y, z];
                        if (currentLetter == ' ')
                        {
                            Gridsquares.Add(new Hole(new Coordinates(x, y, z)));
                        }
                        else
                        {
                            Gridsquares.Add(new Tile(new Coordinates(x, y, z), currentLetter));
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary> Converts a list of tiles to holes. </summary>
 public void ConvertTilesToHoles(List <Tile> tiles)
 {
     foreach (var tile in tiles)
     {
         int match = Gridsquares.FindIndex(g => g == tile);
         if (match >= 0) // tile was found in the list
         {
             Gridsquares[match] = new Hole(tile.Coords);
         }
     }
     OnPropertyChanged("");
 }