private void ResetGame() { foreach (var child in MineGrid.Children) { var button = child as MineButton; button.IsEnabled = true; button.BackgroundColor = Color.Gray; button.Source = _blank; } _core = null; _minesLeft = mines; MinesLeftLabel.Text = String.Format(MinesLeftText, _minesLeft); }
private void OpenField(MineButton button) { if (_core == null) { _core = new MineSweeper.Core.MineSweeper(columns, rows, mines, button.XPosition, button.YPosition); } if (_core.IsMarked(button.XPosition, button.YPosition)) { return; } button.IsEnabled = false; button.BackgroundColor = Color.Silver; var status = _core.Open(button.XPosition, button.YPosition); switch (status) { case FieldStatus.FieldIsMine: ServeGameOver(button); return; case FieldStatus.MinesNearby0: button.Source = _blank; OpenNearbyFields(button); break; case FieldStatus.MinesNearby1: button.Source = _1; break; case FieldStatus.MinesNearby2: button.Source = _2; break; case FieldStatus.MinesNearby3: button.Source = _3; break; case FieldStatus.MinesNearby4: button.Source = _4; break; case FieldStatus.MinesNearby5: button.Source = _5; break; case FieldStatus.MinesNearby6: button.Source = _6; break; case FieldStatus.MinesNearby7: button.Source = _7; break; default: button.Source = _8; break; } if (MineGrid.Children.OfType <MineButton>().Count(b => b.IsEnabled) == mines) { ServeGameWin(); } }
private void OpenField(MineButton button) { if(_core == null) { _core = new MineSweeper.Core.MineSweeper(columns, rows, mines, button.XPosition, button.YPosition); } if(_core.IsMarked(button.XPosition, button.YPosition)) { return; } button.IsEnabled = false; button.BackgroundColor = Color.Silver; var status = _core.Open(button.XPosition, button.YPosition); switch(status) { case FieldStatus.FieldIsMine: ServeGameOver(button); return; case FieldStatus.MinesNearby0: button.Source = _blank; OpenNearbyFields(button); break; case FieldStatus.MinesNearby1: button.Source = _1; break; case FieldStatus.MinesNearby2: button.Source = _2; break; case FieldStatus.MinesNearby3: button.Source = _3; break; case FieldStatus.MinesNearby4: button.Source = _4; break; case FieldStatus.MinesNearby5: button.Source = _5; break; case FieldStatus.MinesNearby6: button.Source = _6; break; case FieldStatus.MinesNearby7: button.Source = _7; break; default: button.Source = _8; break; } if(MineGrid.Children.OfType<MineButton>().Count(b => b.IsEnabled) == mines) { ServeGameWin(); } }