/// <summary> /// Test the key against all board pieces, unlocking the ones that accept the key. /// </summary> /// <param name="keyId"></param> public void useKey(int keyId) { List <BoardPiece> piecesToRemove = new List <BoardPiece>(); for (int i = 0; i < boardPieces.Count; i++) { //Debug.Log("index " + i + " (" + boardPieces[i].x + ", " + boardPieces[i].y + ")"); BoardPiece piece = boardPieces[i]; int xPos = piece.x; int yPos = piece.y; int tileContent = boardContent[xPos, yPos]; if (piece.isAt(xPos, yPos) && piece.GetContentType() == BoardPiece.ZONE_BARRIER) { ZoneBarrierBoardPiece zbb = (ZoneBarrierBoardPiece)boardPieces[i]; if (zbb.unlocks(keyId)) { piecesToRemove.Add(zbb); } } } foreach (BoardPiece bp in piecesToRemove) { RemovePiece(bp, bp.x, bp.y); Destroy(bp.gameObject); } }
/// <summary> /// Get the pickups, if any, at the given board location. /// </summary> /// <param name="xPos"></param> /// <param name="yPos"></param> /// <returns>All pickups at location or an empty list if there are none.</returns> public List <BoardPiece> getPickups(int xPos, int yPos) { List <BoardPiece> pickups = new List <BoardPiece>(); for (int i = 0; i < boardPieces.Count; i++) { int tileContent = boardContent[xPos, yPos]; if (hasSet(tileContent, BoardPiece.PICKUP)) { BoardPiece bp = boardPieces[i]; if (bp.isAt(xPos, yPos) && bp.GetContentType() == BoardPiece.PICKUP) { pickups.Add(boardPieces[i]); RemovePiece(boardPieces[i], xPos, yPos); } } } return(pickups); }
/// <summary> /// Update the contents of the tiles affected by a piece move. /// This version is for moving a piece NOT already on the board. /// Does not validate move. /// </summary> /// <param name="piece">Piece that was moved</param> /// <param name="newX">new x location</param> /// <param name="newY">new y location</param> public void UpdatePiece_Place(BoardPiece piece, int newX, int newY) { int typeId = piece.GetContentType(); boardContent[newX, newY] |= typeId; }
/// <summary> /// Update the contents of the tiles affected by a piece move. /// This version is for moving a piece off the board. /// Does not validate move. /// </summary> /// <param name="piece">Piece that was moved</param> /// <param name="oldX">prev x location</param> /// <param name="oldY">prev y location</param> public void UpdatePiece_Remove(BoardPiece piece, int oldX, int oldY) { int typeId = piece.GetContentType(); boardContent[oldX, oldY] &= mask_remove(typeId); }