/// <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); } }
private BoardPiece createZoneBarrier(int rowNum, int colCount, int colorType) { GameObject bGo = Instantiate(ResourceLoader.instance.zoneBarrierPieceFab); ZoneBarrierBoardPiece pc = bGo.GetComponent <ZoneBarrierBoardPiece>(); pc.SetBoard(curBoard); pc.setKey(colorType); curBoard.AddPiece(pc, colCount, rowNum); return(pc); }
//Make a square. temp code only private void addZoneBarrier(Board board, int zoneKey, int start, int end) { List <Vector2> squares = new List <Vector2>(); //top row for (int y = start; y < end; y++) { for (int x = start; x < board.GetBoardSize() - start; x++) { Vector2 va = new Vector2(x, y); if (!squares.Contains(va)) { squares.Add(va); } Vector2 vb = new Vector2(y, x); if (!squares.Contains(vb)) { squares.Add(vb); } } } //bot row for (int y = board.GetBoardSize() - end; y < board.GetBoardSize() - start; y++) { for (int x = start; x < board.GetBoardSize() - start; x++) { Vector2 va = new Vector2(x, y); if (!squares.Contains(va)) { squares.Add(va); } Vector2 vb = new Vector2(y, x); if (!squares.Contains(vb)) { squares.Add(vb); } } } foreach (Vector2 v in squares) { GameObject vgg = Instantiate(ResourceLoader.instance.zoneBarrierPieceFab); ZoneBarrierBoardPiece vvv = vgg.GetComponent <ZoneBarrierBoardPiece>(); vvv.SetBoard(board); vvv.setKey(zoneKey); board.AddPiece(vvv, (int)v.x, (int)v.y); } }