static int firstPlayerPadSize = 4;
static int secondPlayerPadSize = 4;
static int ballPositionX = 5;
static int ballPositionY = 5;
static bool ballDirectionUp = true;
static bool ballDirectionRight = false;
static int firstPlayerPosition = 0;
static int secondPlayerPosition = 0;
static int firstPlayerResult = 0;
static int secondPlayerResult = 0;
static Random rand = new Random();
static void removeScrollBars()
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BufferHeight = Console.WindowHeight;
Console.BufferWidth = Console.WindowWidth;
static void drawFirstPlayer()
for (int y = firstPlayerPosition; y < firstPlayerPosition + firstPlayerPadSize; y++)
PrintAtPosition(0, y, '|');
PrintAtPosition(1, y, '|');
static void PrintAtPosition(int x, int y, char symbol)
Console.SetCursorPosition(x, y);
static void drawSecondPlayer()
for (int y = secondPlayerPosition; y < secondPlayerPosition + secondPlayerPadSize; y++)
PrintAtPosition(Console.WindowWidth - 1, y, '|');
PrintAtPosition(Console.WindowWidth - 2, y, '|');
static void SetInitialPositions()
firstPlayerPosition = Console.WindowHeight / 2 - firstPlayerPadSize / 2;
secondPlayerPosition = Console.WindowHeight / 2 - secondPlayerPadSize / 2;
SetBallAtTheMiddleOfTheGameField();
static void SetBallAtTheMiddleOfTheGameField()
ballPositionX = Console.WindowWidth / 2;
ballPositionY = Console.WindowHeight / 2;
PrintAtPosition(ballPositionX, ballPositionY,'@');
static void PrintResult()
Console.SetCursorPosition(Console.WindowWidth / 2 - 1, 0);
Console.WriteLine("{0}-{1}", firstPlayerResult, secondPlayerResult);
static void MoveFirstPlayerUp()
if (firstPlayerPosition > 0)
static void MoveFirstPlayerDown()
if (firstPlayerPosition < Console.WindowHeight - firstPlayerPadSize)
static void MoveSecondPlayerUp()
if (secondPlayerPosition > 0)
static void MoveSecondPlayerDown()
if (secondPlayerPosition < Console.WindowHeight - secondPlayerPadSize)
static void SecondPlayerAIMove()
int randomNumber = randomGenerator.Next(1,101);
if (ballDirectionUp == true)
if (ballPositionY == Console.WindowHeight - 1)
if (ballPositionX == Console.WindowWidth - 1)
SetBallAtTheMiddleOfTheGameField();
ballDirectionRight = false;
Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
Console.WriteLine("First player wins!");
SetBallAtTheMiddleOfTheGameField();
ballDirectionRight = true;
Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
Console.WriteLine("Second player wins!");
if (ballPositionY >= firstPlayerPosition && ballPositionY < firstPlayerPosition + firstPlayerPadSize)
ballDirectionRight = true;
if (ballPositionX >= Console.WindowWidth - 3 - 1)
if (ballPositionY >= secondPlayerPosition && ballPositionY < secondPlayerPosition + secondPlayerPadSize)
ballDirectionRight = false;
public static void Main()
if (Console.KeyAvailable)
ConsoleKeyInfo keyInfo = Console.ReadKey();
if (keyInfo.Key == ConsoleKey.UpArrow)
if (keyInfo.Key == ConsoleKey.DownArrow)