private void Update() { if (Input.GetKeyDown(KeyCode.Mouse0)) { director.ConstructShip(battleShipBuilder); _ship = battleShipBuilder.GetResult(); } else if (Input.GetKeyDown(KeyCode.Mouse1)) { _ship.Shoot(); _ship.Scan(); _ship.Move(2f); } else if (Input.GetKeyDown(KeyCode.Mouse2)) { director.ConstructShip(reconShipBuilder); _ship = reconShipBuilder.GetResult(); } }
/// <summary> /// Создание корабля и его рандомное местоположение /// </summary> /// <param name="shipType"></param> /// <returns></returns> private Ship CreateShip(ShipType shipType) { var deckCount = (int)shipType; var rand = new Random(); var builder = new ShipBuilder(); builder.BuildShipType(shipType); var array = new int[2, deckCount]; var x = rand.Next(deckCount - 1, FIELD_SIZE - deckCount + 1); var y = rand.Next(deckCount - 1, FIELD_SIZE - deckCount + 1); var direction = (Direction)rand.Next(0, 3); for (var i = 0; i < deckCount; i++) { array[0, i] = x; array[1, i] = y; direction.Move(ref x, ref y); } builder.BuildPosition(array); return(builder.GetResult() as Ship); }