为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

俄罗斯方块源代码

2017-09-27 9页 doc 23KB 21阅读

用户头像

is_348501

暂无简介

举报
俄罗斯方块源代码俄罗斯方块源代码 #include #include #include #define GAME_MAIN_WIDTH 10 #define GAME_MAIN_HEIGHT 20 #define GAME_INFO_WIDTH 4 #define INFO_BLOCK_TOP 1 #define INFO_SPEED_TOP INFO_BLOCK_TOP + 6 #define INFO_SCORE_TOP INFO_SPEED_TOP + 3 #define BLOCK_LENGTH 4 struc...
俄罗斯方块源代码
俄罗斯方块源代码 #include #include #include #define GAME_MAIN_WIDTH 10 #define GAME_MAIN_HEIGHT 20 #define GAME_INFO_WIDTH 4 #define INFO_BLOCK_TOP 1 #define INFO_SPEED_TOP INFO_BLOCK_TOP + 6 #define INFO_SCORE_TOP INFO_SPEED_TOP + 3 #define BLOCK_LENGTH 4 struct Block { int len; int background[BLOCK_LENGTH][BLOCK_LENGTH]; }; struct Block blocks[7]; HANDLE g_hIn; HANDLE g_hOut; const int GAME_INFO_LEFT = (GAME_MAIN_WIDTH + 2 + 1) * 2 ; void GotoXY(int x,int y); void DrawFrame(int x,int y,int width,int height); //打印分数 void PrintScore(int score); //打印速度 void PrintSpeed(int speed); //指定区域清屏 void ClearWindow(int x,int y,int width,int height); //根据消行数量计算分数 void CalculateScore(int count,int *pscore); //增加速度 int InscreaseSpeed(int score); void GotoXY(int x,int y) { COORD pos = {x,y}; SetConsoleCursorPosition(g_hOut,pos); } void DrawFrame(int x,int y,int width,int height) { int i; //COORD pos = {2,0}; GotoXY(x,y); printf("?"); for (i = 0;i < width;i++) { printf("?"); } //wchar_t //FillConsoleOutputCharacterW(g_hOut,0x2501,20,pos,NULL) ; printf("?"); for (i = 1;i <=height;i++) { GotoXY(x,y+i); printf("?"); GotoXY(x + (width +1) * 2,y+i); printf("?"); } GotoXY(x,y+i); printf("?"); for (i = 0;i < width;i++) { printf("?"); } printf("?"); } void PrintScore(int score) { ClearWindow(GAME_INFO_LEFT,INFO_SCORE_TOP + 1,GAME_INFO_WIDTH,1); GotoXY(GAME_INFO_LEFT,INFO_SCORE_TOP + 1); printf("%d",score); } void PrintSpeed(int speed) { ClearWindow(GAME_INFO_LEFT,INFO_SPEED_TOP + 1,GAME_INFO_WIDTH,1); GotoXY(GAME_INFO_LEFT,INFO_SPEED_TOP + 1); printf("%d",speed); } void ClearWindow(int x,int y,int width,int height) { // int i,j; // for (i = 0; i < height;i++) // { // GotoXY(x,y+i); // for (j = 0; j< width;j++) // { // printf(" "); // } // } int row; COORD pos = {x,y}; for (row = 0; row < height; row++) { pos.Y = y + row; FillConsoleOutputCharacter(g_hOut,' ',width * 2,pos,NULL); } } void CalculateScore(int count,int *pscore) { switch (count) { case 1: *pscore += 10; break; case 2: (*pscore) += 30; break; case 3: *pscore += 60; break; case 4: *pscore = *pscore + 100; break; } //补齐代码,考虑更优算法 } int InscreaseSpeed(int score) { // if (score >= 0 && score < 500) // { // return 1; // } // else if(score >= 500 && score < 1000) // { // return 2; // } // else if(score >= 1000 && score < 1500) // { // return 3; // } if (score >= 0 && score < 500) { return 1; } else if(score < 1000) { return 2; } else if(score < 1500) { return 3; } return 4; } int main() { int x = (GAME_MAIN_WIDTH + 2 + GAME_INFO_WIDTH + 2) * 2 - 1; //35 代36列 int y = GAME_MAIN_HEIGHT + 2; //22 代表23行 int score = 0,speed = 1,counts = 0; //分数,速度,总消行 数 SMALL_RECT rect = {0,0,x,y}; COORD size = {x + 1,y + 1}; CONSOLE_CURSOR_INFO cursorInfo; g_hOut = GetStdHandle(STD_OUTPUT_HANDLE); g_hIn = GetStdHandle(STD_INPUT_HANDLE); //设置控制台界面大小 SetConsoleWindowInfo(g_hOut,TRUE,&rect); //设置屏幕的缓冲区 SetConsoleScreenBufferSize(g_hOut,size); //隐藏光标 cursorInfo.bVisible = FALSE; cursorInfo.dwSize = 100; SetConsoleCursorInfo(g_hOut,&cursorInfo); //画左右边框 DrawFrame(0,0,GAME_MAIN_WIDTH,GAME_MAIN_HEIGHT); DrawFrame(0+(GAME_MAIN_WIDTH + 2) * 2 ,0,GAME_INFO_WIDTH,GAME_MAIN_HEIGHT); //下一方块 GotoXY(GAME_INFO_LEFT,INFO_BLOCK_TOP); printf("下一方块"); GotoXY(GAME_INFO_LEFT,INFO_SPEED_TOP); printf("速度"); GotoXY(GAME_INFO_LEFT,INFO_SCORE_TOP); printf("分数"); //score = 1000; PrintScore(score); PrintSpeed(speed); //score = 0; //PrintScore(score); //ClearWindow(0,0,17,3); while (1) //for(;;) { int count = rand() % 4; int newSpeed; //int count = rand() % 5 + 1; CalculateScore(count,&score); PrintScore(score); newSpeed = InscreaseSpeed(score); if (newSpeed !=speed) { speed = newSpeed; PrintSpeed(speed); } Sleep(500); } GotoXY(0,y); CloseHandle(g_hOut); CloseHandle(g_hIn); return 0; }
/
本文档为【俄罗斯方块源代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索