void ClickLogic(Transform er) { _chanimation.IdleSwitch = 0f; if (!_gameOver) { bool death = er.name.Contains("Death"); if (!death) { int eger = 0; bool parsed = int.TryParse(er.name, out eger); if (parsed) { death = eger > _counter + 1; Debug.Log(eger + " = " + death + " | " + (_counter + 1)); } } if (death) { Debug.Log("<color=red>YOU DIED</color>"); er.GetChild(0).gameObject.SetActive(false); er.GetChild(1).gameObject.SetActive(true); GameOver(); } else { Togglinger togglinger = er.GetComponentInChildren <Togglinger>(); togglinger.enabled = false; TextMesh en = er.GetComponentInChildren <TextMesh>(); if (!en.transform.GetComponent <MeshRenderer>().enabled) { Debug.Log("<color=red>YOU DIED</color>"); er.GetChild(1).gameObject.SetActive(true); GameOver(); return; } else { --_activePieces; ++_counter; er.GetChild(0).GetComponent <MeshRenderer>().enabled = false; er.GetComponentInChildren <Collider>().enabled = false; en.color = _goodColour; en.text = "V"; float timer = Time.timeSinceLevelLoad - _scoreTimer; Debug.Log("KLYKK'D ON: " + er.name + " | " + _activePieces + " of " + _activePiecesList.Count + " pieces left!\n" + timer); bool streak = _activePiecesList.Count > 0 && timer < 2f; if (streak) { Debug.Log("STREAKING!"); ++_streakCount; _currentScore += 10 * (int)(_activePiecesList.Count - _activePieces); streakRoutine = Streaking(); StartCoroutine(streakRoutine); animationRoutine = AnimateHer(4); StartCoroutine(animationRoutine); _streak.text = _streakCount.ToString(); } else { _streakCount = 0; _currentScore += 10; } _score.text = _currentScore.ToString(); _scoreTimer = Time.timeSinceLevelLoad; _system.transform.position = er.position; _system.Play(); if (_activePieces == 0) { AdvanceLevel(); } else { _activePiecesList.Remove(er.gameObject); if (_currentLevel >= (int)((float)_maxLevels * 0.25f) && Random.Range(0f, 1f) <= 0.25f) { rotateRoutine = RotateBoard(); StartCoroutine(rotateRoutine); return; } else if (_currentLevel >= (int)((float)_maxLevels * 0.15f) && Random.Range(0f, 1f) <= 0.25f) { flipRoutine = FlipBoard(); StartCoroutine(flipRoutine); return; } else if (_currentLevel >= (int)((float)_maxLevels * 0.07f) && _activePiecesList.Count == 2 && Random.Range(0f, 1f) <= 0.75f) { for (int c = 0; c < _activePiecesList.Count; ++c) { GameObject et = _activePiecesList[c]; animationRoutine = AnimateHer(3); StartCoroutine(animationRoutine); TextMesh text = et.GetComponentInChildren <TextMesh>(); text.text = c == 0 ? "!" : "?"; } } if (_currentLevel >= (int)((float)_maxLevels * 0.1f) && _activePiecesList.Count > 2 && Random.Range(0f, 1f) <= 0.25f) { IEnumerable <int> numbers = Enumerable.Range(_counter + 1, _activePiecesList.Count); IOrderedEnumerable <int> shuffle = numbers.OrderBy(a => _random.NextDouble()); List <int> egers = shuffle.ToList(); if (animationRoutine != null && _awaiting) { StopCoroutine(animationRoutine); _awaiting = false; } animationRoutine = AnimateHer(3); StartCoroutine(animationRoutine); for (int c = 0; c < _activePiecesList.Count; ++c) { int eger = egers[c]; GameObject et = _activePiecesList[c]; et.name = eger.ToString(); et.transform.GetChild(0).GetChild(0).gameObject.SetActive(true); TextMesh text = et.GetComponentInChildren <TextMesh>(); text.text = eger == 3 ? ":" + eger.ToString() : eger.ToString(); } } } } } } }
void SetupBoard(int size = 5, bool reset = true) { if (size <= 0 || size > 5) { return; } Debug.Log("SETTING UP BOARD"); CleanupBoard(); _activePiecesList.Clear(); _deathPiecesList.Clear(); _activePieces = _streakCount = _counter = 0; _streak.text = _streakCount.ToString(); _scoreTimer = 0f; _boardForm.transform.eulerAngles = Vector3.zero; _boardForm.localScale = Vector3.one; if (streakRoutine != null && _streaking) { StopCoroutine(streakRoutine); _streaking = false; _streakMaterial.color = Color.white; } if (reset) { _resetButton.SetActive(false); _boardForm.position = Vector3.zero; _bigTextForm.position = new Vector3(0f, -5.5f, 0f); _chanimation.MagicNumber = 0; _camerae.backgroundColor = new Color32(0xCC, 0xCC, 0xCC, 0xFF); _gameOver = false; _currentScore = _streakCount = 0; _currentLevel = _currentLevel >= _checkPointLevel ? _checkPointLevel : 1; _bigText.text = _bigTextSub.text = null; StopAllCoroutines(); } _score.text = _currentScore.ToString(); _level.text = _currentLevel.ToString(); float theSize = (size * size); float weight = theSize * 1.618f; float theCalculation = ((float)(_currentLevel < weight ? weight : _currentLevel) / (float)_maxLevels); Debug.Log("<b>The calculation is:</b> " + theCalculation + " | " + ((float)_currentLevel / (float)_maxLevels) + " != " + (weight / (float)_maxLevels) + " | " + weight); for (int c = 0; c < size; ++c) { for (int e = 0; e < size; ++e) { GameObject et = Instantiate(_piece); et.name = "Piece" + c + "-" + e; et.SetActive(true); Transform er = et.transform; er.parent = _board.transform; Vector3 position = Vector3.zero; position.x = ((size + 0.2f) * ((float)c / (float)size)) + (Mathf.Abs(er.localPosition.x - 0.6f) * (1f - ((float)size) / 5f)); position.y = -((size + 0.2f) * ((float)e / (float)size)) - (Mathf.Abs(er.localPosition.y + 0.6f) * (1f - ((float)size) / 5f)); er.localPosition += position; float eger = 1f - Random.Range((float)_deathPiecesList.Count / (float)theSize, 1f); //Debug.Log(eger + " | death: " + _deathPiecesList.Count + " | size: " + theSize); if (eger >= theCalculation && _deathPiecesList.Count < theSize) { er.name = "Death-" + c.ToString() + "-" + e.ToString(); _deathPiecesList.Add(et); eger = Random.Range(0f, 1f); if (_currentLevel >= (int)((float)_maxLevels * 0.05f) && _deathPiecesList.Count >= 3 && eger <= 0.333f) { TextMesh text = et.transform.GetComponentInChildren <TextMesh>(); if (text) { text.text = ((int)Random.Range(1, theSize)).ToString(); text.color = new Color32(0xCC, 0x33, 0x33, 0xFF); } er.GetChild(0).GetComponent <MeshRenderer>().enabled = false; er.GetComponentInChildren <Togglinger>().enabled = false; } else { er.GetChild(0).gameObject.SetActive(false); } } else { ++_activePieces; _activePiecesList.Add(et); } } } if (_activePieces == 0) { GameObject et = _boardForm.GetChild((int)Random.Range(0, _boardForm.childCount - 1)).gameObject; Debug.Log("Found: " + et.name); et = et.transform.GetChild(0).gameObject; et.SetActive(true); Debug.Log("Activated " + et.name + ": " + et.activeSelf); et.GetComponent <MeshRenderer>().material = StartMaterial; ++_activePieces; TextMesh text = et.transform.GetComponentInChildren <TextMesh>(); if (text) { text.text = _activePieces.ToString(); } else { Debug.LogError("FOUND NOT THE TEXT FOR " + et.name); } et = et.transform.parent.gameObject; et.name = _activePieces.ToString(); _deathPiecesList.Remove(et); _activePiecesList.Add(et); Debug.Log("FIXED? " + et.name); } else { IEnumerable <int> numbers = Enumerable.Range(1, _activePiecesList.Count); IOrderedEnumerable <int> shuffle = numbers.OrderBy(a => _random.NextDouble()); List <int> egers = shuffle.ToList(); for (int c = 0; c < _activePiecesList.Count; ++c) { int eger = egers[c]; GameObject et = _activePiecesList[c]; et.name = eger.ToString(); TextMesh text = et.GetComponentInChildren <TextMesh>(); text.text = eger == 3 ? ":" + eger.ToString() : eger.ToString(); if (eger == 1) { //text.color = StartMaterial.color; et.transform.GetComponent <MeshRenderer>().material = StartMaterial; } Togglinger togglinger = et.GetComponentInChildren <Togglinger>(); togglinger.enabled = _currentLevel >= (int)((float)_maxLevels * 0.03f) && Random.Range(0f, 1f) <= 0.25; //if(eger == _activePiecesList.Count) { //text.color = EndMaterial.color; } } } }