public List<GameObject> ParseRowFromBlock(GameObject block) { List<GameObject> blocksOnRow = new List<GameObject>(); if (blockStore.GetAllBlocks() != null) { List<GameObject> blocks = blockStore.GetAllBlocksByRow(block.transform.position.y).OrderBy(x => x.transform.position.x).ToList(); if(blocks.Count() == 1) { return new List<GameObject>(); } for(int i = 0; i < blocks.Count(); i++) { blocksOnRow.Add(blocks.ElementAt(i)); if (blocks.ElementAt(i) == blocks.Last()) { break; } if (!(blocks.ElementAt(i).transform.position.x + 1 == blocks.ElementAt(i + 1).transform.position.x)) { blocksOnRow.Add(null); } } } return blocksOnRow; }
private void FixedUpdate() { if (activeBlock != null) { Block block = activeBlock.GetComponent <Block>(); //Once you cannot keep moving down, you stop being the active block if (!block.GetFreeDirections()[1]) { StoreBlock(activeBlock); List <GameObject> wordBlocks = wordHandler.ParseRow(activeBlock); string wordString = wordHandler.ParseWord(wordBlocks); if (wordString != string.Empty) { var score = scoreHandler.CalculateScore(wordString); scoreHandler.AddToTotal(score); if (floatingScorePrefab != null) { var transformAt = wordBlocks[0].transform; ShowFloatingScoreText(score, transformAt.transform.TransformPoint(transformAt.position)); FindObjectOfType <AudioManager>().Play("Ding"); } } if (wordBlocks != null && wordBlocks.Count > 0) { wordBlocks.ForEach(x => x.transform.position = new Vector3(100, 100, 0)); wordBlocks.ForEach(x => Destroy(x)); foreach (GameObject blockObject in blockStore.GetAllBlocks()) { if (blockObject != null) { blockObject.layer = 2; blockObject.GetComponent <Block>().CheckCollision(); blockObject.layer = 0; } } } activeBlock.layer = 0; ClearActiveBlock(); } } if (activeBlock == null) { activeBlock = SpawnBlock(); userInputHandler.SetActiveObject(activeBlock); } }