Beispiel #1
0
        static void Main(string[] args)
        {
            Game.Start(5);
            Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight);

            Player firstPlayer = new Player(10, 5);
            ComputerPlayer secondPlayer = new ComputerPlayer(10, 5);
            Ball ball = new Ball(Console.WindowWidth / 2, Console.WindowHeight / 2 , true, false, true);

            while (true)
            {
                firstPlayer.Draw();
                secondPlayer.Draw();
                if (!ball.BallIsInField)
                {
                    Game.Over();
                    return;
                }
                // TODO - implement result

                if (Console.KeyAvailable)
                {
                    firstPlayer.Move(Console.ReadKey().Key);
                }

                ClearConsoleBuffer();

                if (firstPlayer.IsPadContainsBall(ball.CoordX, ball.CoordY))
                {
                    if (ball.IsUp && !ball.IsRight)
                    {
                        ball.IsRight = true;
                    }
                    if (!ball.IsUp && !ball.IsRight)
                    {
                        ball.IsRight = true;
                    }
                }

                if (secondPlayer.IsPadContainsBall(ball.CoordX, ball.CoordY))
                {
                    if (ball.IsUp && ball.IsRight)
                    {
                        ball.IsRight = false;
                    }
                    if (!ball.IsUp && ball.IsRight)
                    {
                        ball.IsRight = false;
                    }
                }

                secondPlayer.Move(ball.IsUp);
                ball.Move();
                Thread.Sleep(100);

                Console.Clear();
            }
        }