Witam!
Pisze program losujący losowe znaki i wyswietlajacy je w petli for
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Threading;
namespace Matrixx
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green; // kolor tekstu w konsoli
Random rnd = new Random(); // generator losowych znaków
int los = rnd.Next(256); // <o,9
Console.WriteLine((char)los);
int h = rnd.Next(5, 15);
int x = rnd.Next(40);
int y = rnd.Next(40);
ConsoleKeyInfo info = Console.ReadKey();
for (info = Console.ReadKey(); info.Key != ConsoleKey.Escape; info = Console.ReadKey())
{
for (int i = 0; i < h; i++)
{
char znak = (char)rnd.Next(256);
Console.SetCursorPosition(x, y);
Console.WriteLine(znak);
Thread.Sleep(100);
h++;
}
}
Console.ReadLine();
}
}
}
Chciałbym aby po kliknieciu klawisza ESCAPE zatrzymało dzialanie pętli.
ConsoleKeyInfo info = Console.ReadKey();
if (info.Key == ConsoleKey.Escape)
{
Console.WriteLine("You pressed escape!");
}
Jakos kombinuje w ten sposób ale może wiecie jak to zrobic inaczej i lepiej? Ewentualnie co tutaj jest zle?
Pozdrawiam i prosze o pomoc