public void CreateShip(ShipType shipType) { Ship ship = new Ship(shipType); int headX = random.Next(0, 10); int headY = random.Next(0, 10); int test = random.Next(0, 2); Orientation orientation = (Orientation)test; if (CheckPlacement(orientation, shipType, headX, headY)) { HullComponent hullComponent; for (int i = 0; i < (int)shipType; i++) { switch (orientation) { case Orientation.HORIZONAL: hullComponent = new HullComponent(headY, headX++, ship); ship.AddHullComponent(hullComponent); PlayerGrid.AddGridSquare(hullComponent); break; case Orientation.VERTICAL: hullComponent = new HullComponent(headY++, headX, ship); ship.AddHullComponent(hullComponent); PlayerGrid.AddGridSquare(hullComponent); break; } } } else { CreateShip(shipType); return; } ships.Add(ship); }
public void AddHullComponent(HullComponent hullComponent) { hullComponent.HitEvent += HullComponent_HitEvent; Hull.Add(hullComponent); }