使用C#控制台输出数字雨
无聊时的想法,想用控制台来玩玩黑客帝国中那漂亮的数字雨特效,但是做得超简陋!呵呵!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
namespace ConsoleApplication70
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
char[] number={'0','1',''};
Random rand = new Random(DateTime.Now.Millisecond);
int[] randGreen = new int[rand.Next(10,100)];
for (int i = 0; i < randGreen.Count(); i++)
{
randGreen[i] = rand.Next(5000);
}
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 50; j++)
{
if (randGreen.Any(n => n == (i + 1) * (j + 1)))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(number[rand.Next(3)]);
Console.ForegroundColor = ConsoleColor.DarkGreen;
}
else
{
Console.Write(number[rand.Next(3)]);
}
}
Console.WriteLine();
}
Timer timer = new Timer(100);
timer.Elapsed += (sender, e) =>
{
for (int i = 99; i >=0; i--)
{
Console.MoveBufferArea(0, i, 50, 1, 0, i + 1);
}
Console.MoveBufferArea(0, 100, 50, 1, 0, 0);
};
timer.Start();
while (true)
{
}
}
}
}