1樓:匿名使用者
#include "stdafx.h"
#include
using namespace std;
const int rows = 8,cols = 8;
hinstance hinst;
hbitmap ball;
hdc hdc,mdc,bufdc;
hwnd hwnd;
dword tpre,tnow;
char *str;
int nowpos,prepos;
bool find;
stackpath;
int mapindex[rows*cols] = ; //材8
int record[rows*cols];
atom myregisterclass(hinstance hinstance);
bool initinstance(hinstance, int);
lresult callback wndproc(hwnd, uint, wparam, lparam);
void mypaint(hdc hdc);
int apientry winmain(hinstance hinstance,
hinstance hprevinstance,
lpstr lpcmdline,
int ncmdshow)
msg msg;
myregisterclass(hinstance);
if (!initinstance (hinstance, ncmdshow))
return false;
while( msg.message!=wm_quit )
translatemessage( &msg );
dispatchmessage( &msg );
else
tnow = gettickcount();
if(tnow-tpre >= 100)
mypaint(hdc);
return msg.wparam;
//****註冊視窗*************************
atom myregisterclass(hinstance hinstance)
wndclas*** wcex;
wcex.cbsize = sizeof(wndclas***);
wcex.style = cs_hredraw | cs_vredraw;
wcex.lpfnwndproc = (wndproc)wndproc;
wcex.cbcl***tra = 0;
wcex.cbwndextra = 0;
wcex.hinstance = hinstance;
wcex.hicon = null;
wcex.hcursor = null;
wcex.hcursor = loadcursor(null, idc_arrow);
wcex.hbrbackground = (hbrush)(color_window+1);
wcex.lpszmenuname = null;
wcex.lpszclassname = "canvas";
wcex.hiconsm = null;
//****初始化*************************************
bool initinstance(hinstance hinstance, int ncmdshow)
hbitmap bmp;
hinst = hinstance;
cw_usedefault, 0, cw_usedefault, 0, null, null, hinstance, null);
if (!hwnd)
return false;
movewindow(hwnd,10,10,430,450,true);
showwindow(hwnd, ncmdshow);
updatewindow(hwnd);
hdc = getdc(hwnd);
mdc = createcompatibledc(hdc);
bufdc = createcompatibledc(hdc);
bmp = createcompatiblebitmap(hdc,cols*50,rows*50);
selectobject(mdc,bmp);
hbitmap tile;
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;irecord[i] = mapindex[i];
rownum = i / cols;
colnum = i % cols;
x = colnum * 50;
y = rownum * 50;
selectobject(bufdc,tile);
if(!mapindex[i])
bitblt(mdc,x,y,50,50,bufdc,0,0,srccopy);
else
if(mapindex[i] == 2)
nowpos = i;
path.push(i);
record[i] = 0;
bitblt(mdc,x,y,50,50,bufdc,0,0,whiteness);
prepos = cols * rows + 1;
mypaint(hdc);
return true;
//****核心***********************************
void mypaint(hdc hdc)
int rownum,colnum;
int x,y;
int up,down,left,right;
rownum = prepos / cols;
colnum = prepos % cols;
x = colnum * 50;
y = rownum * 50;
selectobject(bufdc,ball);
bitblt(mdc,x,y,50,50,bufdc,0,0, whiteness);
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);
if(!find)
str = "迷宮入口";
up = nowpos - cols;
down = nowpos + cols;
left = nowpos - 1;
right = nowpos + 1;
if(up>=0 && record[up])
path.push(up);
record[up] = 0;
prepos = nowpos;
nowpos = up;
if(mapindex[nowpos] == 3)
find = true;
else if(down<=cols*rows-1 && record[down])
path.push(down);
record[down] = 0;
prepos = nowpos;
nowpos = down;
if(mapindex[nowpos] == 3)
find = true;
else if(left>=rownum*cols && record[left])
path.push(left);
record[left] = 0;
prepos = nowpos;
nowpos = left;
if(mapindex[nowpos] == 3)
find = true;
else if(right<=(rownum+1)*cols-1 && record[right])
path.push(right);
record[right] = 0;
prepos = nowpos;
nowpos = right;
if(mapindex[nowpos] == 3)
find = true;
else
if(path.size() <= 1) //
str = "***xx";
else
path.pop();
prepos = nowpos;
nowpos = path.top();
else
str = "找到出口";
textout(mdc,0,0,str,strlen(str));
bitblt(hdc,10,10,cols*50,rows*50,mdc,0,0,srccopy);
tpre = gettickcount();
//****訊息函式***********************************
lresult callback wndproc(hwnd hwnd, uint message, wparam wparam, lparam lparam)
switch (message)
case wm_keydown:
if(wparam==vk_escape)
postquitmessage(0);
break;
case wm_destroy:
deletedc(mdc);
deletedc(bufdc);
deleteobject(ball);
releasedc(hwnd,hdc);
postquitmessage(0);
break;
default:
return defwindowproc(hwnd, message, wparam, lparam);
return 0;
// 可以執行 請採納
有不懂的可以聯絡我
這個可是標準c++的 這是結果
這是源**
家裡有老鼠怎麼辦?如何治走老鼠,家裡有老鼠怎麼辦,怎麼把老鼠驅趕出去?
準備個容器,倒入大米加入一勺蜂蜜,一勺白糖,擠一點洗衣液。最後倒入適量的白酒,攪拌均勻後,把多餘的白酒倒掉。在你碗中倒入適量的食用油。攪拌一下,放在老鼠經常出沒的地方,老鼠滅光光。家裡老鼠多,又髒又煩,教你滅鼠妙招,家裡再也沒老鼠 逮捕老鼠神器,用了它家裡更安全。安全滅鼠六法 一 水泥滅鼠 將大米 ...
小志傳奇幻境迷宮怎麼走終極BOSS在哪
幻境迷宮一至四層,都是比較好走的。因為每層之間都會有傳送到下一層的傳送口,而且地圖介面都會標明,大家找起來會非常容易。當大家來到第四層後,你就會發現這裡貌似已到盡頭了,因為這些再也找不到任何傳送口。其實不是的,玩家第四層找到屍王出現的深坑,通過這個深坑,就能進入到幻境迷宮五層。玩家進入幻境迷宮五層,...
冒險島緋紅迷宮3怎麼走,冒險島緋紅怎麼去
圖為迷宮地圖的編號,但是地圖內的傳送門開關是隨機的,而且每隔一段時間會變化。需要反覆嘗試向著你要到達的地圖位置走就能到達目的地。有時候1 2 3就ok了,不過有時候2到3走不通,你可能就要通過1 5 9 10 11 7 3這種很多彎路的走法 這兩種完全是舉例,不是實際走法,實際走法需要嘗試 每個傳送...