【vc++精品源码栏目提醒】:网学会员为广大网友收集整理了,vc 俄罗斯方块源码 - 讲义教程,希望对大家有所帮助!
文件一///////////////////stdafx.cpp/////////////////////////// stdafx.cpp : source file that includes just the standard includes// ToyBricks.pch will be the pre-compiled header// stdafx.obj will contain the pre-compiled type informationinclude stdafx.h// TODO: reference any additional headers you need in STDAFX.H// and not in this fil文件二//////////////////////////////////////stdafx.h//////////////////////////////////////////// stdafx.h : include file for standard system include files// or project specific include files that are used frequently but// are changed infrequently//if definedAFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_defineAFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_if _MSC_VER 1000pragma onceendif // _MSC_VER 1000define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headersinclude// TODO: reference additional headers your program requires here//AFX_INSERT_LOCATION// Microsoft Visual C will insert additional declarations immediately before theprevious line.endif// definedAFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_文件三/////////////////////////////////game.cpp////////////////////////////////////////////////////// ToyBricks.cpp : Defines the entry point for the application.//include StdAfx.h//include //windows.h 文件中包含应用程序中所需的数据类型和数据结构的定义include //包含 SetTimer、KillTimer等关于定时器的函数includedefine CELL 15 // 【方格】的边长pixdefine W 20 // 游戏区宽12个【方格】边长8个格子用来绘制下一个方块define H 26 // 游戏区高26个【方格】边长define MS_NEWBLOCK WM_USER1 // 消息 ID,产生新的【方块】define MS_DRAW WM_USER2 // 消息 ID,用来画【方块】define MS_NEXTBLOCK WM_USER3 //消息 ID,用来显示下一个【俄罗斯方块】形状//------------------------窗口函数的说明------------------------LRESULT CALLBACK WndProc HWND UINT WPARAM LPARAM//---------------------------------------------------------------int WINAPI WinMain HINSTANCE hInstance HINSTANCE hPrevInstance PSTR szCmdLine int iCmdShow static char AppNameToyBrick //窗口类名 HWND hwnd MSG msg //消息结构 WNDCLASSEX wndclass //窗口类 int iScreenWide //定义一个整型变量来取得窗口的宽度 wndclass.cbSize sizeofwndclass wndclass.style CS_HREDRAWCS_VREDRAW//窗口类型 //CS_HREDRAW :Redraws the entire window if a movement or size // adjustment changes the width of the clientarea. //CS_VREDRAW :Redraws the entire window if a movement or size // adjustment changes the height of the clientarea. wndclass.lpfnWndProc WndProc //窗口处理函数为 WndProc wndclass.cbClsExtra 0 //窗口类无扩展 wndclass.cbWndExtra 0 //窗口实例无扩展 wndclass.hInstance hInstance //当前实例句柄 wndclass.hIcon LoadIcon NULL IDI_APPLICATION //默认图标 wndclass.hCursor LoadCursor NULLIDC_ARROW //箭头光标 wndclass.hbrBackground HBRUSHGetStockObject WHITE_BRUSH //背景为黑色 wndclass.lpszMenuName NULL //窗口中无菜单 wndclass.lpszClassName AppName //类名为ToyBrick wndclass.hIconSm LoadIcon NULL IDI_APPLICATION//----------------------------------窗口类的注册----------------------------------------- ifRegisterClassEx wndclass //如果注册失败则发出警报声音,返回 FALSE MessageBeep0 return FALSE // 获取显示器分辨率的 X 值 iScreenWide,将程序窗口置于屏幕中央iScreenWideGetSystemMetrics SM_CXFULLSCREENhwnd CreateWindow AppName //窗口类名 俄罗斯方块模拟项目软件学院.钱彦江 //窗口实例的标题名 WS_MINIMIZEBOXWS_SYSMENU //窗口的风格 iScreenWide/2-WCELL/2 //窗口左上角横坐标X CELL //窗口左上角纵坐标Y WCELL //窗口的宽 HCELL //窗口的高 NULL //窗口无父窗口 NULL //窗口无主菜单 hInstance //创建此窗口的应用程序的当前句柄 NULL //不使用该值 ifhwnd return FALSE //显示窗口ShowWindow hwndiCmdShow//绘制用户区UpdateWindow hwndMessageBoxhwnd 开始游戏nn_软件学院模拟项目开始MB_OKSendMessagehwndMS_NEWBLOCK00 SetTimer hwnd 1 500NULL //消息循环 while GetMessage msg NULL 0 0 TranslateMessage msg DispatchMessage msg //消息循环结束即程序终止时将消息返回系统 return msg.wParam// 函数 DrawRact: 画【正方形】----- □// 参数: 设备环境句柄和【正方形】的四角坐标void DrawRect HDC hdc int l int t int r int b MoveToEx hdc l t NULL //将光标移动到lt LineTo hdc r t LineTo hdc r b LineTo hdc l b LineTo hdc lt// 函数 DrawCell: 画【方格】-----红色■// 参数: 设备环境句柄和【方格】的四角坐标void DrawCell HDC hdc int l int t int r int b HBRUSH hbrush hbrushCreateSolidBrushRGB25500 // 红色画刷 SelectObjecthdchbrush Rectanglehdcl t r b DeleteObject hbrush//绘出游戏区域的方格,其中包括游戏空间和显示下一个【方块】空间//此函数包含在 Cover 函数中。上一篇:VC++数字图像处理源程序及详解之1(灰度直方图)