public static void Engine() { while (true) { Ball.HitFirstRacket(); Ball.HitSecondRacket(); Ball.HitWall(); // check if the ball is in on the table Ball.MoveBall(); // move the ball in specific direction if ((Ball.ballDirection == "Left") && (MenuSettings.gameType == "PL1vsPL2")) { Rackets.MoveSecondPlayer(); } else if (Ball.ballDirection == "Right") { Rackets.MoveFirstPlayer(); } else { Rackets.ComputerMoveSecondRacket(); } Rackets.DrawFirstRacket(); Rackets.DrawSecondRacket(); Table.DrawTable(); Thread.Sleep(MenuSettings.gameSpeed); } }
public static void Main() { MenuSettings.Settings(); MenuSettings.IntroScreen(); Rackets.NewService(); Engine(); }
public static void HitWall() { if (ballPositionX <= 1) { Sounds.MakePoints(); // first player scores Table.firstPlayerPoints++; BackToNormalGameSpeedAndDifficulty(); if (Table.CheckSetWon(Table.firstPlayerPoints, Table.secondPlayerPoints)) { // check if set is won (player has at least 15 points and difference in points is more than 1) Table.InitPoints(); Table.firstPlayerSetsWon++; if (Table.CheckGameOver(Table.firstPlayerSetsWon)) { // check if player won 3 sets -> game over Console.SetCursorPosition((Console.WindowWidth / 2) + 6, Console.WindowHeight / 2); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("GAME won by first Player!"); Console.ForegroundColor = ConsoleColor.Gray; Sounds.WinThreeSets(); // Sounds Win Whole Game 10 sec Thread.Sleep(10000); // old value 5000 Environment.Exit(0); } else { Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition((Console.WindowWidth / 2) + 6, Console.WindowHeight / 2); Console.Write("Set won by first Player!"); Console.ForegroundColor = ConsoleColor.Yellow; Console.SetCursorPosition((Console.WindowWidth / 2) + 6, (Console.WindowHeight / 2) + 2); Console.Write("New set will begin in 5 sec..."); Console.ResetColor(); Sounds.Clapping(); // Sounds Set Win 5 sec Thread.Sleep(5000); } } ChangeBallDirX(); Rackets.NewService(); } if (ballPositionX >= Console.WindowWidth - 2) { // second player scores Table.secondPlayerPoints++; Sounds.MakePoints(); BackToNormalGameSpeedAndDifficulty(); if (Table.CheckSetWon(Table.secondPlayerPoints, Table.firstPlayerPoints)) { // check if set is won (player has at least 15 points and difference in points is more than 1) Table.InitPoints(); Table.secondPlayerSetsWon++; if (Table.CheckGameOver(Table.secondPlayerSetsWon)) { // check if player won 3 sets -> game over Console.SetCursorPosition(8, Console.WindowHeight / 2); Console.ForegroundColor = ConsoleColor.Red; Console.Write("GAME won by second Player!"); Console.ForegroundColor = ConsoleColor.Gray; Sounds.WinThreeSets(); // Win Sounds Whole Game 10 sec Thread.Sleep(10000); // old value 5000 Environment.Exit(0); } else { Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(8, Console.WindowHeight / 2); Console.Write("Set won by second Player!"); Console.ForegroundColor = ConsoleColor.Yellow; Console.SetCursorPosition(8, (Console.WindowHeight / 2) + 2); Console.Write("New set will begin in 5 sec..."); Console.ResetColor(); Sounds.Clapping(); // Win Set 5 sec Thread.Sleep(5000); } } ChangeBallDirX(); Rackets.NewService(); } if (ballPositionY <= Table.offset + 1) { Sounds.WallHit(); ChangeBallDirY(); } if (ballPositionY >= Console.WindowHeight - 2) { Sounds.WallHit(); ChangeBallDirY(); } }