public void SetRandomShips(GameFieldElement gameField, StatedButton.State state) { Ship thisShip; bool isVertical; Point point; for (int j = 3; j >= 0; j--) { for (int i = 0; i < 4 - j; i++) { isVertical = rnd.Next(0, 2) == 1; thisShip = shipToSet.GetShip(j + 1); point = new Point(rnd.Next(0, 10), rnd.Next(0, 10)); while (SetShipState(isVertical, j + 1, point, gameField.PlayerField)) { point = new Point(rnd.Next(0, 10), rnd.Next(0, 10)); } SetShipOnField(thisShip, isVertical, gameField, state); } } }
public void SetShipOnField(Ship ship, bool isVertical, GameFieldElement gameField, StatedButton.State state) { if (ship != null) { int index = 0; foreach (StatedButton btn in buttons) { btn.ButtonState = state; btn.LinkedShip = ship; ship.Position[index++] = btn; } ship.IsVertical = isVertical; ChangeNearState(ship, gameField.PlayerField, false); buttons.Clear(); } }