模仿老版本的windows上的夜空屏保代码
using System; class set_cursor2 { int lastnum; private int RandomNumber(int min, int max) { Random random = new Random(); lastnum = random.Next(min, max); if (lastnum%3 == 0 || lastnum%4==0 ) { lastnum = random.Next(min, max); } if (lastnum%5 == 0 || lastnum%6==0 || lastnum%7==0 ) { lastnum = random.Next(min, max); } return lastnum; } static void Main(string[] args) { set_cursor2 obj = new set_cursor2(); int lastrow,lastcol; int i,j,t; Console.ResetColor(); Console.Clear(); Console.SetWindowSize(100,50); Console.BufferHeight = 500; Console.BufferWidth = 200; Console.CursorSize = 50; Console.CursorVisible = true; i = 1; do { j= obj.RandomNumber(1,99); Console.CursorLeft = j; lastcol = j; j= obj.RandomNumber(1,49); lastrow = j; Console.CursorTop = j; if (i%3 == 0) Console.ForegroundColor = ConsoleColor.White; else if (i%4 == 0) Console.ForegroundColor = ConsoleColor.Cyan; else Console.ForegroundColor = ConsoleColor.DarkBlue; if ((i+j) % 2 == 0 || (i+j) % 3 == 0 || (i+j) % 5 == 0) Console.WriteLine(" "); else Console.WriteLine("."); // Console.WriteLine(". {0} {1}",lastrow,lastcol); for(t=0;t<19999999;t++); i++; } while (i<=10000); Console.WriteLine("\n\n Finish"); Console.ReadLine(); } }