请教如何用win32的GDI做一迷宫,路径要有动画效果 请教如何用win32的GDI做一迷宫,路径要有动画效果最好是这样:迷宫不要太复杂用递归算法找到路径,然后用<list>模板保存路径最后用windows的GDI做出迷宫的效果哪位GG帮帮忙或者发一个到谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #include <windows.h>const int n=6; void check(int a[n][n],int i,int j)//i,j下标 { if(i>=0 && i+1<n && j>=0 && j+1<n && a[i][j] == 0) { cout<<i<<","<<j<<endl; a[i][j] = -1; check(a,i+1,j); check(a,i-1,j); check(a,i,j+1); check(a,i,j-1); }} int initmap() { int a[n][n]={{0,0,1,1,1}, //0是路,1是障碍物 {1,0,0,0,1}, {0,1,0,1,1}, {0,0,0,0,1}, {1,1,1,0,0}}; check(a,0,0); return 0; }路径如何用动画显示出来GG能不能帮帮忙啊 #include <windows.h>#include <stdio.h>#include <list>using namespace std;int b[6][6] = {0};void check(int a[6][6],int i,int j)//i,j下标 { if(i>=0 && i+1<6 && j>=0 && j+1<6 && a[i][j] == 0) { a[i][j] = -1; check(a,i+1,j); check(a,i-1,j); check(a,i,j+1); check(a,i,j-1); }} void drawmap(HWND hwnd,HDC hdc){ RECT rect; GetClientRect(hwnd, &rect); int x = 0; int y = 0; for(int j=0;j<=5;++j) { MoveToEx(hdc,x+50*j,y,NULL); LineTo(hdc,x+50*j,y+250); } for(int j=0;j<=5;++j) { MoveToEx(hdc,x,y+50*j,NULL); LineTo(hdc,x+250,y+50*j); } RECT rct; HBRUSH hbrush = CreateSolidBrush(RGB(0,0,0)); int a[6][6]={{0,0,1,1,1}, //0是路,1是障碍物 {1,0,0,0,1}, {0,1,0,1,1}, {0,0,0,0,1}, {1,1,1,0,0}}; check(a,0,0); for (int i=0;i<6;++i) { for(int j=0;j<6;++j) { if(a[i][j] == 1) { rct.left = x+50*j; rct.top = y+50*i; rct.right = x+50*(j+1); rct.bottom = y+50*(i+1); FillRect(hdc,&rct,hbrush); } } } DeleteObject(hbrush);}LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg, WPARAM wParam,LPARAM lParam);//申明函数HWND hwnd;int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow ) { WNDCLASS wndcls;//窗口类实例 wndcls.cbClsExtra=0; wndcls.cbWndExtra=0; wndcls.hbrBackground=(HBRUSH)GetStockObject(LTGRAY_BRUSH); wndcls.hCursor=LoadCursor(NULL,IDC_CROSS); wndcls.hIcon=(HICON)LoadImage(hInstance,"game.ico",IMAGE_ICON,0,0,LR_LOADFROMFILE); wndcls.hInstance=hInstance; wndcls.lpfnWndProc=WinSunProc; wndcls.lpszClassName="Jerry2007"; wndcls.lpszMenuName=NULL; wndcls.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; if(!RegisterClass(&wndcls)) { MessageBox(NULL,TEXT("This is error!"),"Jerry2007",MB_ICONWARNING); return 0; } hwnd=CreateWindow("Jerry2007","晨风之安魂曲",WS_OVERLAPPEDWINDOW,0,0,260,280,NULL,NULL,hInstance,NULL); if(!hwnd) return false; ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); MSG msg;//消息实例 while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0;}LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){ PAINTSTRUCT ps; HDC hdc; RECT rect; HBRUSH hbrush_path; static bool begindrawpath = false; switch(uMsg) { case WM_CREATE: SetTimer(hwnd, 1, 1000, NULL) ; break; case WM_COMMAND: break; case WM_TIMER: break; case WM_LBUTTONDOWN: // 左键单击动画开始 break; case WM_PAINT: hdc = BeginPaint(hwnd,&ps); drawmap(hwnd, hdc); EndPaint(hwnd,&ps); break; case WM_CLOSE: if(IDYES==MessageBox(hwnd,"是否真的结束?","Jerry",MB_YESNO)) { DestroyWindow(hwnd); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0;}动画显示路径。动画那块怎么做啊各位GG,迷宫我已经绘出,就是动画显示路径,教教我啊,谢谢了。 error C2659 有关Direct3D编程的问题,盼高手赐教 非模态对话框 一个控件问题,请高手指教,在线等待 求上传ftp服务器的示例代码(讨论有分) 有关OpenGl贴图? 各位大哥帮个忙啊,谁可以告诉我一个现在还可以申请免费空间的地方,只支持html就行了。谢谢了!(无内容) 哪位兄台能告之小弟怎么窃获拨号网络中客户端动态分配的IP地址 如何能在VC++中实现自动拨号? 单文档程序里面使用CMFCPropertySheet问题 单文档多视图问题 读取资源的问题(资源的ID以字符串形式存放)
void check(int a[n][n],int i,int j)//i,j下标
{
if(i>=0 && i+1<n && j>=0 && j+1<n && a[i][j] == 0)
{
cout<<i<<","<<j<<endl;
a[i][j] = -1;
check(a,i+1,j);
check(a,i-1,j);
check(a,i,j+1);
check(a,i,j-1);
}
}
int initmap()
{
int a[n][n]={{0,0,1,1,1}, //0是路,1是障碍物
{1,0,0,0,1},
{0,1,0,1,1},
{0,0,0,0,1},
{1,1,1,0,0}};
check(a,0,0);
return 0;
}
路径如何用动画显示出来
GG能不能帮帮忙啊
#include <stdio.h>
#include <list>
using namespace std;
int b[6][6] = {0};
void check(int a[6][6],int i,int j)//i,j下标
{
if(i>=0 && i+1<6 && j>=0 && j+1<6 && a[i][j] == 0)
{
a[i][j] = -1;
check(a,i+1,j);
check(a,i-1,j);
check(a,i,j+1);
check(a,i,j-1);
}
} void drawmap(HWND hwnd,HDC hdc)
{
RECT rect;
GetClientRect(hwnd, &rect);
int x = 0;
int y = 0; for(int j=0;j<=5;++j)
{
MoveToEx(hdc,x+50*j,y,NULL);
LineTo(hdc,x+50*j,y+250);
}
for(int j=0;j<=5;++j)
{
MoveToEx(hdc,x,y+50*j,NULL);
LineTo(hdc,x+250,y+50*j);
} RECT rct;
HBRUSH hbrush = CreateSolidBrush(RGB(0,0,0));
int a[6][6]={{0,0,1,1,1}, //0是路,1是障碍物
{1,0,0,0,1},
{0,1,0,1,1},
{0,0,0,0,1},
{1,1,1,0,0}};
check(a,0,0);
for (int i=0;i<6;++i)
{
for(int j=0;j<6;++j)
{
if(a[i][j] == 1)
{
rct.left = x+50*j;
rct.top = y+50*i;
rct.right = x+50*(j+1);
rct.bottom = y+50*(i+1);
FillRect(hdc,&rct,hbrush);
}
}
}
DeleteObject(hbrush);
}LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg, WPARAM wParam,LPARAM lParam);//申明函数
HWND hwnd;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow )
{
WNDCLASS wndcls;//窗口类实例
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(LTGRAY_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=(HICON)LoadImage(hInstance,"game.ico",IMAGE_ICON,0,0,LR_LOADFROMFILE);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="Jerry2007";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
if(!RegisterClass(&wndcls))
{
MessageBox(NULL,TEXT("This is error!"),"Jerry2007",MB_ICONWARNING);
return 0;
} hwnd=CreateWindow("Jerry2007","晨风之安魂曲",WS_OVERLAPPEDWINDOW,0,0,260,280,NULL,NULL,hInstance,NULL);
if(!hwnd)
return false; ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); MSG msg;//消息实例
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
HBRUSH hbrush_path;
static bool begindrawpath = false; switch(uMsg)
{
case WM_CREATE:
SetTimer(hwnd, 1, 1000, NULL) ;
break; case WM_COMMAND:
break;
case WM_TIMER:
break;
case WM_LBUTTONDOWN: // 左键单击动画开始
break;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
drawmap(hwnd, hdc);
EndPaint(hwnd,&ps); break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","Jerry",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0); break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
动画显示路径。动画那块怎么做啊各位GG,迷宫我已经绘出,就是动画显示路径,教教我啊,谢谢了。