måndag 12 november 2012

C# Matrix Look a like snippet

Made this yesterday if i remember right, i where really bored. Most people rank Matrix as one off the best "geek movies". How ever i have only seen small part off it, and the only thin i remember is the matrix effect, and the name Neo.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
/*http://alexanderrasch.blogspot.se/ */
static void Main(string[] args)
{
bool bRun = true;
Console.Title = "Dem0 By Alexander Rasch";
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Wake up... Follow the White Rabbit");
//Sleep 512 ms
System.Threading.Thread.Sleep(512);
while (bRun == true)
{
int iRand = 1;
for (int i = 0; i < 14; i++)
{
Console.WriteLine(GetRandomString(iRand));
iRand++;
System.Threading.Thread.Sleep(5 * iRand);
Console.Clear();
}
//Check
if (iRand > 14)
{
bRun = false;
Console.WriteLine("AlexanderRasch".ToUpper());
}
}
//End
Console.ReadLine();
}
//Need to "get" a random char
public static readonly Random _rRandom = new Random();
public static string GetRandomString(int iLength)
{
//Very bad when people use ""; String.Empty is the way to go.
string szOut = string.Empty;
//Make it look more "real" only having char used in message
//CharArray, it's single char
char[] arr_cChars = "ACDENRST".ToCharArray();
//While lenght off message lower then iLenght run one more time
while (szOut.Length < iLength)
{
//Add 1 char from chararray to szOut
szOut += arr_cChars[_rRandom.Next(0, arr_cChars.Length)];
}
//Give out szOut
return szOut;
}
}
}
view raw gistfile1.cs hosted with ❤ by GitHub

Inga kommentarer:

Skicka en kommentar