/// <summary> /// Places a block if it fits /// </summary> /// <returns><c>true</c>, if play block was placed, <c>false</c> otherwise.</returns> /// <param name="playBlock">Play block.</param> public bool PlacePlayBlock(PlayBlock playBlock, bool erase = false) { if (CheckPlacePlayBlock(playBlock) == false && !erase) { return(false); } int block_id = last_block_id++; int startX = (int)playBlock.transform.position.x; int startY = (int)playBlock.transform.position.z; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (playBlock.block.GetValue(i, j) == 0) { continue; } Board.ROOM_TYPE type = playBlock.roomType; if (erase) { type = Board.ROOM_TYPE.EMPTY; } PlaceTile(startX + i, startY + j, type, currentPlayerId, block_id); //conquer neightbours if (mode == GAME_MODE.CONQUEST && !erase) { for (int k = 0; k < 4; ++k) { Vector2 offset = offsets[k]; Board.Tile next = board.GetTile(startX + i + (int)offset.x, startY + j + (int)offset.y); if (next == null) { continue; } if (next.data.roomType != Board.ROOM_TYPE.WALL && next.data.roomType != Board.ROOM_TYPE.EMPTY && next.data.roomType != Board.ROOM_TYPE.START) { next.data.player = currentPlayerId; next.data.roomType = type; } } } } } GetComponent <AudioSource>().PlayOneShot(clipFall); return(true); }
/// <summary> /// Check if a PlayBlock could be placed in the board /// Called by the PlayerController to place all the tiles from a new block. /// </summary> /// <param name="playBlock"></param> /// <returns></returns> public bool CheckPlacePlayBlock(PlayBlock playBlock) { int startX = (int)playBlock.transform.position.x; int startY = (int)playBlock.transform.position.z; bool touching_player = false; bool is_corridor = playBlock.roomType == Board.ROOM_TYPE.CORRIDOR; //check if placeable for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { int x = startX + i; int y = startY + j; if (x < 0 || x >= board.boardWidth || y < 0 || y >= board.boardHeight) { return(false); } int has_cell = playBlock.block.GetValue(i, j); if (has_cell != 0 && board.GetTileState(x, y) != Board.ROOM_TYPE.EMPTY) { Debug.Log("not empty"); return(false); } //check if player id near if (!touching_player && has_cell == 1) { for (int k = 0; k < 4; ++k) { Vector2 offset = offsets[k]; int x2 = x + (int)offset.x; int y2 = y + (int)offset.y; if (x2 < 0 || x2 >= board.boardWidth || y2 < 0 || y2 >= boardHeight) { continue; //could happen } Board.Tile tile = board.GetTile(x2, y2); if (tile.data.player == currentPlayerId) { //if not touching a corridor if (force_corridors && tile.data.roomType != playBlock.roomType && ( (is_corridor && tile.data.roomType == Board.ROOM_TYPE.CORRIDOR) || (!is_corridor && tile.data.roomType != Board.ROOM_TYPE.CORRIDOR))) { Debug.Log("wrong corridor connection"); continue; } if (force_connectivity && !tile.data.connected && tile.data.roomType != Board.ROOM_TYPE.START) { Debug.Log("not connected"); continue; } touching_player = true; break; } } } } } if (!touching_player) //add tip in GUI about not close to player { Debug.Log("far from player"); return(false); } return(true); }