private IEnumerator Play() { while (true) { yield return(new WaitForSeconds(0.01f)); if (GameInput.isPressed) { yield return(FindMouseOnBlock()); if (_currentBlock == -1) { continue; } if (RemoveBlockFromList()) { continue; } if (block[_currentBlock].isClicked) { continue; } AddBlockToList(); } else { if (_stackN == 1) { BlockHandler.UndoClick(block[_stack[0]]); } if (_stackN > 1) { yield return(SolveList()); } _stackN = 0; if (!CheckEndGame()) { continue; } yield return(new WaitForSeconds(1.5f)); for (var i = 0; i < 35; ++i) { BlockHandler.ShakePosition(block[i], 1.5f); } yield return(new WaitForSeconds(2f)); Debug.Log("EndGame"); FindObjectOfType <GameScene>().ChangeScene(); break; } } }
private bool RemoveBlockFromList() { if (_stackN <= 1 || _stack[_stackN - 2] != _currentBlock) { return(false); } FindObjectOfType <AudioManager>().Play("Turn"); BlockHandler.UndoClick(block[_stack[_stackN - 1]]); BlockHandler.UndoMatch(_stackN - 1, _stack[_stackN - 2], _stack[_stackN - 1], 0.1f); _stackN--; return(true); }
private IEnumerator SolveList() { FindObjectOfType <AudioManager>().Play("Delete"); for (var i = 1; i < _stackN; ++i) { BlockHandler.DestroyLine(i); var x = _stack[i] / 7; var y = _stack[i] % 7; for (var j = 0; j < i; ++j) { BlockHandler.Move(block[_stack[j]], x, y, 0.08f); } yield return(new WaitForSeconds(0.08f)); } var sum = 0; for (var i = 0; i < _stackN; ++i) { sum += block[_stack[i]].number; } AddScore(sum); var s = 2; var k = 0; while (s <= sum) { s *= 2; } s /= 2; BlockHandler.UndoClick(block[_stack[_stackN - 1]]); for (var i = 0; i < 5; ++i) { var p = 0; var c = 0; for (var j = 0; j < 7; ++j) { var x = i * 7 + j; var y = i * 7 + p; if (!block[x].isClicked) { _tmp = block[x]; block[x] = block[y]; block[y] = _tmp; _down[y] = c; p++; if (x == _stack[_stackN - 1]) { k = y; } } else { BlockHandler.UndoClick(block[x]); c++; } } for (var j = p; j < 7; ++j) { var x = i * 7 + j; BlockHandler.SetNumber(block[x], Rand()); BlockHandler.SetPosition(block[x], i, j + c); _down[x] = c; } } BlockHandler.ChangeNumber(block[k], s); for (var i = 0; i < 35; ++i) { BlockHandler.Move(block[i], i / 7, i % 7, 0.6f); } yield return(null); }