public Move_Billy(BoardElement piece, Vector2i newPos) { Piece = piece; NewPos = newPos; UnityEngine.Assertions.Assert.IsFalse(piece.IsCursed); }
private void ResetArrays() { //Reset the actual arrays. int size = (int)BoardSize; Pieces = new BoardElement[size, size]; Hosts = new BoardElement[size, size]; foreach (Vector2i boardPos in Pieces.AllIndices()) { Pieces.Set(boardPos, null); Hosts.Set(boardPos, null); } //Also reset the grid cell sprites. if (gridCellsContainer != null) { Destroy(gridCellsContainer); } gridCellsContainer = new GameObject("Grid Cells"); foreach (Vector2i boardPos in AllPoses) { GameObject cell = new GameObject(boardPos.ToString()); cell.transform.parent = gridCellsContainer.transform; cell.transform.position = new Vector3(boardPos.x + 0.5f, boardPos.y + 0.5f, 0.0f); var spr = cell.AddComponent <SpriteRenderer>(); spr.sprite = GridCellSprite; spr.sortingOrder = GridCellSortLayer; } }
private void Callback_PieceClicked(InputResponder piece, Vector2 worldMousePos) { //Clean up any previous moves being displayed. if (moveSprites != null) SpritePool.Instance.DeallocateSprites(moveSprites); moveOptions.Clear(); activePiece = piece.GetComponent<Gameplay.BoardElement>(); Gameplay.Move_Billy.GetMoves(Board, activePiece, moveOptions); moveSprites = SpritePool.Instance.AllocateSprites(moveOptions.Count, OptionSprite, SpriteLayer, null, "Billy Move"); for (int i = 0; i < moveSprites.Count; ++i) { moveSprites[i].transform.position = new Vector3(moveOptions[i].NewPos.x + 0.5f, moveOptions[i].NewPos.y + 0.5f, 0.0f); moveSprites[i].transform.localScale = new Vector3(SpriteScale, SpriteScale, 1.0f); moveSprites[i].color = SpriteCol; var collider = moveSprites[i].gameObject.AddComponent<BoxCollider2D>(); var responder = moveSprites[i].gameObject.AddComponent<InputResponder>(); AddResponse(responder, moveOptions[i]); } }
public static void GetMoves(Board board, BoardElement piece, List <Move_Billy> outMoves) { //Breadth-first search up to a certain distance away. //Each "hop" is a valid move as long as the space is empty. //Store a "hop" as the current position plus the number of hops left. Queue <KeyValuePair <Vector2i, int> > hopsToCheck = new Queue <KeyValuePair <Vector2i, int> >(); HashSet <Vector2i> alreadyChecked = new HashSet <Vector2i>(); hopsToCheck.Enqueue(new KeyValuePair <Vector2i, int>(piece.Pos, GameConsts.NSpacesPerBillyMove)); while (hopsToCheck.Count > 0) { var hop = hopsToCheck.Dequeue(); alreadyChecked.Add(hop.Key); if (board.Pieces.Get(hop.Key) == null) { outMoves.Add(new Move_Billy(piece, hop.Key)); } //Make more hops. if (hop.Value > 0) { int nextHop = hop.Value - 1; foreach (Vector2i neighborPos in new Vector2i.Neighbors(hop.Key)) { if (board.IsInRange(neighborPos) && board.Pieces.Get(neighborPos) == null && !alreadyChecked.Contains(neighborPos)) { hopsToCheck.Enqueue(new KeyValuePair <Vector2i, int>(neighborPos, nextHop)); } } } } }