void CheckScore() { if (!isServer) { return; } if (ScoreP1 >= MaxScore) { if (OnEndOfGame != null) { OnEndOfGame.Invoke("Player1"); } GameOn = false; BallObj.Off(); } if (ScoreP2 >= MaxScore) { if (OnEndOfGame != null) { OnEndOfGame.Invoke("Player2"); } GameOn = false; BallObj.Off(); } }
/// <summary> /// move figure downm generate new one and finish the game /// </summary> public void MoveFigureDown() { //move figure down by one var isFall = CurrentFigure.MoveDown(GameField); if (isFall == false) { //fill the field with the current figure foreach (var point in CurrentFigure.Position) { GameField[point.Y, point.X] = CurrentFigure.TypeOfCell; } //check for fill rows CheckForFilledRows(); //change next and current figures, show it CurrentFigure = NextFigure; CurrentFigure.ChangeFigurePosition += InvokeRefresh; NextFigure = FigureGenerator.Generate(_startColumn); ChangedNextFigure.Invoke(); ChangedGameField.Invoke(); //check for end of game(can't insert figure in game field) var isEnd = CurrentFigure.IsCorrect(GameField); if (isEnd == false) { OnEndOfGame.Invoke(); } } ChangedGameField.Invoke(); }
public void EndGame(bool victory) { if (gameEnded) { return; // Dont end twice } gameEnded = true; OnEndOfGame?.Invoke(); if (victory) { OnVictory?.Invoke(); } else { OnGameOver?.Invoke(); } TimeManager.Instance.ChangeTimescale(0f); if (endOfGame != null) { StopCoroutine(endOfGame); endOfGame = null; } endOfGame = StartCoroutine(ResetGame()); }