Umiecie pomoc, bez kitu. W konsoli bo tak mam na zajeciach, i wlasnie o ten algorytm mi chodzilo, bo nie wiem czy mam optymalny.
Dla innych:
using System;
namespace matrix
{
class Program
{
static void Main()
{
Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WindowLeft = Console.WindowTop = 0;
Console.CursorVisible = false;
int szerokosc, wysokosc;
int[] y;
int[] l;
Initialize(out szerokosc, out wysokosc, out y, out l);
int ms;
int i = 0;
while (!Console.KeyAvailable)
{
DateTime t1 = DateTime.Now;
Matrix(szerokosc, wysokosc, y, l);
ms = 40 - (int)((TimeSpan)(DateTime.Now - t1)).TotalMilliseconds;
if (ms > 0)
System.Threading.Thread.Sleep(ms);
i++;
}
}
static bool zmiana = false;
private static void Matrix(int szerokosc, int wysokosc, int[] y, int[] l)
{
int x;
zmiana = !zmiana;
for (x = 0; x < szerokosc; ++x)
{
if (x % 11 == 1)
{
if (!zmiana)
continue;
}
else
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.SetCursorPosition(x, ramka(y[x] - 2 - (l[x] / 17), wysokosc));
Console.Write(znak);
Console.ForegroundColor = ConsoleColor.Green;
}
Console.SetCursorPosition(x, y[x]);
Console.Write(znak);
y[x] = ramka(y[x] + 1, wysokosc);
Console.SetCursorPosition(x, ramka(y[x] - l[x], wysokosc));
Console.Write(' ');
}
}
private static void Initialize(out int szerokosc, out int wysokosc, out int[] y, out int[] l)
{
int h1;
int h2 = (h1 = (wysokosc = Console.WindowHeight) / 2) / 2;
szerokosc = Console.WindowWidth - 1;
y = new int[szerokosc];
l = new int[szerokosc];
int x;
for (x = 0; x < szerokosc; ++x)
{
y[x] = los.Next(wysokosc);
l[x] = los.Next(szerokosc % 30 + wysokosc % 21);
}
}
static Random los = new Random();
static int dlugosc_w = los.Next(200);
static char znak
{
get
{
string text = "<?/.,qwertyuiopasdfghjklmnbvcxz1234567890>;QWERTYUIOPASDFGHJKL:{}[]\\|'ZXCVBNM<?/.,qwertyuiopasdfghjklmnbvcxz1234567890>;uerihfretgrjkrtegelrtjglhiewr4390#$%^$%^#!57943r0p;mfpoup34orjfkhfieqr!@#(&*)*%^$$#$#@#hfe";
if (dlugosc_w == text.Length)
dlugosc_w = los.Next(200);
return text[dlugosc_w++];
}
}
public static int ramka(int k, int wysokosc)
{
k = k % wysokosc;
if (k < 0)
return k + wysokosc;
else
return k;
}
}
}
Nauczcie sie pomagac a nie walic poradami aby nabic posty.