private void InitGrid() { MineGrid.ColumnDefinitions.Clear(); MineGrid.RowDefinitions.Clear(); MineGrid.Children.Clear(); MineGrid.Height = 40 * _minefield.Rows; MineGrid.Width = 40 * _minefield.Cols; for (int row = 0; row < _minefield.Rows; row++) { MineGrid.RowDefinitions.Add(new RowDefinition()); } for (int col = 0; col < _minefield.Cols; col++) { MineGrid.ColumnDefinitions.Add(new ColumnDefinition()); } for (int row = 0; row < _minefield.Rows; row++) { for (int col = 0; col < _minefield.Cols; col++) { var cell = new MineFieldCell(row, col, _minefield.GetCell(row, col), LeftClick, RightClick); Grid.SetRow(cell, row); Grid.SetColumn(cell, col); MineGrid.Children.Add(cell); } } Refresh(); }
private async Task Click(MineFieldCell fieldCell, bool uncover) { var cell = fieldCell.MineCell; if (_minefield.GameState == GameState.Defeat || _minefield.GameState == GameState.Victory || await InitMineFieldIfNeeded(cell.Row, cell.Col)) { return; } if (cell.IsUncovered) { _minefield.UncoverNeighbours(cell); } else if (!uncover) { _minefield.ToggleFlagOnCell(cell.Row, cell.Col); } else { _minefield.UncoverCell(cell); } Refresh(); }
private async Task RightClick(MineFieldCell fieldCell) { await Click(fieldCell, _flagMode); }
private async Task LeftClick(MineFieldCell fieldCell) { await Click(fieldCell, !_flagMode); }