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); }
private PieceDestinationController CreatePieceDestinationController() { GridItemMover pieceMover = CreatePieceMover(); PieceTranslationController pieceTranslationController = CreatePieceTranslationController(pieceMover); return(new PieceDestinationControllerImplementation(pieceTranslationController, pieceMover, new StubWinController())); }
public void MovePieceWhenFirstSelectedSlotIsMovableAndSecondCanReceivePiece() { //TODO: Slot tem que dar a posição dele e não da peça, pq tem slots q não possuem peça Vector2 pieceDestinePosition = new Vector2(1, 2); SlotSelection slotSelection = CreateSlotSelection(); GameObject pieceObject = CreatePieceObject(); GridItemMover pieceMover = pieceObject.GetComponent <GridItemMover>(); PieceTranslationController firstPieceTranslationController = CreatePieceTranslationController(pieceObject); PieceDestinationController firstPieceDestinationController = CreatePieceDestinationController(firstPieceTranslationController, pieceMover); firstPieceDestinationController.SetMovable(); Positioner slotPositioner = CreateSlotPositioner(pieceDestinePosition); Slot slot1 = CreateSlot(slotSelection, firstPieceDestinationController, slotPositioner); GameObject pieceObject2 = CreatePieceObject(); GridItemMover pieceMover2 = pieceObject2.GetComponent <GridItemMover>(); PieceTranslationController secondPieceTranslationController = CreatePieceTranslationController(pieceObject2); PieceDestinationController secondPieceDestinationController = CreatePieceDestinationController(secondPieceTranslationController, pieceMover2); secondPieceDestinationController.SetEmpty(); Positioner slotPositioner2 = CreateSlotPositioner(pieceDestinePosition); Slot slot2 = CreateSlot(slotSelection, secondPieceDestinationController, slotPositioner2); slot1.Touch(); slot2.Touch(); Assert.AreEqual(pieceDestinePosition, pieceMover.Position); }
private PieceDestinationController CreatePieceDestinationController(WinController winController) { PieceTranslationController pieceTranslationController = CreatePieceTranslationController(); GridItemMover slotGridItemMover = SlotGridItemMover(); return(new PieceDestinationControllerImplementation(pieceTranslationController, slotGridItemMover, winController)); }
public void Construct(PieceData pieceData) { this.pieceData = pieceData; text.text = pieceData.Text; GridItemMover gridItemMover = GetComponent <GridItemMover>(); gridItemMover.SetupRownAndColumn(pieceData.PlaceInGrid, 0, 0); }
public void PieceTranslation() { GridItemMover pieceMover = CreatePieceMover(); PieceTranslationController pieceTranslationController = CreatePieceTranslationController(pieceMover); Vector2 newPiecePosition = new Vector2(1, 2); pieceTranslationController.TranslateToPosition(newPiecePosition); Assert.AreEqual(newPiecePosition, pieceMover.Position); }
public void MovingFromOneSlotToAnother() { Vector2 pieceDestinePosition = new Vector2(1, 2); GridItemMover pieceMover = CreatePieceMover(); PieceTranslationController pieceTranslationController = CreatePieceTranslationController(pieceMover); PieceDestinationController pieceDestinationController = CreatePieceDestinationController(pieceTranslationController, pieceMover); pieceDestinationController.MovePieceToDestinePosition(pieceDestinePosition); Assert.AreEqual(pieceDestinePosition, pieceMover.Position); }
public void SetupGridItemMoverRowAndColumn() { int row = 1; int column = 2; GridItemMover gridItemMover = CreateGridItemMover(); gridItemMover.SetupRownAndColumn(0, row, column); Assert.AreEqual(row, gridItemMover.Row); Assert.AreEqual(column, gridItemMover.Column); }
private void CreateGridItemToPlaceRowAndColumn(int place, int column, int row) { GameObject girdItemObject = gridItemFactory.Create(); girdItemObject.name = row + "x" + column; GridItemMover gridItemMover = girdItemObject.GetComponent <GridItemMover>(); gridItemMover.Position = positioningStrategy.GetGridItemPositionByRowAndColum(row, column); gridItemMover.SetupRownAndColumn(place, row, column); GridItemObjects.Add(girdItemObject); }
public void FindGridItemNeighbor() { grid = CreateSlotGrid(3, 3); GameObject currentSlotObject = GetSlotObjectByRowAndColumn(1, 1); GridItemMover slotGridItemMover = currentSlotObject.GetComponent <GridItemMover>(); //List<GameObject> neighBors = grid.GetItemNeighbors(slotGridItemMover); List <GameObject> neighBors = slotGridItemMover.GetNeighbors(); Assert.AreEqual(4, neighBors.Count); }
public void ChangeGridItemPosition() { GridItemMover gridItemMover = CreateGridItemMover(); Vector2 newPosition = new Vector2(1, 2); Vector2 initialGridItemPosition = gridItemMover.Position; gridItemMover.Position = newPosition; Assert.AreEqual(new Vector2(0, 0), initialGridItemPosition); Assert.AreEqual(newPosition, gridItemMover.Position); }
public PieceDestinationControllerImplementation(PieceTranslationController pieceTranslationController, GridItemMover slotGridItemMover, WinController winController) { this.pieceTranslationController = pieceTranslationController; this.slotGridItemMover = slotGridItemMover; this.winController = winController; //this.grid = grid; NULL_TRANSLATION_CONTROLLER = new NullPieceTranslationController(); EMPTY_STATE = new EmptyState(); MOVABLE_STATE = new MovableState(); FIXED_STATE = new FixedState(); SetFixed(); }
public void MovePieceWhenDestinationControlerIsMovingState() { Vector2 pieceDestinePosition = new Vector2(1, 2); GridItemMover pieceMover = CreatePieceMover(); PieceTranslationController pieceTranslationController = CreatePieceTranslationController(pieceMover); PieceDestinationController pieceDestinationController = CreatePieceDestinationController(pieceTranslationController, pieceMover); pieceDestinationController.SetMovable(); pieceDestinationController.TakePieceToPosition(pieceDestinePosition); Assert.AreEqual(pieceDestinePosition, pieceMover.Position); }
public void PieceCreation() { int initialGridItemRow = 1; int initialGridItemColum = 2; GridItemMover gridItemMover = CreateGridItemMover(); gridItemMover.SetupRownAndColumn(0, initialGridItemRow, initialGridItemColum); PieceImplementation piece = new PieceImplementation(gridItemMover); Assert.AreEqual(initialGridItemRow, piece.Row); Assert.AreEqual(initialGridItemColum, piece.Column); }
public void NeigborOfSlotDifferentThanAGivenSlotTurnFixed() { Game.Grid grid = CreateSlotGrid(); GameObject slotObject = GetEmptySlotObjectFromGrid(grid); GridItemMover slotMover = slotObject.GetComponent <GridItemMover>(); List <GameObject> slotNeighbors = slotMover.GetNeighbors(); GameObject givenSlot = slotNeighbors[0]; SlotSelectionServer givenSlotSelectionServer = givenSlot.GetComponent <SlotSelectionServer>(); PieceDestinationController slot = slotObject.GetComponent <PieceDestinationController>(); slot.TurnFixedAllNeighborButOne(givenSlotSelectionServer); TestNeighborsAreFixedButGivenOne(slotNeighbors, givenSlotSelectionServer); }
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()); } }
public void WhenEmptySlotReceivePieceItsNeighborShouldTurnFixed() { Game.Grid grid = CreateSlotGrid(); GameObject emptySlotObject = GetEmptySlotObjectFromGrid(grid); GameObject movableSlotObject = GetNeighborOfSlot(emptySlotObject); GridItemMover slotMover = emptySlotObject.GetComponent <GridItemMover>(); List <GameObject> slotNeighbors = slotMover.GetNeighbors(); Slot emptySlot = emptySlotObject.GetComponent <Slot>(); Slot movableSlot = movableSlotObject.GetComponent <Slot>(); SlotSelectionServer givenSlotSelectionServer = movableSlotObject.GetComponent <SlotSelectionServer>(); PieceDestinationController emptySlotPieceDestinationController = emptySlotObject.GetComponent <PieceDestinationController>(); PieceDestinationController movableSlotPieceDestinationController = movableSlotObject.GetComponent <PieceDestinationController>(); movableSlot.Touch(); emptySlot.Touch(); TestNeighborsAreFixedButGivenOne(slotNeighbors, givenSlotSelectionServer); }
public List <GameObject> GetItemNeighbors(GridItemMover gridMover) { List <GameObject> itemNeighbors = new List <GameObject>(); // Get left item int leftRow = gridMover.Row; int leftColumn = gridMover.Column - 1; if (IsInRowBounds(leftRow) && IsInColumnBounds(leftColumn)) { itemNeighbors.Add(GetGridItemObjectByRowColumn(leftRow, leftColumn)); } // Get up item int upRow = gridMover.Row - 1; int upColumn = gridMover.Column; if (IsInRowBounds(upRow) && IsInColumnBounds(upColumn)) { itemNeighbors.Add(GetGridItemObjectByRowColumn(upRow, upColumn)); } // Get right item int rightRow = gridMover.Row; int rightColumn = gridMover.Column + 1; if (IsInRowBounds(rightRow) && IsInColumnBounds(rightColumn)) { itemNeighbors.Add(GetGridItemObjectByRowColumn(rightRow, rightColumn)); } // Get bottom item int bottomRow = gridMover.Row + 1; int bottomColumn = gridMover.Column; if (IsInRowBounds(bottomRow) && IsInColumnBounds(bottomColumn)) { itemNeighbors.Add(GetGridItemObjectByRowColumn(bottomRow, bottomColumn)); } return(itemNeighbors); }
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); }
private PieceTranslationController CreatePieceTranslationController(GridItemMover pieceMover) { return(new StubPieceTranslationController(pieceMover)); }
public List <GameObject> GetItemNeighbors(GridItemMover item) { return(new List <GameObject>()); }
public StubPieceTranslationController(GridItemMover pieceMover) { this.pieceMover = pieceMover; }
public StubPieceTranslationController(GameObject pieceObject) { PieceObject = pieceObject; this.pieceMover = PieceObject.GetComponent <GridItemMover>(); }
public void GridItemMoverCreation() { GridItemMover gridItemMover = CreateGridItemMover(); Assert.IsNotNull(gridItemMover); }
public PieceImplementation(GridItemMover pieceMover) { this.pieceMover = pieceMover; Row = pieceMover.Row; Column = pieceMover.Column; }
public List <GameObject> GetItemNeighbors(GridItemMover gridMover) { return(grid.GetItemNeighbors(gridMover)); }
public List <GameObject> GetItemNeighbors(GridItemMover item) { return(itemNeighborRetriever.GetItemNeighbors(item)); }
private PieceTranslationController CreatePieceTranslationController(GridItemMover pieceMover) { GameObject pieceObject = CreatePieceObject(); return(new StubPieceTranslationController(pieceObject)); }
private GameObject GetNeighborOfSlot(GameObject slotObject) { GridItemMover gridItemMover = slotObject.GetComponent <GridItemMover>(); return(gridItemMover.GetNeighbors()[0]); }