public void AddPlate(Button btnButton, int x, int y) { ShipPlate plate = new ShipPlate(row: y, column: x, button: btnButton); #if DEBUG Trace.WriteLine(message: "Adding plate btn " + plate.BtnButton.ToString()); #endif ShipPlates.Add(item: plate); }
public bool RevealRandomButton() { ShipPlate plate = null; while (plate == null || plate.IsRevealed) { plate = ShipPlates[index : _rnd.Next(maxValue : ShipPlates.Count)]; if (plate == null) { plate = ShipPlates[index : 0]; break; } } return(RevealButton(btn: plate.BtnButton as Button)); }
public bool RevealButton(Button btn) { ShipPlate plate = ShipPlates. FirstOrDefault(predicate: x => Equals(objA: x.BtnButton as Button, objB: btn)); if (plate == null) { throw new NullReferenceException(message: "Plate not found from " + ShipPlates.Count); } if (!plate.IsRevealed) { SetButtonVisuals(stat: plate.IsMined?ShipStat.Ship: ShipStat.Water, btn: btn, plate: plate); } return(CheckGameEndingConditions()); }
private void SetButtonVisuals(ShipStat stat, Button btn, ShipPlate plate) { btn.IsEnabled = false; btn.Background = Brushes.DimGray; plate.IsRevealed = true; switch (stat) { case ShipStat.Ship: btn.Content = "X"; ShipsLeft--; btn.Background = Brushes.Crimson; break; case ShipStat.Water: btn.Content = ""; break; default: btn.Content = ""; break; } }