private List<GameBlockSelector> GetNullNeighbors(GameBlockSelector gameBlockSelector) { List<GameBlockSelector> nullNeighbor = new List<GameBlockSelector>(); int row = gameBlockSelector.Row - 1; int column = gameBlockSelector.Column; if (row >= 0 && row < this.solvedGameBoard.Count && column >= 0 && column < this.solvedGameBoard[0].Count) { GameBlockSelector top = this.solvedGameBoard[row][column]; if (top.BlockType == GameBoard.GameBlockType.Null) { nullNeighbor.Add(top); } } row = gameBlockSelector.Row + 1; column = gameBlockSelector.Column; if (row >= 0 && row < this.solvedGameBoard.Count && column >= 0 && column < this.solvedGameBoard[0].Count) { GameBlockSelector bottom = this.solvedGameBoard[row][column]; if (bottom.BlockType == GameBoard.GameBlockType.Null) { nullNeighbor.Add(bottom); } } row = gameBlockSelector.Row; column = gameBlockSelector.Column - 1; if (row >= 0 && row < this.solvedGameBoard.Count && column >= 0 && column < this.solvedGameBoard[0].Count) { GameBlockSelector left = this.solvedGameBoard[row][column]; if (left.BlockType == GameBoard.GameBlockType.Null) { nullNeighbor.Add(left); } } row = gameBlockSelector.Row; column = gameBlockSelector.Column + 1; if (row >= 0 && row < this.solvedGameBoard.Count && column >= 0 && column < this.solvedGameBoard[0].Count) { GameBlockSelector right = this.solvedGameBoard[row][column]; if (right.BlockType == GameBoard.GameBlockType.Null) { nullNeighbor.Add(right); } } return nullNeighbor; }
private void OnInitializeGameBoard() { ObservableCollection<ObservableCollection<GameBlockSelector>> oldBoard = this.solvedGameBoard; int oldRows = oldBoard == null ? 0 : oldBoard.Count; int oldColumns = oldRows > 0 ? oldBoard[0].Count : 0; this.SolvedGameBoard = new ObservableCollection<ObservableCollection<GameBlockSelector>>(); for (int i = 0; i < this.numberOfRows; i++) { ObservableCollection<GameBlockSelector> row = new ObservableCollection<GameBlockSelector>(); for (int j = 0; j < this.numberOfColumns; j++) { if (oldRows > i && oldColumns > j) { row.Add(oldBoard[i][j]); } else { GameBlockSelector gameBlockSelector = new GameBlockSelector(GameBoard.GameBlockType.Null); gameBlockSelector.Row = i; gameBlockSelector.Column = j; row.Add(gameBlockSelector); } } this.solvedGameBoard.Add(row); } }
private GameBlockSelector GetNeighbor(GameBlockSelector gameBlockSelector, MovementDirection direction) { GameBlockSelector neighbor = null; int row; int column; switch (direction) { case MovementDirection.Up: row = gameBlockSelector.Row - 1; column = gameBlockSelector.Column; if (row >= 0 && row < this.solvedGameBoard.Count && column >= 0 && column < this.solvedGameBoard[0].Count) { neighbor = this.solvedGameBoard[row][column]; } break; case MovementDirection.Down: row = gameBlockSelector.Row + 1; column = gameBlockSelector.Column; if (row >= 0 && row < this.solvedGameBoard.Count && column >= 0 && column < this.solvedGameBoard[0].Count) { neighbor = this.solvedGameBoard[row][column]; } break; case MovementDirection.Left: row = gameBlockSelector.Row; column = gameBlockSelector.Column - 1; if (row >= 0 && row < this.solvedGameBoard.Count && column >= 0 && column < this.solvedGameBoard[0].Count) { neighbor = this.solvedGameBoard[row][column]; } break; case MovementDirection.Right: row = gameBlockSelector.Row; column = gameBlockSelector.Column + 1; if (row >= 0 && row < this.solvedGameBoard.Count && column >= 0 && column < this.solvedGameBoard[0].Count) { neighbor = this.solvedGameBoard[row][column]; } break; } return neighbor; }