资源描述:
《俄罗斯方块C++控制台源代码》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、d:cpp_code方块方块方块.cpp1//方块.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#include#include#include#include#includeclassConsole{public:Console(){hStdOutput=INVALID_HANDLE_VALUE;hStdError=INVALID_HANDLE_VALUE;}boolOpen(void){hStdOutput=GetSt
2、dHandle(STD_OUTPUT_HANDLE);hStdError=GetStdHandle(STD_ERROR_HANDLE);returnINVALID_HANDLE_VALUE!=hStdOutput&&INVALID_HANDLE_VALUE!=hStdError;}inlineboolSetTitle(char*title)//设置标题{returnTRUE==SetConsoleTitle(title);}boolRemoveCursor(void)//去处光标{CONSOLE_CURSOR_INFOcci;if(!GetConsole
3、CursorInfo(hStdOutput,&cci))returnfalse;cci.bVisible=false;if(!SetConsoleCursorInfo(hStdOutput,&cci))returnfalse;if(!GetConsoleCursorInfo(hStdError,&cci))returnfalse;cci.bVisible=false;if(!SetConsoleCursorInfo(hStdError,&cci))returnfalse;returntrue;}boolSetWindowRect(shortx,short
4、y)//设置窗体尺寸{SMALL_RECTwrt={0,0,x,y};if(!SetConsoleWindowInfo(hStdOutput,TRUE,&wrt))returnfalse;if(!SetConsoleWindowInfo(hStdError,TRUE,&wrt))returnfalse;returntrue;}boolSetBufSize(shortx,shorty)//设置缓冲尺寸{COORDcoord={x,y};if(!SetConsoleScreenBufferSize(hStdOutput,coord))returnfalse;
5、if(!SetConsoleScreenBufferSize(hStdError,coord))returnfalse;returntrue;}boolGotoXY(shortx,shorty)//移动光标{COORDcoord={x,y};if(!SetConsoleCursorPosition(hStdOutput,coord))returnfalse;if(!SetConsoleCursorPosition(hStdError,coord))returnfalse;returntrue;}boolSetColor(WORDcolor)//设置前景色
6、/背景色{if(!SetConsoleTextAttribute(hStdOutput,color))returnfalse;if(!SetConsoleTextAttribute(hStdError,color))returnfalse;returntrue;}boolOutputString(constchar*pstr,size_tlen=0)//输出字符串{DWORDn=0;returnTRUE==WriteConsole(hStdOutput,pstr,len?len:strlen(pstr),&n,NULL);}d:cpp_code方块
7、方块方块.cpp2boolOutputStringNoMove(shortx,shorty,constchar*pstr,size_tlen=0)//输出字符串{COORDcoord={x,y};DWORDn=0;returnTRUE==WriteConsoleOutputCharacter(hStdOutput,pstr,len?len:strlen(pstr),coord,&n);}private:HANDLEhStdOutput;HANDLEhStdError;};constcharbg[]="┏━━━━━━━━━━━┓""┃■■■■■■■■■■
8、■┃←↓→↑""┃■■■■■■■■■■■┃Begin:F8""┃■■■■■■■■