コード例 #1
0
        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();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
    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);
    }
コード例 #4
0
ファイル: FleetTests.cs プロジェクト: sgnatonski/battleships
        private Ship CreateShip(string input, ICoordinateBoundary cb)
        {
            var coord = cb.CoordinateFromInput(input);
            var pos   = ShipPosition.Horizontal(coord, ShipSize.Destroyer);

            return(new Ship(pos));
        }
コード例 #5
0
ファイル: ShipPositionManager.cs プロジェクト: dargonar/LRIT
 /// <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);
     }
 }
コード例 #6
0
        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));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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]}");
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #9
0
 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}");
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: ShipEvent.cs プロジェクト: ZacOlsen/Pirate-Game
    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());
    }
コード例 #11
0
    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();
    }
コード例 #12
0
ファイル: PlanetBehaviour.cs プロジェクト: gualt1995/EVIJV
    public void onClick()
    {
        GameObject   ship = GameObject.Find("SpaceShip");
        ShipPosition shipPositionScript = ship.GetComponent <ShipPosition>();

        shipPositionScript.setPlanet(this.gameObject);
    }
コード例 #13
0
ファイル: Ship.cs プロジェクト: dbx386/SBWC
        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;
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        public void UninitializedShipObject()
        {
            Setup();
            ShipPosition pos = new ShipPosition();
            bool         ret = _sut.PlaceShipOnBoard(pos);

            Assert.False(ret);
        }
コード例 #17
0
        public void NullShipObject()
        {
            Setup();
            ShipPosition pos = null;
            bool         ret = _sut.PlaceShipOnBoard(pos);

            Assert.False(ret);
        }
コード例 #18
0
    public Ship(Layout layout)
    {
        Layout = layout;

        Position = new ShipPosition();

        Radar = new ShipRadar();
    }
コード例 #19
0
        public void TestGame_ConvertShootToRowAndColumn()
        {
            var shoot    = "C9";
            var position = new ShipPosition(shoot);

            Assert.Equal(position.Row, GridRows.C);
            Assert.Equal(position.Column, 8);
        }
コード例 #20
0
 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);
 }
コード例 #21
0
ファイル: ShipPositionManager.cs プロジェクト: dargonar/LRIT
        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);
        }
コード例 #22
0
    public AIShip( )
    {
        Positions = new ShipPosition();

        Positions.Solar = new Vector2((int)Random.Range(-300, 300), (int)Random.Range(-300, 300));

        Positions.OnReachedTargetPosition += NeedNewTargetPosition;

        NeedNewTargetPosition();
    }
コード例 #23
0
        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);
        }
コード例 #24
0
 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);
     }
 }
コード例 #25
0
        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);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
 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);
 }
コード例 #28
0
 /// <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;
 }
コード例 #29
0
        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);
            }
        }
コード例 #32
0
ファイル: Cannon.cs プロジェクト: Crome696/ServUO
        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();
        }
コード例 #33
0
ファイル: ShipPosition.cs プロジェクト: else-if/homeworks
 protected bool Equals(ShipPosition other)
 {
     return X == other.X && Y == other.Y && ShipDirection == other.ShipDirection;
 }