Beispiel #1
0
    /// <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);
        }
    }