Пример #1
0
        private Cell RotateCell(ShipRotation rotation, Cell cell)
        {
            var rotatedCell = new Cell(0, 0);

            switch (rotation)
            {
            case ShipRotation._0:
                return(cell);

            case ShipRotation._90:
                rotatedCell.X = -cell.Y;
                rotatedCell.Y = cell.X;
                break;

            case ShipRotation._180:
                rotatedCell.X = -cell.X;
                rotatedCell.Y = -cell.Y;
                break;

            case ShipRotation._270:
                rotatedCell.X = cell.Y;
                rotatedCell.Y = -cell.X;
                break;
            }

            return(rotatedCell);
        }
Пример #2
0
 // Use this for initialization
 void Start()
 {
     orbit      = GetComponent <OrbitingObject>();
     shipRotate = GetComponent <ShipRotation>();
     rotating   = false;
     powered    = false;
 }
Пример #3
0
        public ShipRotation GetRotationInput()
        {
            string       userInput    = "";
            ShipRotation shipRotation = ShipRotation.Horizontal;

            bool isInputCorrect = false;

            while (!isInputCorrect)
            {
                Console.WriteLine("Chose ship rotation");
                Console.WriteLine("V -> Vertical");
                Console.WriteLine("H -> Horizontal");

                userInput = Console.ReadLine();
                if (userInput == "V")
                {
                    shipRotation   = ShipRotation.Vertical;
                    isInputCorrect = true;
                }
                else if (userInput == "H")
                {
                    shipRotation   = ShipRotation.Horizontal;
                    isInputCorrect = true;
                }
                else
                {
                    Console.WriteLine("Input Error. Try Again.");
                }
            }

            return(shipRotation);
        }
Пример #4
0
        public void AddShip_SurroundShipWithClosedCells(int pointX, int pointY, ShipRotation shipRotation, ShipType shipType)
        {
            var shipStorage = new ShipsStorage();

            shipStorage.AddShip(shipType, 1);

            _builder.SetDimension(5, 5);
            _builder.SetShipsStorage(shipStorage);

            var shipPlacementInfo = new ShipPlacementInfo
            {
                Point        = new Point(pointX, pointY),
                ShipRotation = shipRotation,
                ShipType     = shipType
            };


            _builder.AddShip(shipPlacementInfo);

            var listOfCells = GetListOfCellsAroundShip(shipPlacementInfo);

            foreach (var cell in listOfCells)
            {
                Assert.False(cell.CanPlaceShip);
            }
        }
Пример #5
0
        public void AddShip_RightShipPlacementInfo(int pointX, int pointY, ShipRotation shipRotation, ShipType shipType)
        {
            var shipStorage = new ShipsStorage();

            shipStorage.AddShip(shipType, 1);

            _builder.SetDimension(5, 5);
            _builder.SetShipsStorage(shipStorage);

            var shipPlacementInfo = new ShipPlacementInfo
            {
                Point        = new Point(pointX, pointY),
                ShipRotation = shipRotation,
                ShipType     = shipType
            };


            _builder.AddShip(shipPlacementInfo);

            var listOfCells = GetListOfCellsWhereShipShouldBe(shipPlacementInfo);

            foreach (var cell in listOfCells)
            {
                Assert.True(cell.CellState == CellState.Ship);
            }
        }
 void Start()
 {
     playerPos   = GameObject.FindGameObjectWithTag("Player");
     pirateShoot = thisPirateShip.GetComponent <PirateShoot>();
     shiprot     = thisPirateShip.GetComponent <ShipRotation>();
     agent       = GetComponent <NavMeshAgent>();
     GetRandomLocation();
     action = Action.PATROLLING;
 }
Пример #7
0
 public void ToggleShipRotation()
 {
     if (currentRotation == ShipRotation.Horizontal)
     {
         currentRotation = ShipRotation.Vertical;
     }
     else
     {
         currentRotation = ShipRotation.Horizontal;
     }
 }
Пример #8
0
    void Start()
    {
        shipSpeed    = new ShipSpeed(minSpeed, maxSpeed);
        shipRotation = new ShipRotation();
        shipRb       = GetComponent <Rigidbody>();
        speedText    = speedTextObj.GetComponent <TextMeshPro>();
        if (speedText)
        {
            speedText.text = shipSpeed.speed.ToString();
        }

        engineText = engineTextObj.GetComponent <TextMeshPro>();
    }
        public void GenerateShipOfSize_Input2_ReturnsTwoDeckShipWithRotationGeneratedByRandom(
            ShipRotation shipRotationGeneratedByRandom)
        {
            var randomIndexGeneratorStub        = new Mock <IRandomGenerator>();
            var possibleRotationsForTwoDeckShip = new[] { ShipRotation._0, ShipRotation._90 };

            randomIndexGeneratorStub.Setup(r => r.GetRandomElementFromArrayAsInt(possibleRotationsForTwoDeckShip))
            .Returns((int)shipRotationGeneratedByRandom);
            var randomShipGenerator = new RandomShipGenerator(randomIndexGeneratorStub.Object);

            var result = randomShipGenerator.GenerateShipOfSize(2);

            Assert.Multiple(() =>
            {
                Assert.That(result, Is.TypeOf <TwoDeckShip>());
                Assert.That(result.Rotation, Is.EqualTo(shipRotationGeneratedByRandom));
            });
        }
