public void CardSlotClick(object sender) { CardSlot c = (CardSlot)sender; if (CurrentCard != null && LineDifference(CurrentCard.line, c.line) == 1 && CurrentCard.CanMove) { if (CurrentCard.Parent == yourGrid) { CurrentCard.CanMove = false; CurrentCard.Status = Card.status.hasMove; ShipPosition origin = getShipPosition(CurrentCard.GetShip()); move.MoveList.Add(new Tuple <ShipPosition, Line>(origin, c.line)); c.Active = false; SetSlots(false); if (!readyToSend) { defendingShips.Remove(CurrentCard.GetShip()); } LastCard = null; CurrentCard = null; } } UpdateButtonNull(); }
private ShipPosition getShipPosition(Ship ship) { ShipPosition result = null; if (currentGameState.YourGameBoard.Board[Line.SHORT].Contains(ship)) { result = new ShipPosition(Line.SHORT, getIndexOfShip(ship, currentGameState.YourGameBoard.Board[Line.SHORT])); } else if (currentGameState.YourGameBoard.Board[Line.MEDIUM].Contains(ship)) { result = new ShipPosition(Line.MEDIUM, getIndexOfShip(ship, currentGameState.YourGameBoard.Board[Line.MEDIUM])); } else if (currentGameState.YourGameBoard.Board[Line.LONG].Contains(ship)) { result = new ShipPosition(Line.LONG, getIndexOfShip(ship, currentGameState.YourGameBoard.Board[Line.LONG])); } else if (currentGameState.EnemyGameBoard.Board[Line.SHORT].Contains(ship)) { result = new ShipPosition(Line.SHORT, getIndexOfShip(ship, currentGameState.EnemyGameBoard.Board[Line.SHORT])); } else if (currentGameState.EnemyGameBoard.Board[Line.MEDIUM].Contains(ship)) { result = new ShipPosition(Line.MEDIUM, getIndexOfShip(ship, currentGameState.EnemyGameBoard.Board[Line.MEDIUM])); } else if (currentGameState.EnemyGameBoard.Board[Line.LONG].Contains(ship)) { result = new ShipPosition(Line.LONG, getIndexOfShip(ship, currentGameState.EnemyGameBoard.Board[Line.LONG])); } else { result = null; } return(result); }
public bool Assign(CrewMember crew, ShipPosition shipPos, bool asNewMemeber = false) { if (!shipPos.isManned) { if (crew.shipPos) { crew.shipPos.isManned = false; } crew.shipPos = shipPos; crew.role = shipPos.getRole(); shipPos.isManned = true; if (asNewMemeber) { crewMembers.Add(crew); crew.ship = this; } crew.BeginPath(AStar.FindPath(crew.current, shipPos.tile, true)); return(true); } return(false); }
private Ship CreateShip(string input, ICoordinateBoundary cb) { var coord = cb.CoordinateFromInput(input); var pos = ShipPosition.Horizontal(coord, ShipSize.Destroyer); return(new Ship(pos)); }
/// <summary> /// Agrega una posicion para un barco determinado a la base de datos /// </summary> /// <param name="shipPosition">Objecto ShipPosition</param> public void Insert(ShipPosition shipPosition) { using (var dao = new ShipPositionDataAccess()) { dao.Insert(shipPosition); } }
private Ship AllocateShip(ShipSize shipSize, IEnumerable <Ship> battleships) { var eqComparer = new BattleCoordinateEqualityComparer(); var battleshipCoordinates = battleships.SelectMany(x => x.Coordinates).ToList(); var availableCoords = this.coordinates .Except(battleshipCoordinates, eqComparer) .ToList(); var availablePositions = availableCoords.SelectMany(c => new[] { ShipPosition.Vertical(c, shipSize), ShipPosition.Horizontal(c, shipSize) }); var validPositions = availablePositions.Where(x => x.IsValid).ToList(); if (!validPositions.Any()) { return(null); } var nonOverlappingPositions = validPositions .Where(x => !x.Coordinates.Intersect(battleshipCoordinates, eqComparer).Any()) .ToList(); var r = this.random.Next(nonOverlappingPositions.Count); var selectedPosition = nonOverlappingPositions[r]; return(new Ship(selectedPosition)); }
public void TestHasLost() { Setup(); int x = 0; bool ret = true; ShipPosition pos = new ShipPosition { X = 0, Y = 4, Length = 5, Align = ShipPosition.AlignmentType.Vertical }; player1.PlaceShipOnBoard(pos); player2.PlaceShipOnBoard(pos); for (int y = 4; y < 9; y++) { player2.Attack(x, y); } ret = player1.HasLost(); Assert.True(ret); }
public void Move_ReturnsValidPosition() { int i = 0; for (int x = 0; x < Constants.MAP_WIDTH; x++) { for (int y = 0; y < Constants.MAP_HEIGHT; y++) { for (int speed = 0; speed <= Constants.MAX_SHIP_SPEED; speed++) { for (int orientation = 0; orientation < 6; orientation++) { foreach (var moveCommand in ShipMoveCommands.all) { var shipPosition = new ShipPosition(new Coord(x, y), orientation, speed); var nextPositions = shipPosition.Apply(moveCommand); nextPositions.Count.Should().Be(2); var fastShipPosition = FastShipPosition.Create(shipPosition); for (int phase = 0; phase < nextPositions.Count; phase++) { if ((i++) % 99 == 0) { Console.Out.WriteLine($"shipPosition: {shipPosition}; moveCommand: {moveCommand}; phase: {phase}; nextPosition: {nextPositions[phase]}"); } var actual = FastShipPosition.ToShipPosition(FastShipPosition.GetPositionAtPhase(FastShipPosition.Move(fastShipPosition, moveCommand), phase)); actual.Should().Be(nextPositions[phase], $"shipPosition: {shipPosition}; moveCommand: {moveCommand}; phase: {phase}; nextPosition: {nextPositions[phase]}"); } } } } } } }
public void DistanceTo_ReturnsValidValue() { for (int xt = 0; xt < Constants.MAP_WIDTH; xt++) { for (int yt = 0; yt < Constants.MAP_HEIGHT; yt++) { for (int x = 0; x < Constants.MAP_WIDTH; x++) { for (int y = 0; y < Constants.MAP_HEIGHT; y++) { for (int speed = 0; speed <= Constants.MAX_SHIP_SPEED; speed++) { for (int orientation = 0; orientation < 6; orientation++) { var shipPosition = new ShipPosition(new Coord(x, y), orientation, speed); var target = new Coord(xt, yt); var fastShipPosition = FastShipPosition.Create(shipPosition); FastShipPosition.DistanceTo(fastShipPosition, FastCoord.Create(target)).Should().Be(shipPosition.DistanceTo(target), $"shipPosition: {shipPosition}; target: {target}"); } } } } } } }
protected new void Start() { base.Start(); int otherPeople = Random.Range(minNumOfPeople, maxNumOfPeople + 1); for (int i = 0; i < otherPeople; i++) { ShipPosition sp = otherShip.GetVacantPositionByPriority(); CrewMember c = CreateCrewMember(sp.tile); c.ship = otherShip; otherShip.Assign(c, sp, true); } int food = Random.Range(foodMin, foodMax + 1); int wood = Random.Range(woodMin, woodMax + 1); int gold = Random.Range(goldMin, goldMax + 1); otherShip.AddInventory(food, wood, gold); if (PlayerHasRangeAdvantage()) { message.text += "The ship has not yet seen us.\nWhat do we wish to do?"; shipSeesFirstOptions.SetActive(false); playerSeesFirstOptions.SetActive(true); } else { ShipDecision decision = GenerateShipDecision(false); switch (decision) { case ShipDecision.FLEE: otherParleyOptions.SetActive(false); message.text += "The ship is attempting to flee us.\nWe are "; if (!PlayerHasFasterShip()) { engageOptions.SetActive(false); message.text += "not "; } message.text += "faster than them."; break; case ShipDecision.PARLEY: message.text += "The ship wishes to parley with us."; break; case ShipDecision.ENGAGE: message.text += "The ship is engaging us."; continueMessageButton.SetActive(true); shipSeesFirstOptions.SetActive(false); break; } } battleManager.Init(playerShip.GetBoardingTile(), otherShip.GetBoardingTile()); }
public void AssignTo(ShipPosition pos) { if (!selected || !selected.isPlayerCrew || selected.currentAction == CrewMember.Action.ATTACKING || !zoneEvent.canChangeCrewPositions) { return; } //TODO: clean this shit up if (pos.isManned) { CrewMember memToSwap = null; for (int i = 0; i < ship.crewMembers.Count; i++) { if (ship.crewMembers[i].shipPos == pos) { memToSwap = ship.crewMembers[i]; break; } } ship.Unassign(memToSwap); ShipPosition temp = selected.shipPos; ship.Assign(selected, pos); ship.Assign(memToSwap, temp, true); } else { ship.Assign(selected, pos); } selected = null; DisplayStats(); }
public void onClick() { GameObject ship = GameObject.Find("SpaceShip"); ShipPosition shipPositionScript = ship.GetComponent <ShipPosition>(); shipPositionScript.setPlanet(this.gameObject); }
public ShipType shipType; // Тип корабля #endregion Fields #region Constructors /// <summary> /// Создание нового корабля /// </summary> /// <param name="owner">Игрок-владелец корабля</param> /// <param name="shipType">Тип корабля</param> /// <param name="shipPosition">Позиция корабля</param> /// <param name="shipCells">Список ячеек, которые занимает корабль</param> public Ship(Player owner, ShipType shipType, ShipPosition shipPosition, List<Cell> shipCells) { this.owner = owner; this.shipType = shipType; this.shipPosition = shipPosition; this.shipCells = shipCells; }
public void PlaceShipCoveringWithIntersectingShips() { Setup(); ShipPosition pos = new ShipPosition { X = 5, Y = 2, Length = 4, Align = ShipPosition.AlignmentType.Horizontal }; bool ret = _sut.PlaceShipOnBoard(pos); Assert.True(ret); pos = new ShipPosition { X = 8, Y = 0, Length = 4, Align = ShipPosition.AlignmentType.Vertical }; ret = _sut.PlaceShipOnBoard(pos); // Second Ship intersects, so return false Assert.False(ret); }
public void TestGridManager_SinkShip() { var destroyer = new Destroyer(3); var gridManager = new GridManager(); gridManager.Init(); gridManager.PlaceShip(destroyer, (int)GridRows.A, 0, ShipPlacementMode.Vertically); Assert.True(destroyer.IsPlaced); for (int i = 0; i < GameSettings.GridSize; i++) { var row = (GridRows)i; var shoot = row + "1"; var position = new ShipPosition(shoot); if (position.Row != GridRows.Undefined && position.Column != -1) { var place = gridManager.GetPlace(position); place.ShootShip(); if (place.IsThereShip) { Assert.Equal(place.State, GridStates.Hit); } else { Assert.Equal(place.State, GridStates.Miss); } } } Assert.True(destroyer.IsSunk); }
public void UninitializedShipObject() { Setup(); ShipPosition pos = new ShipPosition(); bool ret = _sut.PlaceShipOnBoard(pos); Assert.False(ret); }
public void NullShipObject() { Setup(); ShipPosition pos = null; bool ret = _sut.PlaceShipOnBoard(pos); Assert.False(ret); }
public Ship(Layout layout) { Layout = layout; Position = new ShipPosition(); Radar = new ShipRadar(); }
public void TestGame_ConvertShootToRowAndColumn() { var shoot = "C9"; var position = new ShipPosition(shoot); Assert.Equal(position.Row, GridRows.C); Assert.Equal(position.Column, 8); }
public ShipPosition[] ConvertShipPositionsForEngine() { ShipPosition[] array = new ShipPosition[this.Ships.Count]; for (int i = 0; i < array.Length; i++) { array[i] = new ShipPosition(this.Ships[i].ShipType, new Position((byte)(this.Ships[i].Position.X + 1), (byte)(this.Ships[i].Position.Y + 1)), this.Ships[i].Orientation); } return(array); }
public string[] GetLatLongOfPoint(ShipPosition pos) { var point = SqlGeography.STPointFromWKB(new System.Data.SqlTypes.SqlBytes(pos.Position.ToArray()), 4326); var latlong = new string[2]; latlong[0] = point.Lat.ToString(); latlong[1] = point.Long.ToString(); return(latlong); }
public AIShip( ) { Positions = new ShipPosition(); Positions.Solar = new Vector2((int)Random.Range(-300, 300), (int)Random.Range(-300, 300)); Positions.OnReachedTargetPosition += NeedNewTargetPosition; NeedNewTargetPosition(); }
public Ship SpawnShip(ShipType type) { Ship newShip = new Ship(type); _Ships.Add(newShip); ShipPosition newPos = new ShipPosition(newShip, new Vector2(0, 0)); _ShipPositions.Add(newPos); return(newShip); }
public void UpdatePositions() { foreach (Ship ship in _Ships) { ShipPosition oldPos = _ShipPositions.Find(item => item.Key == ship); ShipPosition newPos = new ShipPosition(oldPos.Key, oldPos.Value + oldPos.Key.GetVelocity()); _ShipPositions.Remove(oldPos); _ShipPositions.Add(newPos); } }
public void ShouldCreateInvalidHorizontalPosition(string value, ShipSize size) { var cb = new TestCoordinateBoundary(10, 10); var coord = cb.CoordinateFromInput(value); var result = ShipPosition.Horizontal(coord, size); Assert.False(result.IsValid); Assert.Null(result.Coordinates); }
public void DistanceTo_StrangeCase_ReturnsValidValue() { //coord: 23, 5, orientation: 0, speed: 0 23, 5 var shipPosition = new ShipPosition(new Coord(23, 5), 0, 0); var target = new Coord(20, 5); var fastShipPosition = FastShipPosition.Create(shipPosition); var fastTarget = FastCoord.Create(target); FastShipPosition.DistanceTo(fastShipPosition, fastTarget).Should().Be(1000); }
public ShipPosition[] ConvertShipPositionsForEngine() { // internally, boarder tiles are ignored - convert to format used by game engine ShipPosition[] s = new ShipPosition[Ships.Count]; for (int i = 0; i < s.Length; i++) { s[i] = new ShipPosition(Ships[i].ShipType, new Position((byte)(Ships[i].Position.X + 1), (byte)(Ships[i].Position.Y + 1)), Ships[i].Orientation); } return(s); }
/// <summary> /// Constructeur d'un navire. /// </summary> /// <param name="shipPosition">Position et type du navire.</param> public Ship(ShipPosition shipPosition) { Orientation = shipPosition.Orientation; ClassOfShipInfo = shipPosition.ClassOfShipInfo; //TODO: Revoir la pertinence de cette classe et de son usage. Lenght = shipPosition.ClassOfShipInfo.Lenght; TopLeft = shipPosition.Coordonate; BottomRight = shipPosition.Coordonate + shipPosition.Size - new Size(1, 1); // -1 en X et Y car on TopLeft "consomme" une case Class = shipPosition.Class; HealthPoint = Lenght; }
public void ShouldCreateHorizontalCoordinates(string value, ShipSize size) { var cb = new TestCoordinateBoundary(10, 10); var coord = cb.CoordinateFromInput(value); var result = ShipPosition.Horizontal(coord, size); Assert.True(result.IsValid); Assert.NotNull(result.Coordinates); Assert.True(result.Coordinates.Count() == (int)size); }
public void DefineShipLocation_PassTrue_ReturnsBool() { var shipOrientation = true; var verticalStartIndex = ShipPosition.VerticalStarterIndex((bool)shipOrientation); var horizontalStartIndex = ShipPosition.HorizontalStarterIndex((bool)shipOrientation); var _grid2 = ShipPosition.DefineShipLocation(_grid, shipOrientation, verticalStartIndex, horizontalStartIndex); bool[][] expectedType = new bool[10][]; Assert.IsType(expectedType.GetType(), _grid2); }
public void IsShipVertical_TrueOrFalse() { var ship = (bool)ShipPosition.IsShipVertical(); if (ship) { Assert.True(ship); } else { Assert.True(!ship); } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); if (version > 1) m_Cleansliness = reader.ReadInt(); else { m_Cleaned = true; m_Cleansliness = 0; } if (version > 0) { if (reader.ReadBool()) { string name = reader.ReadString(); m_LoadedAmmo = ScriptCompiler.FindTypeByName(name); } } m_Cleaned = reader.ReadBool(); m_Charged = reader.ReadBool(); m_Primed = reader.ReadBool(); m_Galleon = reader.ReadItem() as BaseGalleon; m_Hits = reader.ReadInt(); m_AmmoType = (AmmoType)reader.ReadInt(); m_Position = (ShipPosition)reader.ReadInt(); if (m_LoadedAmmo == null && m_AmmoType != AmmoType.Empty) m_AmmoType = AmmoType.Empty; InvalidateDamageState(); }
protected bool Equals(ShipPosition other) { return X == other.X && Y == other.Y && ShipDirection == other.ShipDirection; }