Пример #1
0
        public void GetCreatedGridItems()
        {
            Vector2 originPosition = new Vector2(0, 0);

            Game.GridImplementation grid = CreateGrid(3, 3, 2, originPosition);

            GameObject firstGridItemObject  = grid.GridItemObjects[0];
            GameObject secondGridItemObject = grid.GridItemObjects[1];
            GameObject thirdGridItemObject  = grid.GridItemObjects[2];

            GridItemMover firstGridItemMover  = firstGridItemObject.GetComponent <GridItemMover>();
            GridItem      firstGridItem       = firstGridItemObject.GetComponent <GridItem>();
            GridItemMover secondGridItemMover = secondGridItemObject.GetComponent <GridItemMover>();
            GridItem      secondGridItem      = secondGridItemObject.GetComponent <GridItem>();
            GridItemMover thirdGridItemMover  = thirdGridItemObject.GetComponent <GridItemMover>();
            GridItem      thirdGridItem       = thirdGridItemObject.GetComponent <GridItem>();

            Assert.AreEqual(5, firstGridItem.WidthInUnit);
            Assert.AreEqual(6, firstGridItem.HeightInUnit);
            Assert.AreNotEqual(secondGridItemMover.Position, thirdGridItemMover.Position);
            Assert.AreNotEqual(firstGridItemMover.Position, secondGridItemMover.Position);
            //Assert.AreEqual(new Vector2(-10.5f, 12), firstGridItemMover.Position);
            Assert.AreEqual(firstGridItemMover.Position + new Vector2(secondGridItem.WidthInUnit + 2, 0), secondGridItemMover.Position);
            Assert.AreEqual(secondGridItemMover.Position + new Vector2(thirdGridItem.WidthInUnit + 2, 0), thirdGridItemMover.Position);
        }
Пример #2
0
        private Game.GridImplementation CreateGrid(int width, int height, float offset, Vector2 originPosition)
        {
            StubItemNeighborRetriever itemNeighborRetriever = CreateItemNeighborRetriever();
            GridItemFactory           gridItemFactory       = CreateGridItemFactory(itemNeighborRetriever);
            GridImplementation        gridImplementation    = new Game.GridImplementation(width, height, gridItemFactory, offset, originPosition);

            itemNeighborRetriever.Initialize(gridImplementation);

            return(gridImplementation);
        }
Пример #3
0
        public void GridCreation()
        {
            Vector2 originPosition = new Vector2(0, 0);

            Game.GridImplementation grid = CreateGrid(3, 3, 1, originPosition);

            Assert.AreEqual(3, grid.Width);
            Assert.AreEqual(3, grid.Height);
            Assert.IsNotNull(grid.GridItemObjects);
            Assert.AreEqual(9, grid.GridItemObjects.Count);
        }
Пример #4
0
        public void SetEmptyStateToRandomSlot()
        {
            Game.GridImplementation slotGrid    = CreateSlotGrid();
            SlotSorting             slotSorting = CreateSlotSortingToGrid(slotGrid);

            GameObject randomSlotObject = slotSorting.GetRandomEmptySlotObject();
            PieceDestinationController randomSlotPieceDestinationController = randomSlotObject.GetComponent <PieceDestinationController>();

            Assert.IsTrue(randomSlotPieceDestinationController.State is EmptyState);
            Assert.IsNull(randomSlotPieceDestinationController.Piece);
        }
Пример #5
0
        public void FirstAndSecondGridItemAreNotNull()
        {
            Vector2 originPosition = new Vector2(0, 0);

            Game.GridImplementation grid = CreateGrid(3, 3, 2, originPosition);

            GameObject firstGridItemObject  = grid.GridItemObjects[0];
            GameObject secondGridItemObject = grid.GridItemObjects[1];

            Assert.IsNotNull(firstGridItemObject);
            Assert.IsNotNull(secondGridItemObject);
        }
Пример #6
0
        public void RandomEmptySlotHasMovableNeighbors()
        {
            Game.GridImplementation slotGrid    = CreateSlotGrid();
            SlotSorting             slotSorting = CreateSlotSortingToGrid(slotGrid);

            GameObject        randomSlotObject = slotSorting.GetRandomEmptySlotObject();
            GridItemMover     slotMover        = randomSlotObject.GetComponent <GridItemMover>();
            List <GameObject> slotNeighbors    = slotGrid.GetItemNeighbors(slotMover);

            Assert.Greater(slotNeighbors.Count, 1);
            foreach (GameObject slotNeighbor in slotNeighbors)
            {
                PieceDestinationController currentSlotPieceDestinationController = slotNeighbor.GetComponent <PieceDestinationController>();

                Assert.IsTrue(currentSlotPieceDestinationController.CanMovePiece());
            }
        }
Пример #7
0
        public void CreatePieaceAndSetItsPosition()
        {
            float   offset         = 2;
            Vector2 originPosition = new Vector2(0, 0);

            Game.GridImplementation grid            = CreateGrid(3, 3, offset, originPosition);
            GridItemFactory         gridItemFactory = CreateGridItemFactory();

            float   gridItemWidthInUnit  = gridItemFactory.GridItemWidthInUnit;
            float   gridItemHeightInUnit = gridItemFactory.GridItemHeightInUnit;
            int     amountOfGridColumns  = grid.Width;
            int     amountOfGridRows     = grid.Height;
            Vector2 gridOrigin           = grid.Position;
            Vector2 piceMeasuresInUnit   = new Vector2(gridItemWidthInUnit, gridItemHeightInUnit);

            GridItemPositioningStrategy positioningStrategy = CreateCenterPositioningStrategy
                                                              (
                amountOfGridColumns,
                amountOfGridRows,
                gridOrigin,
                piceMeasuresInUnit,
                offset
                                                              );

            GameObject    gridItemObject = gridItemFactory.Create();
            GridItem      gridItem       = gridItemObject.GetComponent <GridItem>();
            GridItemMover gridItemMover  = gridItemObject.GetComponent <GridItemMover>();

            Assert.IsNotNull(gridItem);
            Assert.IsNotNull(gridItemMover);

            gridItemMover.Position = positioningStrategy.GetGridItemPositionByRowAndColum(0, 0);

            Assert.AreEqual(gridItemWidthInUnit, gridItem.WidthInUnit);
            Assert.AreEqual(gridItemHeightInUnit, gridItem.HeightInUnit);
            //Assert.AreEqual(new Vector2(-10.5f, 12), gridItemMover.Position);
        }
Пример #8
0
 private SlotSorting CreateSlotSortingToGrid(Game.GridImplementation slotGrid)
 {
     return(new SlotSortingImplementation(slotGrid));
 }