private void secondShipChoice_Click(object sender, RoutedEventArgs e) { ListShip listReturn = new ListShip(); List <Ship> corvetteList = new List <Ship>(); Ship corvette = new Ship(); corvette.Name = "Corvette"; corvette.State = true; // dimensions of the ship if (this.secondShipWidthTxt.Text == "" || this.secondShipWidthTxt.Text == "0") { corvette.WidthNbBox = 3; } else { int widthChoice = int.Parse(this.secondShipWidthTxt.Text); if (widthChoice < 0) { widthChoice = -widthChoice; } corvette.WidthNbBox = widthChoice; } if (this.secondShipHeightTxt.Text == "" || this.secondShipHeightTxt.Text == "0") { corvette.HeightNbBox = 1; } else { int heightChoice = int.Parse(this.secondShipHeightTxt.Text); if (heightChoice < 0) { heightChoice = -heightChoice; } corvette.HeightNbBox = heightChoice; } corvette.PositionShip = new int[corvette.WidthNbBox, corvette.HeightNbBox]; // number of ship int quantity = 0; if (this.secondShipQuantityTxt.Text == "" || this.secondShipQuantityTxt.Text == "0") { quantity = 1; } else { quantity = int.Parse(this.secondShipQuantityTxt.Text); if (quantity < 0) { quantity = -quantity; } } // quantity test Boolean quantityTestReturn = false; while (quantityTestReturn != true && quantity != 0) { quantityTestReturn = ListShip.quantityTest(quantity, corvette.WidthNbBox, corvette.HeightNbBox); if (quantityTestReturn == false) { quantity--; } } listReturn.Quantity = quantity; listReturn.QuantityAlive = quantity; listReturn.DisplayString = listReturn.QuantityAlive + " " + corvette.Name + " alive"; listReturn.ImageSource = new BitmapImage(new Uri("pack://application:,,,/NavalBattle;component/Resources/corvette.jpg")); for (int i = 0; i < quantity; i++) { corvetteList.Add(corvette); } listReturn.ShipsList = corvetteList; (this.Parent as MainWindow).PlacementPlayer.Add(listReturn); (this.Parent as MainWindow).PlacementVersus.Add(listReturn); (this.Parent as Window).Content = new PageThirdShipChoice(); }
private void fourthShipChoice_Click(object sender, RoutedEventArgs e) { ListShip listReturn = new ListShip(); List <Ship> aircraftCarrierList = new List <Ship>(); Ship aircraftCarrier = new Ship(); aircraftCarrier.Name = "Aircraft carrier"; aircraftCarrier.State = true; // dimensions of the ship if (this.fourthShipWidthTxt.Text == "" || this.fourthShipWidthTxt.Text == "0") { aircraftCarrier.WidthNbBox = 4; } else { int widthChoice = int.Parse(this.fourthShipWidthTxt.Text); if (widthChoice < 0) { widthChoice = -widthChoice; } aircraftCarrier.WidthNbBox = widthChoice; } if (this.fourthShipHeightTxt.Text == "" || this.fourthShipHeightTxt.Text == "0") { aircraftCarrier.HeightNbBox = 2; } else { int heightChoice = int.Parse(this.fourthShipHeightTxt.Text); if (heightChoice < 0) { heightChoice = -heightChoice; } aircraftCarrier.HeightNbBox = heightChoice; } aircraftCarrier.PositionShip = new int[aircraftCarrier.WidthNbBox, aircraftCarrier.HeightNbBox]; // number of ship int quantity = 0; if (this.fourthShipQuantityTxt.Text == "" || this.fourthShipQuantityTxt.Text == "0") { quantity = 1; } else { quantity = int.Parse(this.fourthShipQuantityTxt.Text); if (quantity < 0) { quantity = -quantity; } } // quantity test Boolean quantityTestReturn = false; while (quantityTestReturn != true && quantity != 0) { quantityTestReturn = ListShip.quantityTest(quantity, aircraftCarrier.WidthNbBox, aircraftCarrier.HeightNbBox); if (quantityTestReturn == false) { quantity--; } } listReturn.Quantity = quantity; listReturn.QuantityAlive = quantity; listReturn.DisplayString = listReturn.QuantityAlive + " " + aircraftCarrier.Name + " alive"; listReturn.ImageSource = new BitmapImage(new Uri("pack://application:,,,/NavalBattle;component/Resources/aircraft_carrier.jpg")); for (int i = 0; i < quantity; i++) { aircraftCarrierList.Add(aircraftCarrier); } listReturn.ShipsList = aircraftCarrierList; (this.Parent as MainWindow).PlacementPlayer.Add(listReturn); (this.Parent as MainWindow).PlacementVersus.Add(listReturn); PageGridGame game = new PageGridGame(); game.PlacementShipsPlayer = (this.Parent as MainWindow).PlacementPlayer; game.BindListviews(); // generate random configuration of ships game.placementAleatoire((this.Parent as MainWindow).PlacementPlayer); game.placementAleatoire((this.Parent as MainWindow).PlacementVersus); (this.Parent as Window).Content = game; }