问题描述
如题。小妹苦苦求高人帮助,c#源代码的最好。
解决方案
解决方案二:
从大大富翁抄来的usesWindows,Messages;constSnowNumber=500;//雪点数量-1typeSnowNode=recordPoint:TPoint;//雪点位置Color:Integer;//先前颜色Speed:Integer;//下落速率nMove:Integer;//下落距离Stick:Integer;//'粘连'度end;varSnowNodes:array[0..SnowNumber]ofSnowNode;//雪点数组hTimer:Integer;//'随机风向'时钟句柄CrWind:Integer;//当前风向(-1~1)CrStep:Integer;//当前循环步数(用于限速)ScreenWidth,ScreenHeight:Integer;//屏幕尺寸//取屏幕尺寸->ScreenWidth,ScreenHeightprocedureGetScreenSize;beginScreenWidth:=GetSystemMetrics(SM_CXSCREEN);ScreenHeight:=GetSystemMetrics(SM_CYSCREEN);end;//初始化雪点数组procedureInitSnowNodes;varhScreenDc,J:Integer;beginhScreenDc:=CreateDC('DISPLAY',nil,nil,nil);forJ:=0toSnowNumberdobeginSnowNodes[J].Point.X:=Random(ScreenWidth);SnowNodes[J].Point.Y:=Random(ScreenHeight);SnowNodes[J].Color:=GetPixel(hScreenDc,SnowNodes[J].Point.X,SnowNodes[J].Point.Y);SnowNodes[J].Speed:=Random(5)+1;//几次循环作下落一次(1~5)SnowNodes[J].nMove:=Random(SnowNodes[J].Speed)+1;//每次下落距离(1~5)SnowNodes[J].Stick:=30-Random(SnowNodes[J].Speed);//'粘连'度end;DeleteDC(hScreenDc);end;//'随机风向'时钟procedureTimerProc(hWnd:HWND;uMsg:UINT;idEvent:UINT;dwTime:DWORD);stdcall;beginSetTimer(0,hTimer,(Random(27)+4)*500,@TimerProc);//重设下次风向改变时间if(CrWind<>0)thenCrWind:=0elseCrWind:=Random(3)-1;//修改风向end;//移动雪点procedureMoveSnowNodes;varhScreenDc,I,X,Y:Integer;beginhScreenDc:=CreateDC('DISPLAY',nil,nil,nil);forI:=0toSnowNumberdobegin//控制雪点下降速率if(CrStepmodSnowNodes[I].Speed)<>0thenContinue;//恢复上次被覆盖点ifGetPixel(hScreenDc,SnowNodes[I].Point.X,SnowNodes[I].Point.Y)=$FFFFFFthenSetPixel(hScreenDc,SnowNodes[I].Point.X,SnowNodes[I].Point.Y,SnowNodes[I].Color);//根据风向作随机飘落X:=SnowNodes[I].Point.X+Random(3)-1+CrWind;Y:=SnowNodes[I].Point.Y+SnowNodes[I].nMove;//积雪(停留)效果处理SnowNodes[J].Stickif((CrStepmodSnowNodes[I].Stick)=0)//降低积雪概率..and(GetPixel(hScreenDc,X,Y)<>GetPixel(hScreenDc,X,Y+1))//'边缘'判断and(GetPixel(hScreenDc,X-1,Y)<>GetPixel(hScreenDc,X-1,Y+1))and(GetPixel(hScreenDc,X+1,Y)<>GetPixel(hScreenDc,X+1,Y+1))thenbegin//稍微调整坐标ifGetPixel(hScreenDc,X,Y-1)=GetPixel(hScreenDc,X,Y-2)thenDec(Y)//上边缘elseifGetPixel(hScreenDc,X,Y+1)=GetPixel(hScreenDc,X,Y+2)thenInc(Y);//下边缘Inc(X,CrWind);//画三个点表示雪花SetPixel(hScreenDc,X,Y,$FFFFFF);SetPixel(hScreenDc,X+1,Y+1,$FFFFFF);SetPixel(hScreenDc,X-1,Y+1,$FFFFFF);//重生雪点SnowNodes[I].Point.Y:=Random(10);SnowNodes[I].Point.X:=Random(ScreenWidth);SnowNodes[I].Color:=GetPixel(hScreenDc,SnowNodes[I].Point.X,SnowNodes[I].Point.Y);endelsebeginif(X<0)or(X>ScreenWidth)or(Y>ScreenHeight)then//超出范围则重生雪点beginSnowNodes[I].Point.Y:=Random(10);SnowNodes[I].Point.X:=Random(ScreenWidth);SnowNodes[I].Color:=GetPixel(hScreenDc,SnowNodes[I].Point.X,SnowNodes[I].Point.Y);endelsebegin//保存颜色并绘制雪点SnowNodes[I].Color:=GetPixel(hScreenDc,X,Y);SetPixel(hScreenDc,X,Y,$FFFFFF);//此时保存新雪点位置SnowNodes[I].Point.X:=X;SnowNodes[I].Point.Y:=Y;end;end;end;DeleteDC(hScreenDc);CrStep:=CrStep+1;end;varThreadMsg:TMsg;//标准消息结构体Frequency:Int64;//高性能定时器频率StartCt,EndCt:Int64;//高性能定时器计数ElapsedTime:Extended;//时间间隔beginGetScreenSize;//预置屏幕范围InitSnowNodes;//初始化雪点数组QueryPerformanceFrequency(Frequency);//高性能定时器频率hTimer:=SetTimer(0,0,Random(5)*500,@TimerProc);//安装随机风向定时器RegisterHotKey(0,0,MOD_CONTROL,ORD('L'));//注册退出热键Ctrl+LwhileTRUEdo//消息循环beginQueryPerformanceCounter(StartCt);//执行运算前计数值ifPeekMessage(ThreadMsg,0,0,0,PM_REMOVE)then//取到消息begincaseThreadMsg.messageofWM_TIMER:TimerProc(0,0,0,0);//取到时钟消息说明时间已到WM_HOTKEY:beginKillTimer(0,hTimer);//删除随机风向定时器UnregisterHotKey(0,0);//删除退出热键Ctrl+LInvalidateRect(0,nil,TRUE);//刷新屏幕Break;//跳出消息循环end;WM_DISPLAYCHANGE:beginGetScreenSize;//重新取屏幕范围InitSnowNodes;//初始化雪点数组end;end;end;MoveSnowNodes;//移动雪点QueryPerformanceCounter(EndCt);//执行运算后计数值ElapsedTime:=(EndCt-StartCt)/Frequency;if(ElapsedTime<0.0005)thenSleep(3)//限制循环速度elseif(ElapsedTime<0.0010)thenSleep(2)elseif(ElapsedTime<0.0015)thenSleep(1);end;end.
解决方案三:
贴在dpr中编译成exe,运行就可以了
解决方案四:
sorry,弄错地方了,不好意思当我没说