26. tétel: Téglalap felirattal

Feladat: A szöveges képernyőn rajzoljon ki az üres képernyőre egy 20*40-es téglalapot „x” karakterekkel, majd kb. a közepére írassa ki a „Escape = Kilépés” szöveget! A programból Escape karakter lenyomásával lehessen kilépni!
A működő programot és a kódot mutassa be tanárának!

Egy lehetséges megoldás Visual C# nyelven:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 26tetel
{
    class Program
    {
        static void Main(string[] args)
        {
            //26. tétel: Téglalap felirattal
            bool billolvas = false;
            bool kilep = false;
            Console.Clear();
            Console.SetCursorPosition(0, 0);
            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    Console.SetCursorPosition(i, j);
                    if ((i == 0) || (i == 39) || (j == 0) || (j == 19)) Console.Write("x");
                }
            }
            Console.SetCursorPosition(10, 10);
            Console.Write("Escape = Kilépés");
            do
            {
                billolvas = Console.KeyAvailable;
                if (billolvas)
                {
                    ConsoleKeyInfo gomb = Console.ReadKey();
                    if (gomb.Key == ConsoleKey.Escape) kilep = true;
                }
            } while (kilep == false);
            Console.SetCursorPosition(0,22);

            Console.WriteLine("\n\nA program futása véget ért!");
        }
    }
}