private static Point UpdateLeftRocket(bool isLeftRocketForUpdate, Point newDirection) { Point elementToDelete = new Point(0, 0); if (!isLeftRocketForUpdate) { elementToDelete = PlayerRocketManager.GetElementToDelete(PlayerRocketManager.RightPlayerRocket, newDirection); PlayerRocketManager.UpdateRightPlayerRocket(newDirection); } else { elementToDelete = PlayerRocketManager.GetElementToDelete(PlayerRocketManager.LeftPlayerRocket, newDirection); PlayerRocketManager.UpdateLeftPlayerRocket(newDirection); } ConsolePrinter.DeleteElement(elementToDelete.Y, elementToDelete.X); return(elementToDelete); }
public static void GamePlay(int parsedDifficultyKey, bool areTwoPlayersSelected) { PlayerRocketManager.CreatePlayerRockets(parsedDifficultyKey, areTwoPlayersSelected); if (!areTwoPlayersSelected) { HighScoreManager.ResetPlayerPoints(); } var changeDirection = false; var ballMovementSpeed = (5 * parsedDifficultyKey) + 50; var baseScore = ballMovementSpeed; //default ball starting position var pongBall = new Point(Console.BufferHeight / 2, 1); //default forward and up direction of the pong ball var ballDirection = DirectionManager.GetStartingDirection(); while (true) { ReadPlayersInputKey(areTwoPlayersSelected); var isHittingFirstPlayerRocket = BallBounceValidator.IsHittingPlayerRocket(pongBall, ballDirection, PlayerRocketManager.LeftPlayerRocket); bool isHittingSecondPlayerRocket = false; if (areTwoPlayersSelected) { isHittingSecondPlayerRocket = BallBounceValidator.IsHittingPlayerRocket(pongBall, ballDirection, PlayerRocketManager.RightPlayerRocket); } if ((isHittingFirstPlayerRocket || isHittingSecondPlayerRocket) && changeDirection) { ballMovementSpeed -= (int)0.5; if (!areTwoPlayersSelected) { HighScoreManager.IncreasePlayerScore(baseScore); } else if (BallBounceValidator.IsHittingEdge(pongBall, ballDirection, areTwoPlayersSelected)) { ballDirection = DirectionManager.GetReversedDiagonalDirection(pongBall, ballDirection); } ballDirection = DirectionManager.GetDiagonalDirection(pongBall, ballDirection); } else if (BallBounceValidator.IsHittingBorder(pongBall, ballDirection, areTwoPlayersSelected)) { ballDirection = DirectionManager.GetDiagonalDirection(pongBall, ballDirection); } try { ConsolePrinter.DeleteElement(pongBall.Y, pongBall.X); pongBall = BallManager.MoveBall(pongBall, ballDirection); } catch (GameOverException ex) { if (areTwoPlayersSelected) { ConsolePrinter.PrintGameOverScreen(ex.Message, ex.InnerException.Message); } else { ConsolePrinter.PrintGameOverScreen(ex.Message); } break; } changeDirection = true; ConsolePrinter.PrintPlayerRocket(PlayerRocketManager.LeftPlayerRocket); ConsolePrinter.PrintPongBall(pongBall); if (areTwoPlayersSelected) { ConsolePrinter.PrintPlayerRocket(PlayerRocketManager.RightPlayerRocket); } else { ConsolePrinter.PrintPlayerScore(HighScoreManager.GetPlayerScore); } Thread.Sleep(ballMovementSpeed); } }