Código fuente de limpieza del laberinto móvil
# include & ltstack>
Usar espacio de nombres std
const int rows = 8, cols = 8
<; p>HINSTANCE hInstbola HBITMAP;
HDChdc, mdc, bufdc
HWNDhWnd
DWORDtPre, tNow
p>char * str
intnowPos, prePos
boolfind
stack<int>path;
int mapIndex[ filas*cols] = { 0 , 2, 0, 0, 0, 0, 0, 0, //Material 1
0,1,0,1,1,1, 1,0, ?//Material 2
0,1,0,1,0,1,1,0, ?//Material 3
0,1,0 ,0,0,1,1,0, ?//Material 4
0,1,1,1,1,1,1 ,0, ?//Material 5 & ;#59049;
0,1,0,0,0,0,1,0, ?//Material 6
0,0,1, 1,1,1,1,0, ?//Material 7
0,0,0,0,0,0,3, 0 };//Material 8 &; #59049;
int? Registro[fila*columna];
ATOMMyRegisterClass(h instancia h instancia);
BOOLInitInstance(h instancia, int);
LRESULT callbackndproc(HWND, UINT , WPARAM, LPARAM);
void mypaint(HDC HDC);
int entrada API WinMain(h instancia h instancia,
?HINSTANCE hPrevInstance, p>
p>
? LPSTR lpCmdLine,
? nCmdShow)
MSG MSG;
MyRegisterClass(instancia h);
¿Si (!InitInstance (hInstance, nCmdShow))?
{
Devuelve FALSO
}
mientras(msg.message!=WM_QUIT)
{
if(PeekMessage(& msg, NULL, 0, 0, PM_REMOVE))
{
Traducir mensaje(& msg);
mensaje de envío(amp;MSG);
}
Otros
{
tNow = GetTickCount();
if(tNow-tPre & gt; = 100)
mi pintura(hdc);
}
}
Return msg.wParam
}
//* * * *Ventana de registro* * * * * * * * * * * * * * * * * * * * * * *
ATOM mi clase de registro (instancia h instancia h)
{
WNDCLASSEX wcex
wcex tamaño CB = tamaño de(WNDCLASSEX);?
wcex .style = CS _ HREDRAW | CS _ VREDRAW
wcex . p>
p>
wcex cbwndextra = 0;
wcex h instancia = h instancia;
wcex.hIcon = NULL
wcex.hCursor = NULL
wcex . hcursor = cargar cursor(NULL, IDC _ ARROW);
wcex = (HBRUSH)(COLOR _ WINDOW+1); p>
wcex.lpszMenuName = NULL
wcex .lpsz nombre de clase = "lienzo"
wcex hi consm = NULL; classex(& amp; wcex);
}
//* * * *Inicialización* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
BOOL InitInstance(h instancia h instancia, int nCmdShow)
{
HBITMAP bmp
hInst = hInstance
HWnd = CreateWindow("lienzo", "laberinto", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
Si (!hWnd)
{
Devuelve FALSO
}
MoverVentana(hWnd, 10, 10, 430, 450, verdadero);
ShowWindow(hWnd, nCmdShow);
Ventana de actualización (hWnd);
hdc = GetDC(hWnd);
MDC = CreateCompatibleDC(hdc);
bufdc = CreateCompatibleDC(hdc);
bmp = CreateCompatibleBitmap(hdc, cols*50, filas * 50);
SelectObject(mdc, BMP);
Mosaico HBITMAP;
int rowNum, colNum
int i, x, y;
tile = (HBITMAP)LoadImage(NULL, "tile.bmp",IMAGE_BITMAP,50,50,LR_LOADFROMFILE);
ball = (HBITMAP)LoadImage(NULL, "ball.bmp ",IMAGE_BITMAP , 50, 50, LR_LOADFROMFILE);
para (I = 0; i<número de filas * número de columnas; i++)
{
registro[I]= mapIndex[I];
rowNum = I/cols;
colNum = i % columnas
x = colNum * 50
y = filaNum * 50
SelectObject(bufdc,tile);
if (!mapIndex[i])
BitBlt(mdc, x, y, 50, 50, bufdc, 0, 0, SRCCOPY);
Otro
{
if(mapIndex [i] == 2)
{
nowPos = I;
ruta.push(一);
Registro [I ]= 0;
}
BitBlt(mdc, x, y, 50, 50, bufdc, 0, 0, blancura
}< / p>
}
prePos = cols * filas+1;
mi pintura(hdc
Devuelve VERDADERO
}
//* * * *Código principal* * * * * * * * * * * * * * * * * * * * * * * * * *
void MyPaint(HDC hdc)
{
int númerofila, númerocol
int x, y;
int arriba, abajo, izquierda, Derecha;
rowNum = prePos/cols;
colNum = prePos % cols
x = colNum * 50
y = filaNum * 50
SelectObject(bufdc, ball);
BitBlt(mdc, x, y, 50, 50, bufdc, 0, 0, blancura);
numfila = nowPos/cols;
numcol = nowPos % cols
x = numcol * 50
y = numfila * 50
SeleccionarObjeto (bufdc, ball);
BitBlt(mdc, x, y, 50, 50, bufdc, 0, 0, SRCCOPY);
If (! Find)
{
Str = "Entrada al laberinto";
arriba = nowPos-cols;
¿Abajo? = nowPos+cols;
¿Izquierda? = ahora pos-1;
right = ahoraPos+1;
if(arriba>= 0&&grabado)
{ p>
ruta .push(arriba);
record[arriba] = 0;
prePos = nowPos
nowPos = arriba
if(mapIndex [nowPos] == 3)
find = true
}
else if(abajo & lt;=columna*fila- 1&&record[abajo] )?
{
ruta.push(abajo);
Registro[abajo] = 0;
prePos = nowPos
nowPos = abajo
if(mapIndex[nowPos] == 3)
find = true
}
else if(left>= rowNum * cols&&record[izquierda])?
{
ruta.push(izquierda);
Registro[izquierda] = 0;
prePos = nowPos
nowPos = left
if(mapIndex[nowPos] == 3)
find = true
}
si no (derecha<=(rowNum+1)* cols-1&&record[right])?
{
ruta.push(derecha);
Registro[derecha] = 0;
prePos = nowPos
nowPos = right
if(mapIndex[nowPos] == 3)
find = true
}
Otro
{
if(ruta . tamaño()<= 1)//& amp;#59076;& amp#59343;& amp#58864;& amp#58892; /p>
str = " xxxxx
Otro
{
ruta . pop();
prePos = nowPos
ahora pos = ruta . top();
}
}
}
Otros
p>
{
Str = "Salida encontrada";
}
TextOut(mdc, 0, 0, str, strlen (str)) ;
BitBlt(hdc, 10, 10, columnas*50, filas*50, mdc, 0, 0, copia src
tPre = GetTickCount()); ;
}
//* * * *Función de mensaje* * * * * * * * * * * * * * * * * * * * * * * * * *
Devolución de llamada LRESULT WndProc(HWND hWnd, mensaje UINT, WPARAM wParam, LPARAM lParam)
{
Cambiar (mensaje)
{
Caso WM_KEYDOWN:
if(wParam==VK_ESCAPE)
PostQuitMessage(0);
Romper;
Caso WM_DESTROY:
DeleteDC(MDC);
DeleteDC(bufdc);
DeleteObject(ball); (hWnd, hdc) ;
PostQuitMessage(0);
Break;
Valor predeterminado:
Devolver DefWindowProc(hWnd, mensaje , wParam, lParam) ;
}
Devuelve 0;
}
// ?¿Se puede ejecutar? Por favor adopte
Si no entiende, por favor contácteme.
¿Es este C++ estándar? Este es el resultado.
¿Es este el código fuente?