當前位置:編程學習大全網 - 源碼下載 - Cc構建遊戲源代碼

Cc構建遊戲源代碼

#包含" stdafx.h "

# include & lt堆棧& gt

使用命名空間std

const int rows = 8,cols = 8;

HINSTANCE hInst

HBITMAP球;

HDChdc,mdc,bufdc

HWNDhWnd

DWORDtPre,tNow

char * str

intnowPos,prePos

boolfind

堆棧& ltint & gt路徑;

int mapIndex[rows*cols] = { 0,2,0,0,0,0,0,0,//材料1 &;#59049;

0,1,0,1,1,1,1,0, ?//素材2 &;#59049;

0,1,0,1,0,1,1,0, ?//素材3 &;#59049;

0,1,0,0,0,1,1,0, ?//素材4 &;#59049;

0,1,1,1,1,1,1,0, ?//素材5 &;#59049;

0,1,0,0,0,0,1,0, ?//素材6 &;#59049;

0,0,1,1,1,1,1,0, ?//素材7 &;#59049;

0,0,0,0,0,0,3,0 };//素材8 &;#59049;

int?記錄[行*列];

ATOMMyRegisterClass(h instance h instance);

BOOLInitInstance(h instance,int);

LRESULT callbackndproc(HWND,UINT,WPARAM,LPARAM);

void mypaint(HDC HDC);

int API entry WinMain(h instance h instance,

?HINSTANCE hPrevInstance,

?LPSTR lpCmdLine,

?int?nCmdShow)

{

味精味精;

MyRegisterClass(h instance);

如果(!InitInstance (hInstance,nCmdShow))?

{

返回FALSE

}

while( msg.message!=WM_QUIT)

{

if(PeekMessage(& amp;msg,NULL,0,0,PM_REMOVE))

{

翻譯消息(& amp味精);

dispatch message(amp;味精);

}

其他

{

tNow = GetTickCount();

if(tNow-tPre & gt;= 100)

my paint(hdc);

}

}

返回msg.wParam

}

//* * * *註冊窗口* * * * * * * * * * * * * * * * * * * * * *

ATOM my register class(h instance h instance)

{

WNDCLASSEX wcex

wcex . CB size = sizeof(WNDCLASSEX);?

wcex . style = CS _ HREDRAW | CS _ VREDRAW;

wcex . lpfnwndproc =(WNDPROC)WNDPROC;

wcex . cbclsextra = 0;

wcex . cbwndextra = 0;

wcex . h instance = h instance;

wcex.hIcon = NULL

wcex.hCursor = NULL

wcex . hcursor = load cursor(NULL,IDC _ ARROW);

wcex . hbrbackground =(HBRUSH)(COLOR _ WINDOW+1);

wcex.lpszMenuName = NULL

wcex . lpsz class name = " canvas ";

wcex . hi consm = NULL;

return register classex(& amp;wcex);

}

//* * * *初始化* * * * * * * * * * * * * * * * * * * * * * * * * * * * *

BOOL InitInstance(h instance h instance,int nCmdShow)

{

HBITMAP bmp

hInst = hInstance

HWnd = CreateWindow("canvas "," maze ",WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);

如果(!hWnd)

{

返回FALSE

}

MoveWindow(hWnd,10,10,430,450,true);

ShowWindow(hWnd,nCmdShow);

更新窗口(hWnd);

hdc = GetDC(hWnd);

MDC = CreateCompatibleDC(hdc);

bufdc = CreateCompatibleDC(hdc);

bmp = CreateCompatibleBitmap(hdc,cols*50,rows * 50);

SelectObject(mdc,BMP);

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);

for(I = 0;我& lt行數*列數;i++)

{

record[I]= mapIndex[I];

rowNum = I/cols;

colNum = i % cols

x = colNum * 50

y = rowNum * 50

SelectObject(bufdc,tile);

如果(!mapIndex[i])

BitBlt(mdc,x,y,50,50,bufdc,0,0,SRCCOPY);

其他

{

if(mapIndex[i] == 2)

{

nowPos = I;

path.push(壹);

記錄[I]= 0;

}

BitBlt(mdc,x,y,50,50,bufdc,0,0,白度);

}

}

prePos = cols * rows+1;

my paint(hdc);

返回TRUE

}

//* * * *核心代碼* * * * * * * * * * * * * * * * * * * * * * * * *

void MyPaint(HDC hdc)

{

int rowNum,colNum

int x,y;

int上、下、左、右;

rowNum = prePos/cols;

colNum = prePos % cols

x = colNum * 50

y = rowNum * 50

SelectObject(bufdc,ball);

BitBlt(mdc,x,y,50,50,bufdc,0,0,白度);

rowNum = nowPos/cols;

colNum = nowPos % cols

x = colNum * 50

y = rowNum * 50

SelectObject(bufdc,ball);

BitBlt(mdc,x,y,50,50,bufdc,0,0,SRCCOPY);

如果(!查找)

{

Str = "迷宮入口";

up = nowPos-cols;

下來?= nowPos+cols;

向左?= now pos-1;

右= nowPos+1;

if(up & gt;= 0 & amp& amp記錄下來)

{

path.push(向上);

記錄[向上]= 0;

prePos = nowPos

nowPos = up

if(mapIndex[nowPos] == 3)

find = true

}

else if(down & lt;=列*行-1 & amp;& amp記錄[下來])?

{

path.push(下);

記錄[向下]= 0;

prePos = nowPos

nowPos = down

if(mapIndex[nowPos] == 3)

find = true

}

else if(left & gt;= rowNum * cols & amp& amp記錄[左])?

{

path.push(左);

記錄[左]= 0;

prePos = nowPos

nowPos = left

if(mapIndex[nowPos] == 3)

find = true

}

else if(right & lt;=(rowNum+1)* cols-1 & amp;& amp記錄[右])?

{

path.push(右);

記錄[右]= 0;

prePos = nowPos

nowPos = right

if(mapIndex[nowPos] == 3)

find = true

}

其他

{

if(path . size()& lt;= 1)//& amp;#59076;& amp#59343;& amp#58864;& amp#58892;

str = " xxxxx

其他

{

path . pop();

prePos = nowPos

now pos = path . top();

}

}

}

其他

{

Str = "找到出口";

}

TextOut(mdc,0,0,str,strlen(str));

BitBlt(hdc,10,10,cols*50,rows*50,mdc,0,0,src copy);

tPre = GetTickCount();

}

//* * * *消息功能* * * * * * * * * * * * * * * * * * * * * * * * * *

LRESULT回調WndProc(HWND hWnd,UINT消息,WPARAM wParam,LPARAM lParam)

{

開關(消息)

{

案例WM_KEYDOWN:

if(wParam==VK_ESCAPE)

PostQuitMessage(0);

打破;

案例WM_DESTROY:

DeleteDC(MDC);

DeleteDC(bufdc);

DeleteObject(球);

ReleaseDC(hWnd,hdc);

PostQuitMessage(0);

打破;

默認值:

返回DefWindowProc(hWnd,message,wParam,lParam);

}

返回0;

}

// ?它能跑嗎?請采納

有不明白的可以聯系我。

這是標準的c++?這就是結果。

這是源代碼?

  • 上一篇:SEO站群優化方案有哪幾種?
  • 下一篇:肥城的公共文化場所於4月20日恢復開放。
  • copyright 2024編程學習大全網