Example #1
0
 public void Setup()
 {
     gridOrigin             = new Vector2(0, 0);
     amountOfGridColumns    = 3;
     amountOfGridRows       = 3;
     gridItemMeasuresInUnit = new Vector2(5, 6);
     offset = 2;
     positioningStrategy = CreateCenterPositioningStrategy(amountOfGridColumns, amountOfGridRows, gridOrigin, gridItemMeasuresInUnit, offset);
 }
        public GridImplementation(int width, int height, GridItemFactory gridItemFactory, float offsetBetweenGridItems, Vector2 origin)
        {
            this.width                  = width;
            this.height                 = height;
            this.gridItemFactory        = gridItemFactory;
            this.offsetBetweenGridItems = offsetBetweenGridItems;
            Origin          = origin;
            GridItemObjects = new List <GameObject>();

            positioningStrategy = CreatePositioningStrategy();
            CreateGridItems();
        }
        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);
        }