public void RemoveBrick(Vector2 location) { GameObject numberObject = null; lastLocation = location; foreach (GameObject go in activeBricks) { if (go.GetComponent <NumberBlock>() != null) { if (go.transform.position.x == location.x && go.transform.position.y == location.y) { numberObject = go; break; } } } if (numberObject != null) { numberObject.GetComponentInChildren <Text>().text = ""; NumberBlock numberBlock = numberObject.GetComponent <NumberBlock>(); activeBricks.Remove(numberObject); Destroy(numberBlock); } }
public void DragendOver(NumberBlock block) { if (dragendBlocks.Count == 0) { return; } NumberBlock lastBlock = dragendBlocks[dragendBlocks.Count - 1]; if (block.Equals(lastBlock)) { return; } if (!predicatePosition(block, dragendBlocks[dragendBlocks.Count - 1])) { return; } if (!allowInvalidPath && !predicateValue(block, dragendBlocks[dragendBlocks.Count - 1])) { return; } if (!dragendBlocks.Contains(block)) { dragendBlocks.Add(block); } else { if (dragendBlocks.Count > 1) { List <NumberBlock> removedBlocks = dragendBlocks.GetRange(dragendBlocks.IndexOf(block), dragendBlocks.Count - 1); removedBlocks.ForEach(b => dragendBlocks.Remove(b)); removedBlocks.ForEach(b => b.ResetShadow()); } } UpdateBlockShadows(); }
private void createBlock(int row, int column) { GameObject go = GameObject.Instantiate(blockPrefab); NumberBlock numberBlock = go.GetComponent <NumberBlock> (); numberBlock.Init(this, row, column, rand.Next(maxNumber) + 1); blocks.Add(numberBlock); }
public void DragStart(NumberBlock block) { dragendBlocks = new List <NumberBlock> (); //if (block.value == 1) { dragendBlocks.Add(block); UpdateBlockShadows(); //} }
/// <summary> /// Called when a team has hit a brick /// </summary> /// <param name="brick">the brick you hit.</param> /// <returns>Whether the move was allowed or not.</returns> public bool HitBrick(Interactable brick) { //At the start of the game, pick a start number. if (currentTeam.started == false) { if (brick is NumberBlock) { ui.StartMoveNumberBrick(brick, currentTeam); currentTeam.HitNumberBrick(brick, true); currentTeam.started = true; } else { return(false); } } //During the rest of the game, we have to check which brick was hit. else { //A Number block if (brick is NumberBlock) { NumberBlock num = brick as NumberBlock; //Only if there is a multiplier selected, you are allowed to hit a number. if (!currentTeam.operationRound) { ui.StartMoveNumberBrick(brick, currentTeam); currentTeam.HitNumberBrick(num); } else { return(false); } } //An operation block else if (brick is OperationBlock) { //Only if there is currently no multiplier you are allowed to hit one. if (currentTeam.operationRound) { ui.StartMoveOperationBrick(brick, currentTeam); currentTeam.HitOperationBrick(brick); } else { return(false); } } } StartHitTimout(); return(true); }
public Cell GetClosestCell(NumberBlock _block) { float minDistance = cells.Min(c => (c.transform.position - _block.transform.position).magnitude); if (minDistance > distanceToPut) { return(null); } Cell closestCell = cells.Find(c => (c.transform.position - _block.transform.position).magnitude == minDistance); return(closestCell); }
public void HitNumberBrick(Interactable i, bool start = false) { NumberBlock b = i as NumberBlock; if (start) { started = true; number1 = b.number; operationRound = true; process = 2; } else { number2 = b.number; process = 4; operationRound = true; } }
public void PutBlockInQueue(NumberBlock _block) { List <Cell> emptyCells = cells.FindAll(c => c.IsEmpty()); _block.AttachToCell(emptyCells[Random.Range(0, emptyCells.Count)]); }