资源描述:
《c语言编写的小游戏代码费》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、用vc6.0新建一个Win32Application工程,把附件代码拷贝进去即可。上下左右键控制蛇的方向,空格键用于启动或者停止游戏。上下左右空格键#include#include#include#defineC_W516#defineC_H548//#defineC_W1024//#defineC_H1024#defineGO_RIGHT0x01#defineGO_DOWN0x02#defineGO_LEFT0x03#defineGO_UP0x04#defineSNAKE_NUMBER30typed
2、efstructnode_struct{unsignedchardirection;unsignedcharcnt;}s_node,*s_node_handle;s_nodes_count[SNAKE_NUMBER];typedefstructSNAKE{unsignedcharHead_X;unsignedcharHead_Y;unsignedcharTail_X;unsignedcharTail_Y;unsignedcharh_index;unsignedchart_index;unsignedcharfood_state;unsignedcharsc
3、ore;unsignedcharsnake_state;}Snake_Data,*Snake_Data_handle;Snake_Datasnk_1;#defineMAP_X64#defineMAP_Y64unsignedchargame_map[MAP_Y][MAP_X];LRESULTCALLBACKWin_tetris_Proc(HWNDhwnd,//handletowindowUINTuMsg,//messageidentifierWPARAMwParam,//firstmessageparameterLPARAMlParam//secondmes
4、sageparameter);intWINAPIWinMain(HINSTANCEhInstance,//handletocurrentinstanceHINSTANCEhPrevInstance,//handletopreviousinstanceLPSTRlpCmdLine,//commandlineintnCmdShow//showstate){snk_1.Head_X=0x01;//headxsnk_1.Head_Y=0x00;//headysnk_1.Tail_X=0x00;//tailxsnk_1.Tail_Y=0x00;//tailysnk_
5、1.h_index=0;snk_1.t_index=0;snk_1.food_state=0;snk_1.score=0;snk_1.snake_state=1;s_count[snk_1.h_index].cnt=2;s_count[snk_1.h_index].direction=GO_RIGHT;s_count[snk_1.t_index].cnt=2;s_count[snk_1.t_index].direction=GO_RIGHT;WNDCLASSwndcls;wndcls.cbClsExtra=0;wndcls.cbWndExtra=0;wnd
6、cls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndcls.hInstance=hInstance;wndcls.lpfnWndProc=Win_tetris_Proc;wndcls.lpszClassName="Game_tetris";wndcls.lpszMenuName=NULL;wndcls.style=CS_HRE
7、DRAW
8、CS_VREDRAW;RegisterClass(&wndcls);//Game_TetrisHWNDhwnd;hwnd=CreateWindow("Game_tetris","Game_Snake(http://blog.ednchina.com/zook0k/)",WS_OVERLAPPEDWINDOW&~WS_MAXIMIZEBOX&~WS_MINIMIZEBOX&~WS_THICKFRAME,0,0,C_W,C_H,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,SW_SHOWNORMAL);//ini
9、tialsnakeHDChdc;hdc=GetDC(hwnd);H