public IStarship CreateShip(StarshipType type, string name, StarSystem location) { IStarship ship; switch (type) { case StarshipType.Frigate: ship = new Frigate(name, location); break; case StarshipType.Cruiser: ship = new Cruiser(name, location); break; case StarshipType.Dreadnought: ship = new Dreadnought(name, location); break; default: throw new NotSupportedException("Starship type not supported."); } Console.WriteLine(Messages.CreatedShip, ship.GetType().Name, ship.Name); return(ship); }
public void EmptyNameTest() { var cruiser = new Cruiser(null, true, 220, 200, "A big one", "A tender line", "I suppose a picture is in order"); Assert.Throws <InvalidAttributeException>(() => CruiserValidator.Validate(cruiser)); var cruiser2 = new Cruiser("The great seeker of wonder", true, 220, 200, "A big one", "A tender line", "I suppose a picture is in order"); }
public virtual void AssignReferences(ShipData data) { parentBoard = (data.ownedByAttacker ? Battle.main.attacker : Battle.main.defender).board; if (data.tiles != null) { if (data.tiles.Length > 0) { tiles = new Tile[data.tiles.GetLength(0)]; for (int i = 0; i < data.tiles.GetLength(0); i++) { tiles[i] = parentBoard.tiles[data.tiles[i, 0], data.tiles[i, 1]]; } } } Vector3 directional = tiles[0].transform.position - tiles[tiles.Length - 1].transform.position; placementInfo.boardPosition = (tiles[0].transform.position + tiles[tiles.Length - 1].transform.position) / 2.0f; placementInfo.boardRotation = Quaternion.Euler(0, directional.z != 0 ? 0 : 90, 0); if (data.concealedBy >= 0) { concealedBy = (Cruiser)parentBoard.ships[data.concealedBy]; } transform.SetParent(parentBoard.transform); gameObject.SetActive(false); }
public void ReturnTrue_ComparingWithSameDirectionsAndLengthAbove1() { var ship1 = new Cruiser(x: 1, y: 2, direction: Direction.Horizontal); var ship2 = new Cruiser(x: 1, y: 2, direction: Direction.Horizontal); Assert.AreEqual(ship1, ship2); }
public async Task <CruiserResponse> UpdateCruiserAsync(int id, Cruiser cruiser) { try { var dbCruiser = await _cruiserDao.FindCruiserByIdAsync(id); if (dbCruiser == null) { return(new CruiserResponse("Cruiser not found")); } dbCruiser.Name = cruiser.Name; dbCruiser.Line = cruiser.Line; dbCruiser.Model = cruiser.Model; dbCruiser.Status = cruiser.Status; dbCruiser.LoadingShipCap = cruiser.LoadingShipCap; dbCruiser.Picture = cruiser.Picture; dbCruiser.Capacity = cruiser.Capacity; _cruiserDao.UpdateCruiser(dbCruiser); await _unitOfWork.CompleteAsync(); return(new CruiserResponse(dbCruiser)); } catch (Exception e) { return(new CruiserResponse($"An error occurred when updating the Cruiser: {e.Message}")); } }
public static void ConsiderConcealmentOfShipsInOrder(this Cruiser ship, int[] order, ref float[][,] maps) { Board board = ship.parentBoard; float baseConcealChance = 1.00f / board.ships.Sum(x => x.concealmentAIValue); float[,] cruiser_map = maps[ship.index]; for (int concealee_order = 0; concealee_order < order.Length; concealee_order++) { int concealee_index = order[concealee_order]; Ship concealee = board.ships[concealee_index]; float[,] concealee_map = maps[concealee_index]; if (concealee != ship && UnityEngine.Random.Range(0.00f, 1.00f) < baseConcealChance * concealee.concealmentAIValue) { Vector2Int concealee_map_max = concealee_map.Max(); float concealee_map_average = concealee_map.Average(); cruiser_map = cruiser_map.AddHeat(concealee_map_max, dist => Mathf.Pow(0.85f, dist) * concealee_map_average); cruiser_map = cruiser_map.AddHeat(concealee_map_max, dist => dist < 2 ? -concealee_map_average : 0); ship.placementPriority = int.MaxValue - concealee_order * 2; concealee.placementPriority = int.MaxValue - 1 - concealee_order * 2; break; } if (concealee_order == order.Length - 1) { cruiser_map = ship.GetPreferredMap(); } } maps[ship.index] = cruiser_map; }
public void ReturnFalse_ComparingWithDifferentDirectionsAndLengthAbove1() { var ship1 = new Cruiser(x: 1, y: 2, directionInShip: Direction.Horizontal); var ship2 = new Cruiser(x: 1, y: 2, directionInShip: Direction.Vertical); Assert.AreNotEqual(ship1, ship2); }
/// <summary> /// Metodo para validar todos los campos de un crucero /// </summary> /// <param name="layover">Objeto que contiene toda la informacion del crucero a validar</param> public static void Validate(Cruiser cruiser) { if (string.IsNullOrEmpty(cruiser.Name)) { throw new InvalidAttributeException("El nombre es requerido"); } if (cruiser.Capacity <= 0) { throw new InvalidAttributeException("La capacidad tiene que ser mayor a 0"); } if (cruiser.LoadingShipCap <= 0) { throw new InvalidAttributeException("La capacidad de carga debe ser mayor a 0"); } if (string.IsNullOrEmpty(cruiser.Model)) { throw new InvalidAttributeException("El modelo es requerido"); } if (string.IsNullOrEmpty(cruiser.Line)) { throw new InvalidAttributeException("La Linea del crucero es requerida"); } if (string.IsNullOrEmpty(cruiser.Picture)) { throw new InvalidAttributeException("La imagen es requerida"); } }
public void ReturnFalse_ComparingWithDifferentLength() { var ship1 = new PatrolBoat(x: 1, y: 2); var ship2 = new Cruiser(x: 1, y: 2); Assert.AreNotEqual(ship1, ship2); }
public void ReturnFalse_ComparingWithDifferentDirectionsAndLengthAbove1() { var ship1 = new Cruiser(x: 1, y: 2, direction: Direction.Horizontal); var ship2 = new Cruiser(x: 1, y: 2, direction: Direction.Vertical); Assert.AreNotEqual(ship1, ship2); }
/// <summary> /// Метод возвращает корабль в зависимости от перданного типа корaбля /// </summary> /// <param name="shipType"></param> /// <returns>Корабль полученый из строки</returns> private ShipBase CreateShipFromString(string shipType) { ShipBase shipBase = null; switch (shipType) { case "b": shipBase = new BattleShip(); // линкор break; case "c": shipBase = new Carrier(); // эсминец break; case "cr": shipBase = new Cruiser(); // крейсер break; case "s": shipBase = new Submarine(); // подлодка break; default: throw new Exception("Нет так кого корабля!"); } return(shipBase); }
void button_Click(object sender, EventArgs e) { Button b = (Button)sender; Cruiser cruiser = (Cruiser)b.Tag; ViewModel.HandleCruiserSelected(cruiser); }
private void _removeItemBTN_Click(object sender, EventArgs e) { Panel p = ((Panel)((Button)sender).Parent); Cruiser cruiser = (Cruiser)p.Tag; Settings.RemoveCruiser(cruiser); this.UpdateCruiserList(); }
public void Execute() { DAOFactory daoFactory = DAOFactory.GetFactory(DAOFactory.Type.Postgres); CruiserMapper cruiserMapper = MapperFactory.CreateCruiserMapper(); Cruiser cruiser = cruiserMapper.CreateEntity(_cruiserDto); CommandFactory.CreateGetCruiserValidatorCommand(cruiser).Execute(); _cruiserDto = cruiserMapper.CreateDTO(daoFactory.GetCruiserDAO().UpdateCruiser(cruiser)); }
public void GetShip_From_ShipFactory_Of_Type_Cruiser_Should_Return_new_Cruiser() { ShipFactory factory = new CruiserFactory(); Cruiser newShip = new Cruiser(); var res = factory.GetShip(); Assert.True(res.Name == newShip.Name && res.Size == newShip.Size && res.ShipType == newShip.ShipType); }
public void Execute() { DAOFactory daoFactory = DAOFactory.GetFactory(DAOFactory.Type.Postgres); PostgresCruiserDAO cruiserDao = (PostgresCruiserDAO)daoFactory.GetCruiserDAO(); CruiserMapper cruiserMapper = MapperFactory.CreateCruiserMapper(); Cruiser cruiser = (Cruiser)cruiserMapper.CreateEntity(_cruiserDTO); _cruiserDTO.Id = cruiserDao.AddCruiser(cruiser); }
public void CanCreateCruiserHorizontalCoordinates() { var ship = new Cruiser(new BoardCoordinate("A1"), new BoardCoordinate("C1")); Assert.AreEqual(ship.Coordinates.Length, 3, "Incorrect length"); Assert.AreEqual(ship.Coordinates[0].ToString(), "A1", "Incorrect Coordinates"); Assert.AreEqual(ship.Coordinates[1].ToString(), "B1", "Incorrect Coordinates"); Assert.AreEqual(ship.Coordinates[2].ToString(), "C1", "Incorrect Coordinates"); }
/// <summary> /// Metodo para añadir un Crucero. /// </summary> /// <param name="cruiser">Datos a ser guardados en tipo crucero</param> /// <returns>ID del registro del crucero en la base de datos</returns> /// <exception cref="InvalidAttributeException">Algun atributo tenia un valor invalido</exception> /// <exception cref="DatabaseException"> /// Lanzada si ocurre un fallo al ejecutar la funcion en la bse de /// datos /// </exception> public static int AddCruiser(Cruiser cruiser) { cruiser.Validate(); var table = PgConnection.Instance.ExecuteFunction( "AddShip(@name,@capacity,@loadingcap,@model,@line,@picture)", cruiser.Name, cruiser.Capacity, cruiser.LoadingShipCap, cruiser.Model, cruiser.Line, cruiser.Picture); var id = Convert.ToInt32(table.Rows[0][0]); return(id); }
void Function_Click_Raycast() // FUNCTION WITH CLICK-RAYCAST on Unit and MOVE ship on click position { if (Input.GetMouseButtonDown(0)) { Ray ray = Cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 300.0f)) { if (hit.collider.tag == "Water_Plane") { if (UnitSelected) { //plShip.transform.position = hit.point; //plShip.destination = hit.point; //plShip.GetComponent<Ship>().destination = hit.point; if (hit.collider.name == "Pl_Hitbox_fletcher") { print("dd"); } if (hit.collider.name == "Pl_Lexington_hitbox") { print("lx"); } if (plShip.GetComponent <Ship>()) { Ship shipscript = plShip.GetComponent <Ship>(); shipscript.isMoving = true; shipscript.destination = hit.point; UnitSelected = false; } if (plShip.GetComponent <Carrier>()) { Carrier shipscript = plShip.GetComponent <Carrier>(); shipscript.isMoving = true; shipscript.destination = hit.point; UnitSelected = false; } if (plShip.GetComponent <Cruiser>()) { Cruiser shipscript = plShip.GetComponent <Cruiser>(); shipscript.isMoving = true; shipscript.destination = hit.point; UnitSelected = false; } } } if (hit.collider.tag == "Player_Ship") { UnitSelected = true; plShip = hit.collider.gameObject; } } } }
public void Setup() { _cruiser = new Cruiser("The great seeker of wonder", true, 220, 200, "A big one", "A tender line", "I suppose a picture is in order"); _cruiserMapper = MapperFactory.CreateCruiserMapper(); _cruiserDTOList = new List <CruiserDTO>(); _cruiserList = new List <Cruiser>(); _layover = new Layover(0, "02/12/2019", "05/01/2020", 250, 1, 2); _layoverMapper = MapperFactory.CreateLayoverMapper(); _layoverDTOList = new List <LayoverDTO>(); _layoverList = new List <Layover>(); }
public void UpdateCruiserTest() { var id = _cruiserDao.AddCruiser(_cruiser); _addedCruiserList.Add(id); var toUpdateCruiser = new Cruiser(id, "Seeker of wonder2", true, 500, 250, "A bigger one", "A fine line", "I suppose a picture is in order... soon"); var updatedCruiser = _cruiserDao.UpdateCruiser(toUpdateCruiser); var actualCruiser = _cruiserDao.GetCruiser(id); Assert.AreEqual(updatedCruiser.Name, actualCruiser.Name); }
/// <summary> /// Executes the command. /// </summary> /// <param name="parameter">Possible specified command arguments.</param> /// <exception cref="ArgumentOutOfRangeException">If the ShipType is undefined.</exception> public override void Execute(object parameter) { if (this.battleFieldViewModel.ShipToPlace.ShipType == ShipType.Undefined) { return; } Position position = (Position)parameter; Ship ship; switch (this.battleFieldViewModel.ShipToPlace.ShipType) { case ShipType.Battleship: ship = new Battleship(position); break; case ShipType.Carrier: ship = new Carrier(position); break; case ShipType.Cruiser: ship = new Cruiser(position); break; case ShipType.Destroyer: ship = new Destroyer(position); break; case ShipType.Sub: ship = new Sub(position); break; default: throw new ArgumentOutOfRangeException(nameof(this.battleFieldViewModel.ShipToPlace.ShipType)); } ship.Orientation = this.battleFieldViewModel.ShipToPlace.ShipOrientation; this.battleFieldViewModel.ShipToPlace.Ship = ship; this.battleFieldAreaViewModel.ClearHighlighted(); bool validPosition = this.battleFieldAreaViewModel.HighlightSquares(ship); if (!validPosition) { this.battleFieldViewModel.ShipToPlace.ValidPosition = false; } else { this.battleFieldViewModel.ShipToPlace.ValidPosition = true; } }
public virtual void Damage(int damageTaken) { health -= damageTaken; if (concealedBy) { concealedBy.concealing = null; concealedBy = null; } if (health <= 0) { Destroy(); } }
public async Task <CruiserResponse> SaveCruiserAsync(Cruiser cruiser) { try { await _cruiserDao.SaveCrusierAsync(cruiser); await _unitOfWork.CompleteAsync(); return(new CruiserResponse(cruiser)); } catch (Exception e) { return(new CruiserResponse($"An error occurred when saving the Cruiser: {e.Message}")); } }
private void AlignmentThrust(ShipControlCommons shipControl, Vector3D offset, Cruiser cruiser) { var velocity = shipControl.LinearVelocity; if (velocity != null) { // Project offset against reference direction var referenceDirection = GetReferenceVector(shipControl, cruiser.LocalForward); var referenceDistance = Vector3D.Dot(offset, referenceDirection); var targetSpeed = Math.Min(Math.Abs(referenceDistance) * VTVLHELPER_APPROACH_GAIN, VTVLHELPER_MAXIMUM_SPEED); targetSpeed *= Math.Sign(referenceDistance); cruiser.Cruise(shipControl, targetSpeed, (Vector3D)velocity); } }
public Ship Parse(string notation) { if (notation == null) throw new ArgumentException(); var pattern = @"^([A-J])(10|[1-9])(x[1-4])?(-|\|)?$"; var regEx = new Regex(pattern); var match = regEx.Match(notation); if (!match.Success) throw new NotAShipException(); uint x = (uint)(match.Groups[1].Value[0] - 'A' + 1); uint y = uint.Parse(match.Groups[2].Value); var direction = Direction.Horizontal; switch (match.Groups[4].Value) { case "-": direction = Direction.Horizontal; break; case "|": direction = Direction.Vertical; break; } Ship result = null; switch (match.Groups[3].Value) { case "": case "x1": result = new PatrolBoat(x, y, direction); break; case "x2": result = new Cruiser(x, y, direction); break; case "x3": result = new Submarine(x, y, direction); break; case "x4": result = new AircraftCarrier(x, y, direction); break; } return result; }
private void AlignmentThrust(ShipControlCommons shipControl, Vector3D offset, Cruiser cruiser) { var velocity = shipControl.LinearVelocity; if (velocity != null) { // Project offset against reference direction var referenceDirection = GetReferenceVector(shipControl, cruiser.LocalForward); var referenceDistance = Vector3D.Dot(offset, referenceDirection); var targetSpeed = Math.Min(Math.Abs(referenceDistance) * VTVLHELPER_APPROACH_GAIN, VTVLHELPER_MAXIMUM_SPEED); targetSpeed *= Math.Sign(referenceDistance); Func <IMyThrust, bool> AlignThrusterCondition = VTVLHELPER_USE_BRAKING_THRUSTER_SPEC_FOR_ALIGN ? ThrusterCondition : null; cruiser.Cruise(shipControl, targetSpeed, (Vector3D)velocity, condition: AlignThrusterCondition); } }
private void SpawnCruiserAtRandomPos(bool showArrivalMessage = true) { cruisers.RemoveAll(x => x == null); Vector2 pos = MKUtility.GetRandomPositionInBounds(arenaBounds.bounds, gameData.spawningPadding); Cruiser cruiser = Instantiate(gameData.cruiserPrefab, pos, Quaternion.identity); cruisers.Add(cruiser); if (showArrivalMessage) { UIManager.PromptIfEmpty(2f, MK.UI.TransitionPreset.ScaleIn, "An enemy cruiser has arrived!"); AudioManager.PlayOneShot(AudioData.cruiserMessageAudio, AudioData.cruiserMessageVolume); } DestroyWorldObjectsAroundPos(pos, gameData.cruiserClearRadius); }
private void MakeCruiserListItem(Cruiser cruiser, Control parent) { Panel panel = new Panel(); panel.SuspendLayout(); Label lbl = new Label(); Button btn = new Button(); panel.BackColor = System.Drawing.Color.Tan; panel.Controls.Add(lbl); panel.Controls.Add(btn); panel.Size = new System.Drawing.Size(240, 25); panel.Dock = System.Windows.Forms.DockStyle.Top; //panel.Location = new System.Drawing.Point(0, 0); //panel.Name = "panel3"; btn.BackColor = System.Drawing.Color.Crimson; btn.Dock = System.Windows.Forms.DockStyle.Right; //this.button1.Location = new System.Drawing.Point(213, 0); //this.button1.Name = "button1"; btn.Size = new System.Drawing.Size(27, 25); btn.TabIndex = 1; btn.Text = "X"; btn.Click += new System.EventHandler(this._removeItemBTN_Click); lbl.Location = new System.Drawing.Point(12, 3); lbl.Name = "label2"; lbl.Size = new System.Drawing.Size(48, 20); lbl.Text = cruiser.Initials; panel.Tag = cruiser; panel.Parent = parent; #if NetCF FMSC.Controls.DpiHelper.AdjustControl(panel); FMSC.Controls.DpiHelper.AdjustControl(lbl); FMSC.Controls.DpiHelper.AdjustControl(btn); panel.ResumeLayout(false); #else panel.ResumeLayout(true); #endif }
public IStarship CreateShip(StarshipType type, string name, StarSystem location) { switch (type) { case StarshipType.Frigate: Frigate frigate = new Frigate(name, location); return(frigate); case StarshipType.Cruiser: Cruiser crusier = new Cruiser(name, location); return(crusier); case StarshipType.Dreadnought: Dreadnought dreadnought = new Dreadnought(name, location); return(dreadnought); default: throw new NotSupportedException("Starship type not supported."); } }
private void Thrust(ShipControlCommons shipControl, double distance, Vector3D velocity, Cruiser cruiser) { if (Math.Abs(distance) < 1.0) { // Close enough var thrustControl = shipControl.ThrustControl; thrustControl.Enable(cruiser.LocalForward, true); thrustControl.Enable(cruiser.LocalBackward, true); } else { var targetSpeed = Math.Min(Math.Abs(distance) / AUTOPILOT_TTT_BUFFER, AutopilotSpeed); targetSpeed = Math.Max(targetSpeed, AUTOPILOT_MIN_SPEED); // Avoid Zeno's paradox... targetSpeed *= Math.Sign(distance); cruiser.Cruise(shipControl, targetSpeed, velocity); } }
/// <summary> /// Metodo para obtener todos los cruveros guardados. /// </summary> /// <returns>Lista de cruceros</returns> /// <exception cref="DatabaseException"> /// Lanzada si ocurre un fallo al ejecutar la funcion en la base de /// datos /// </exception> public static List <Cruiser> GetCruisers() { var cruiserList = new List <Cruiser>(); var table = PgConnection.Instance.ExecuteFunction("GetALLShip()"); for (int i = 0; i < table.Rows.Count; i++) { var id = Convert.ToInt32(table.Rows[i][0]); var name = table.Rows[i][1].ToString(); var status = Convert.ToBoolean(table.Rows[i][2]); var capacity = Convert.ToInt32(table.Rows[i][3]); var loadingShipCap = Convert.ToInt32(table.Rows[i][4]); var model = table.Rows[i][5].ToString(); var line = table.Rows[i][6].ToString(); var picture = table.Rows[i][7].ToString(); Cruiser cruiser = new Cruiser(id, name, status, capacity, loadingShipCap, model, line, picture); cruiserList.Add(cruiser); } return(cruiserList); }
/// <summary> /// Metodo para obtener objeto Crucero correspondiente a los datos guardados para el ID recibido. /// </summary> /// <param name="shipId">ID del crucero a obtener</param> /// <returns>Objeto Crucero correspondiente al ID recibido</returns> /// <exception cref="CruiserNotFoundException">Lanzada si no existe un Crucero para el ID recibido</exception> /// <exception cref="DatabaseException"> /// Lanzada si ocurre un fallo al ejecutar la funcion en la bse de /// datos /// </exception> public static Cruiser GetCruiser(int shipId) { var table = PgConnection.Instance.ExecuteFunction("GetShip(@ship_id)", shipId); if (table.Rows.Count == 0) { throw new CruiserNotFoundException("Crucero no encontrado"); } var id = Convert.ToInt32(table.Rows[0][0]); var name = table.Rows[0][1].ToString(); var status = Convert.ToBoolean(table.Rows[0][2]); var capacity = Convert.ToInt32(table.Rows[0][3]); var loadingShipCap = Convert.ToInt32(table.Rows[0][4]); var model = table.Rows[0][5].ToString(); var line = table.Rows[0][6].ToString(); var picture = table.Rows[0][7].ToString(); var cruiser = new Cruiser(id, name, status, capacity, loadingShipCap, model, line, picture); return(cruiser); }