using System;
using System.Collections.Generic;
using System.Text;

namespace Pong
{
    class Program
    {
        public const int HOEHE = 25;
        public const int BREITE = 80;
        public const int PADDLE = 5;

        public static int[,] Bildschirm = new int[BREITE, HOEHE];
        public static char Ballground = ' ';

        static void Main(string[] args)
        {
            Tennisplatz(BREITE,HOEHE);
            Play();
            
               
               
               Console.ReadLine();
            
        }

        static void PrintCharAt(int x, int y, ConsoleColor Farbe, char Zeichen)
        {
            Console.SetCursorPosition(x, y);
            Console.ForegroundColor = Farbe;
            Console.Write(Zeichen);
            Bildschirm[x, y] = Zeichen;
        }
        static char GetCharAt(int x, int y)
        {
            return (char)Bildschirm[x,y];
        }
        static void Tennisplatz(int x, int y)
        {
            for (int i = 0; i < x; i++)
                {
                 PrintCharAt(i, 0, ConsoleColor.White, '#');
                 PrintCharAt(i, y-1, ConsoleColor.White, '#');
                  
                }
            for (int i = 0; i < y; i += 2)
                {
                 PrintCharAt(x/2, i, ConsoleColor.White, '|');
            
                } 
        
         
        }
        static void PaddleDraw(int x, int y)
        {
            for (int i = y; i < y+PADDLE; i++)
                {
                    PrintCharAt(x, i, ConsoleColor.Yellow, '8');

                }
        
        }
        static void Play()
        {
            int paddleleft  =   (HOEHE - PADDLE) / 2;
            int paddleright =   (HOEHE - PADDLE) / 2;
            int Ballx       =   BREITE / 2;
            int Bally       =   HOEHE / 2;
            int Ballvecx    =   1;
            int Ballvecy    =   1;
            int Scoreleft   =   0;
            int Scoreright  =   0;


            BallDraw(Ballx, Bally, true);
            for ( ; ; )
                {
                    System.Threading.Thread.Sleep(50);
                    if (Console.KeyAvailable)
                        {
                            ConsoleKeyInfo Key = Console.ReadKey(true);
                            switch (Key.KeyChar)
                            { 
                                case 'w':
                                    if(paddleleft > 1)
                                        {
                                        paddleleft -= 1;
                                        PrintCharAt(0, paddleleft + PADDLE,ConsoleColor.Black , ' ');
                                        }
                                        break;
                                case 's':
                                    if (paddleleft < HOEHE-PADDLE-1)
                                        {
                                        PrintCharAt(0, paddleleft, ConsoleColor.Black, ' ');
                                        paddleleft += 1;
                                        
                                        }
                                        break;
                                case 'o':
                                    if(paddleright > 1)
                                        {
                                        paddleright -= 1;
                                        PrintCharAt(BREITE-1, paddleright+ PADDLE,ConsoleColor.Black , ' ');
                                        }
                                        break;
                                case 'l':
                                    if (paddleright < HOEHE - PADDLE - 1)
                                        {
                                        PrintCharAt(BREITE - 1, paddleright, ConsoleColor.Black, ' ');
                                        paddleright += 1;
                                        }
                                        break;
                             
                            }
                            
                        }
                PaddleDraw(0, paddleleft);
                PaddleDraw(BREITE - 1, paddleright);




                BallDraw(Ballx, Bally, false);
                Ballx += Ballvecx;
                Bally += Ballvecy;
                if (GetCharAt(Ballx,Bally) == '#')
                {
                    Ballvecy *= -1;
                    Bally += Ballvecy;
                }
                if (GetCharAt(Ballx, Bally) == '8')
                {
                    Ballvecx *= -1;
                    Ballx += Ballvecx;
                }
                if (Ballx >= BREITE - 1)
                {
                    Scoreleft++; // Score +1 left

                    System.Threading.Thread.Sleep(1500);
                    Ballx = BREITE / 2;
                    Bally = HOEHE / 2;
                    Ballvecx = -1;
                    Ballvecy = 1;
                    
                }
                if (Ballx < 1)
                {
                    Scoreright++;
                    // Score +1 right

                    System.Threading.Thread.Sleep(1500);
                    Ballx = BREITE / 2;
                    Bally = HOEHE / 2;
                    Ballvecx = 1;
                    Ballvecy = 1;
                }
                PrintCharAt(BREITE / 2 - 3, 3, ConsoleColor.Magenta, (char)(Scoreleft + '0'));
                PrintCharAt(BREITE / 2 + 3, 3, ConsoleColor.Magenta, (char)(Scoreright + '0'));
                BallDraw(Ballx, Bally, true);
            }        
        }
        static void BallDraw(int x, int y, bool show)
        {
            if (show)
            {
                Ballground = GetCharAt(x, y);

                PrintCharAt(x, y, ConsoleColor.Cyan, 'o');
                // PrintCharAt(x + 1, y, ConsoleColor.Cyan, ')');

            }
            else
            {
                PrintCharAt(x, y, ConsoleColor.White, Ballground);
               // PrintCharAt(x + 1, y, ConsoleColor.Black, ' ');

            }
        
        
        }

    }

} // Z�ch :)


syntax highlighted by Code2HTML, v. 0.9.1