Beispiel #1
0
        /// <summary>
        /// Set up a game.
        /// </summary>
        /// <param name="setup">The numbers in this game, as a two dimensional array.</param>
        public Game(int?[,] setup)
        {
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    Tile tile = new Tile(setup[i, j]);
                    tile.XIndex = i;
                    tile.YIndex = j;
                    _tiles[i, j] = tile;
                }
            }

            for (int i = 0; i < 9; i++)
            {
                _rows[i] = new TileCollection(GetRow(_tiles, i));
                _columns[i] = new TileCollection(GetColumn(_tiles, i));

                foreach (Tile tile in _rows[i].Tiles)
                    tile.Row = _rows[i];

                foreach (Tile tile in _columns[i].Tiles)
                    tile.Column = _columns[i];
            }

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int index = i * 3 + j;
                    _squares[index] = new TileCollection(GetSquare(_tiles, i, j));

                    foreach (Tile tile in _squares[index].Tiles)
                        tile.Square = _squares[index];
                }
            }
        }
Beispiel #2
0
 private static IEnumerable<Tile> GetRow(Tile[,] tiles, int rowIndex)
 {
     for (int i = 0; i < 9; i++)
         yield return tiles[rowIndex, i];
 }
Beispiel #3
0
        private static IEnumerable<Tile> GetSquare(Tile[,] tiles, int vertIndex, int horzIndex)
        {
            int startRow = vertIndex * 3;
            int startColumn = horzIndex * 3;

            for (int i = startRow; i < startRow + 3; i++)
            {
                for (int j = startColumn; j < startColumn + 3; j++)
                {
                    yield return tiles[i, j];
                }
            }
        }
Beispiel #4
0
 private static IEnumerable<Tile> GetColumn(Tile[,] tiles, int colIndex)
 {
     for (int i = 0; i < 9; i++)
         yield return tiles[i, colIndex];
 }