/// <summary> Resets the whole field and the accompanying properties. </summary> /// /// <remarks> Christopher, 6/19/2015. </remarks> private void ResetField() { for (int i = 0; i < 100; i++) { var button = this.ContentRoot.Children.OfType <Button>().Single(x => x.TabIndex == i); button.Background = new SolidColorBrush(Colors.LightBlue); App.WarViewModel.Field[i] = false; } App.WarViewModel.WhichShip.SetAllValues(false); App.GameViewModel.MyField.SetAllValues(false); App.WarViewModel.WhichShip[0] = true; App.WarViewModel.AllShipsSet = false; App.WarViewModel.ShipLength = 5; App.WarViewModel.Battleship = 1; App.WarViewModel.Cruiser = 2; App.WarViewModel.Destroyer = 3; App.WarViewModel.Submarine = 4; ships.ResetValues(); }
/// <summary> Places all ships for the enemy in random psoitions. </summary> /// /// <remarks> Christopher, 6/19/2015. </remarks> /// /// <returns> A Task<bool> </returns> private async Task <bool> PlaceEnemy() { int counter = 0; ships.ResetValues(); while (App.GameViewModel.AllShipsSet == false) { Random random = new Random(); var randomNumber = random.Next(0, 100); counter++; PlaceShip(randomNumber, App.GameViewModel.ShipLength, GetRandomBoolean()); if (ships.Battleship == 0) { App.GameViewModel.WhichShip.SetAllValues(false); App.GameViewModel.WhichShip[1] = true; App.GameViewModel.ShipLength = 4; } if (ships.Cruiser == 0) { App.GameViewModel.WhichShip.SetAllValues(false); App.GameViewModel.WhichShip[2] = true; App.GameViewModel.ShipLength = 3; } if (ships.Destroyer == 0) { App.GameViewModel.WhichShip.SetAllValues(false); App.GameViewModel.WhichShip[3] = true; App.GameViewModel.ShipLength = 2; } if (counter > 200) { ResetField(); await PlaceEnemy(); } await Task.Delay(1); } return(true); }