Пример #10
0
 public void StartGame(int totalShip)
 {
     OccupiedCells   = string.Empty;
     ships           = new List <GameObject>();
     OccupiedNumber  = 0;
     isActive        = false;
     grid            = new GameObject[gridSizeX, gridSizeY];
     tileWidth       = tilePrefab.transform.lossyScale.x;
     tileHeight      = tilePrefab.transform.lossyScale.y;
     currentRotation = ShipRotation.Horizontal;
     if (gridType == GridType.Defense)
     {
         totalShipCount = totalShip;
         shipCount      = 0;
     }
     setupComplete = false;
     CreateGrid();
 }
        GenerateShipOfSize_Input4RandomReturnsLineOrZigzagShipShape_ReturnsFourDeckShipWithShapeAndRotationGeneratedByRandom(
            ShipShape shipShapeGeneratedByRandom, ShipRotation shipRotationGeneratedByRandom)
        {
            var randomIndexGeneratorStub = new Mock <IRandomGenerator>();
            var fourDeckShipShapes       = Enum.GetValues(typeof(ShipShape));
            var lineOrZigzagShapeFourDeckShipRotations = new[] { ShipRotation._0, ShipRotation._90 };

            randomIndexGeneratorStub.Setup(r => r.GetRandomElementFromArrayAsInt(fourDeckShipShapes))
            .Returns((int)shipShapeGeneratedByRandom);
            randomIndexGeneratorStub.Setup(r => r.GetRandomElementFromArrayAsInt(lineOrZigzagShapeFourDeckShipRotations))
            .Returns((int)shipRotationGeneratedByRandom);
            var randomShipGenerator = new RandomShipGenerator(randomIndexGeneratorStub.Object);

            var result = randomShipGenerator.GenerateShipOfSize(4);

            Assert.Multiple(() =>
            {
                Assert.That(result, Is.TypeOf <FourDeckShip>());
                Assert.That(result.Shape, Is.EqualTo(shipShapeGeneratedByRandom));
                Assert.That(result.Rotation, Is.EqualTo(shipRotationGeneratedByRandom));
            });
        }
Пример #12
0
 private void Awake()
 {
     shipEngine   = GetComponent <ShipEngine>();
     shipRotation = GetComponent <ShipRotation>();
 }
Пример #13
0
        public void AddShip_ThrowsShipPlacementCollisionException(int pointX, int pointY, ShipRotation shipRotation)
        {
            var shipStorage = new ShipsStorage();

            shipStorage.AddShip(ShipType.FourDecks, 1);
            shipStorage.AddShip(ShipType.TwoDecks, 1);

            _builder.SetDimension(5, 5);
            _builder.SetShipsStorage(shipStorage);

            var shipPlacementInfoFirst = new ShipPlacementInfo
            {
                Point        = new Point(3, 3),
                ShipRotation = ShipRotation.Horizontal,
                ShipType     = ShipType.TwoDecks
            };

            _builder.AddShip(shipPlacementInfoFirst);

            var shipPlacementInfoSecond = new ShipPlacementInfo
            {
                Point        = new Point(pointX, pointY),
                ShipRotation = shipRotation,
                ShipType     = ShipType.FourDecks
            };


            void Action() => _builder.AddShip(shipPlacementInfoSecond);


            Assert.Throws <ShipPlacementCollisionException>(Action);
        }
Пример #14
0
        public void AddShip_ThrowsShipPlacementOutOfBoundsException(int pointX, int pointY, ShipRotation shipRotation)
        {
            var shipStorage = new ShipsStorage();

            shipStorage.AddShip(ShipType.FourDecks, 1);


            _builder.SetDimension(5, 5);
            _builder.SetShipsStorage(shipStorage);

            var shipPlacementInfo = new ShipPlacementInfo
            {
                Point        = new Point(pointX, pointY),
                ShipRotation = shipRotation,
                ShipType     = ShipType.FourDecks
            };


            void Action() => _builder.AddShip(shipPlacementInfo);


            Assert.Throws <ShipPlacementOutOfBoundsException>(Action);
        }
Пример #15
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        ShipRotation job = new ShipRotation();

        return(job.Schedule(this, inputDeps));
    }
 public FourDeckShip(ShipShape shape, ShipRotation shipRotation)
 {
     Size     = 4;
     Shape    = shape;
     Rotation = shipRotation;
 }
 public TwoDeckShip(ShipRotation shipRotation)
 {
     Size     = 2;
     Rotation = shipRotation;
     Shape    = ShipShape.Line;
 }
 public ThreeDeckShip(ShipShape shape, ShipRotation shipRotation)
 {
     Size     = 3;
     Shape    = shape;
     Rotation = shipRotation;
 }