void Update() { List <NodePiece> finishedUpdating = new List <NodePiece>(); for (int i = 0; i < update.Count; i++) { NodePiece piece = update[i]; if (!piece.UpdatePiece()) { finishedUpdating.Add(piece); } } for (int i = 0; i < finishedUpdating.Count; i++) { NodePiece piece = finishedUpdating[i]; FlippedPieces flip = GetFlipped(piece); NodePiece flippedPiece = null; int x = (int)piece.index.x; fills[x] = Mathf.Clamp(fills[x] - 1, 0, width); List <Point> connected = isConnected(piece.index, true); bool wasFlipped = (flip != null); if (wasFlipped) { flippedPiece = flip.GetOtherPiece(piece); AddPoints(ref connected, isConnected(flippedPiece.index, true)); } if (connected.Count == 0) { if (wasFlipped) { FlipPieces(piece.index, flippedPiece.index, false); } } else { foreach (Point pnt in connected) { KillPiece(pnt); Node node = GetNodeAtPoint(pnt); NodePiece nodePiece = node.GetPiece(); if (nodePiece != null) { nodePiece.gameObject.SetActive(false); dead.Add(nodePiece); } node.SetPiece(null); } ApplyGravityToBoard(); } flipped.Remove(flip); update.Remove(piece); } }
void Update() { if (gameFinished == false) { List <NodePiece> finishedUpdating = new List <NodePiece>(); timerText.text = "Time: " + timeRemaining.ToString(); if (score >= targetScore) { gameFinished = true; CancelInvoke(nameof(UpdateMatch3Game)); resultsPanel.SetActive(true); audioSource.clip = audioClips[1]; audioSource.Play(); Debug.Log("Game Complete - You Win!"); } for (int i = 0; i < update.Count; i++) { NodePiece piece = update[i]; if (piece.UpdatePiece() == false) { finishedUpdating.Add(piece); } } for (int i = 0; i < finishedUpdating.Count; i++) { NodePiece piece = finishedUpdating[i]; FlippedPieces flip = GetFlipped(piece); NodePiece flippedPiece = null; int x = (int)piece.index.x; fills[x] = Mathf.Clamp(fills[x] - 1, 0, width); List <Point> connected = IsConnected(piece.index, true); bool wasFlipped = (flip != null); // If flipped make this update if (wasFlipped) { flippedPiece = flip.GetOtherPiece(piece); AddPoints(ref connected, IsConnected(flippedPiece.index, true)); } // If match wasn't made if (connected.Count == 0) { // If flipped if (wasFlipped) { FlipPieces(piece.index, flippedPiece.index, false); // Flip pieces back } } else // If match is made { // Remove the node pieces that are connected foreach (Point p in connected) { KillPiece(p); Node node = GetNodeAtPoint(p); NodePiece nodePiece = node.GetPiece(); if (nodePiece != null) { nodePiece.gameObject.SetActive(false); dead.Add(nodePiece); } node.SetPiece(null); } audioSource.clip = audioClips[0]; audioSource.Play(); ApplyGravityToBoard(); } // Remove the flip after update flipped.Remove(flip); update.Remove(piece); } } }
private void Update() { List <NodePiece> finishedUpdating = new List <NodePiece>(); for (int i = 0; i < _update.Count; i++) { NodePiece piece = _update[i]; if (!piece.UpdatePiece()) { finishedUpdating.Add(piece); } } for (int i = 0; i < finishedUpdating.Count; i++) { NodePiece piece = finishedUpdating[i]; FlippedPieces flip = GetFlipped(piece); NodePiece flippedPiece = null; int x = piece.index.x; _fills[x] = Mathf.Clamp(_fills[x] - 1, 0, Width); List <Point> connected = IsConnected(piece.index, true); bool wasFlipped = flip != null; if (wasFlipped) { flippedPiece = flip.GetOtherPiece(piece); AddPoints(ref connected, IsConnected(flippedPiece.index, true)); } if (connected.Count == 0) { if (wasFlipped) { FlipPieces(piece.index, flippedPiece.index, false); } } else { foreach (Point p in connected) { KillPiece(p); Node node = GetNodeAtPoint(p); NodePiece nodePiece = node.GetPiece(); if (nodePiece != null) { nodePiece.gameObject.SetActive(false); _dead.Add(nodePiece); _score += 10; highScore -= 10; scoreText.text = _score.ToString(); levelScoreText.text = "Ты набрал " + _score + " очков!"; if (highScore <= 0) { gameOverPanel.SetActive(true); } } node.SetPiece(null); } ApplyGravityToBoard(); } _flipped.Remove(flip); _update.Remove(piece); } }
//*******Aktív fázis******* //Változások kezelése void Update() { if (battleManager.GetBattleState() == BattleState.PlayerTurn) { //Mozgások szerint a pozíciók frissítése List <Piece> finishedUpdatingList = new List <Piece>(); for (int i = 0; i < updatePieceList.Count; i++) { Piece piece = updatePieceList[i]; if (!piece.UpdatePiece()) { finishedUpdatingList.Add(piece); } } for (int i = 0; i < finishedUpdatingList.Count; i++) { Piece piece = finishedUpdatingList[i]; FlippedPieces flip = GetFlipped(piece); Piece flippedPiece = null; //Simább piece esés int x = (int)piece.positionInGrid.x; fills[x] = Mathf.Clamp(fills[x] - 1, 0, width); List <Point> listOfConnectedPoints = IsConnected(piece.positionInGrid, true); bool wasFlipped = (flip != null); //Ha volt flip az update előtt megnézzük, hogy lett-e match if (wasFlipped) { flippedPiece = flip.GetOtherPiece(piece); IncludePoints(ref listOfConnectedPoints, IsConnected(flippedPiece.positionInGrid, true)); } //Ha nem lett match if (listOfConnectedPoints.Count == 0) { if (wasFlipped) //Visszacsinaljuk a flippet { FlipPieces(piece.positionInGrid, flippedPiece.positionInGrid, false); } } //Ha match lett else { //Eltávolítja a listában szereplő pontokat foreach (Point pointInConnection in listOfConnectedPoints) { GridCell cell = GetCellAtPoint(pointInConnection); Piece tempPiece = cell.GetPieceFromCell(); if (tempPiece != null) { tempPiece.gameObject.SetActive(false); usedPieceList.Add(tempPiece); //Növeljük az adott típus counterét ScoreController.IncreasePoints(tempPiece.typeValue - 1); battleManager.Attack(tempPiece.typeValue - 1); } //Kinullázzuk az adott cellához tartozó piece-t cell.AddPieceToCell(null); //Lyuk keletkezett, szóval hívjuk a gravitációt ApplyGravityToColumn(cell.positionOfCell.x); } battleManager.ChangeTurn(); } //Eltakarítjuk a pontokat mikor már végeztünk velük flippedPieceList.Remove(flip); updatePieceList.Remove(piece); } } else if (battleManager.GetBattleState() == BattleState.EnemyTurn) { int random = UnityEngine.Random.Range(1, 3); for (int i = 0; i < random; i++) { battleManager.Attack(); } battleManager.ChangeTurn(); } }