public bool HasNeighbors(int x, int y) { BoardPiece currentPiece = GetPiece(x, y); if (currentPiece != null) { BoardPiece leftPiece = GetPiece(x - 1, y); if ((leftPiece != null) && (leftPiece.Level == currentPiece.Level)) { return(true); } BoardPiece rightPiece = GetPiece(x + 1, y); if ((rightPiece != null) && (rightPiece.Level == currentPiece.Level)) { return(true); } BoardPiece topPiece = GetPiece(x, y + 1); if ((topPiece != null) && (topPiece.Level == currentPiece.Level)) { return(true); } BoardPiece bottomPiece = GetPiece(x, y - 1); if ((bottomPiece != null) && (bottomPiece.Level == currentPiece.Level)) { return(true); } } return(false); }
public List <BoardPiece> GetConnectedPieces(int x, int y, out List <BoardPiece> outline) { List <BoardPiece> ret = new List <BoardPiece>(); outline = new List <BoardPiece>(); BoardPiece currentPiece = GetPiece(x, y); HashSet <BoardPiece> visited = new HashSet <BoardPiece>(); Stack <BoardPiece> stack = new Stack <BoardPiece>(); stack.Push(currentPiece); while (stack.Count > 0) { BoardPiece temp = stack.Pop(); if (visited.Contains(temp)) { continue; } visited.Add(temp); if (temp.Level == currentPiece.Level) { ret.Add(temp); } else { outline.Add(temp); continue; } BoardPiece left = GetPiece(temp.X - 1, temp.Y); if ((left != null)) { stack.Push(left); } BoardPiece right = GetPiece(temp.X + 1, temp.Y); if ((right != null)) { stack.Push(right); } BoardPiece top = GetPiece(temp.X, temp.Y + 1); if ((top != null)) { stack.Push(top); } BoardPiece bottom = GetPiece(temp.X, temp.Y - 1); if ((bottom != null)) { stack.Push(bottom); } } return(ret); }
private void HandlePieceHighlighted(BoardPiece boardPiece) { Color color = m_spriteRenderer.color; color.a = 0.5f; m_spriteRenderer.color = color; }
public int GetPieceLevel(int x, int y) { BoardPiece piece = GetPiece(x, y); if (piece != null) { return(piece.Level); } return(-1); }
public Board(int width, int height, int numPieceLevels) { m_width = width; m_height = height; m_numPieceLevels = numPieceLevels; m_pieces = new BoardPiece[width + 2, height + 2]; for (int x = 0; x < m_pieces.GetLength(0); x++) { for (int y = 0; y < m_pieces.GetLength(1); y++) { m_pieces[x, y] = new BoardPiece(x, y, this); m_pieces[x, y].Level = -1; } } }
private void HandlePieceUnhighlighted(BoardPiece boardPiece) { m_spriteRenderer.color = parentBoard.colorLevels[boardPiece.Level]; }
private void HandlePieceLevelChanged(BoardPiece boardPiece, int oldLevel, int newLevel) { m_spriteRenderer.color = parentBoard.colorLevels[newLevel]; }
private void HandlePieceDestroyed(BoardPiece boardPiece) { Destroy(gameObject); }