#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
/* 【自学去】网站收集 http://www.zixue7.com */
/* 管道句柄的定义 */
HANDLE hStdOutput = INVALID_HANDLE_VALUE;
HANDLE hStdError = INVALID_HANDLE_VALUE;
const WORD COLOR_A = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY; /* 运动中的颜色 */
const WORD COLOR_B = FOREGROUND_GREEN; /* 固定不动的颜色 */
const WORD COLOR_C = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE; /* 空白处的颜色 */
bool voice = true; /* 背景音乐 */
int score = 0; /* 得分 */
int level = 0; /* 等级 */
char data[19][11] = { 0 }; /* 游戏窗口的状态 */
int next = -1; /* 记录下一个图形的随机信息 */
int x = 4, y = -2, c = -1, z = 0; /* x坐标,坐标,当前方块,方向 */
/* 程序开始为句柄初始化 */
bool Open( void )
{
hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE );
hStdError = GetStdHandle( STD_ERROR_HANDLE );
return INVALID_HANDLE_VALUE!=hStdOutput && INVALID_HANDLE_VALUE!=hStdError;
}
/* 设置标题 */
bool SetTitle( char* title )
{
return TRUE==SetConsoleTitle(title);
}
/* 去处光标 */
bool RemoveCursor( void )
{
CONSOLE_CURSOR_INFO cci; /* 光标信息 */
/* 标准输出句柄获取信息出错就返回错误 */
if( !GetConsoleCursorInfo( hStdOutput, &cci ) )
{
return false;
}
cci.bVisible = false;
/* 标准输出句柄设置信息出错就返回错误 */
if( !SetConsoleCursorInfo( hStdOutput, &cci ) )
{
return false;
}
/* 错误输出句柄获取信息出错就返回错误 */
if( !GetConsoleCursorInfo( hStdError, &cci ) )
{
return false;
}
cci.bVisible = false;
/* 错误输出句柄设置信息出错就返回错误 */
if( !SetConsoleCursorInfo( hStdError, &cci ) )
{
return false;
}
return true;
}
/* 设置窗体尺寸 */
bool SetWindowRect( short x, short y )
{
/* 定义用于取得console程序的窗口大小的结构 */
SMALL_RECT wrt = { 0, 0, x, y };
/* 标准输出设置失败 */
if( !SetConsoleWindowInfo( hStdOutput, TRUE, &wrt ) )
{
return false;
}
/* 错误输出设置失败 */
if( !SetConsoleWindowInfo( hStdError, TRUE, &wrt ) )
{
return false;
}
return true;
}
/* 设置缓冲尺寸 */
bool SetBufSize( short x, short y )
{
/* 定义用于获取坐标结构体 */
COORD coord = { x, y };
/* 设置标准输出失败 */
if( !SetConsoleScreenBufferSize( hStdOutput, coord ) )
{
return false;
}
/* 设置错误输出失败 */
if( !SetConsoleScreenBufferSize( hStdError, coord ) )
{
return false;
}
return true;
}
/* 移动光标 */
bool GotoXY( short x, short y )
{
/* 定义用于获取坐标结构体 */
COORD coord = { x, y };
/* 设置标准输出鼠标位置失败 */
if( !SetConsoleCursorPosition( hStdOutput, coord ) )
{
return false;
}
/* 设置错误输出鼠标位置失败 */
if( !SetConsoleCursorPosition( hStdError, coord ) )
{
return false;
}
return true;
}
/* 设置前景色/背景色 */
bool SetColor( WORD color )
{
/* 背景颜色标准输出失败 */
if( !SetConsoleTextAttribute( hStdOutput, color ) )
{
return false;
}
/* 背景颜色错误输出失败 */
if( !SetConsoleTextAttribute( hStdError, color ) )
{
return false;
}
return true;
}
/* 输出字符串 */
bool OutputString( const char* pstr, size_t len )
{
/* 32bit 无符号整数 */
DWORD n = 0;
/* 输出到控制台 */
return TRUE == WriteConsole( hStdOutput, pstr, len?len:strlen(pstr), &n, NULL );
}
/* 输出字符串 */
bool OutputStringNoMove( short x, short y, const char* pstr, size_t len)
{
/* 定义用于获取坐标结构体 */
COORD coord = { x, y };
/* 32bit 无符号整数 */
DWORD n = 0;
return TRUE == WriteConsoleOutputCharacter( hStdOutput, pstr, len?len:strlen(pstr), coord, &n );
}
/* 窗口界面显示 */
/* 构建11*19的游戏窗口 */
const char bg[] =
"┏━━━━━━━━━━━┓ "
"┃■■■■■■■■■■■┃ ←↓→ ↑ "
"┃■■■■■■■■■■■┃ Begin "
"┃■■■■■■■■■■■┃ Voice = Yes"
"┃■■■■■■■■■■■┃ Sleep "
"┃■■■■■■■■■■■┃ Quit "
"┃■■■■■■■■■■■┃ "
"┃■■■■■■■■■■■┃ "
"┃■■■■■■■■■■■┃ NEXT "
"┃■■■■■■■■■■■┃┏━━━━┓"
"┃■■■■■■■■■■■┃┃ ┃"
"┃■■■■■■■■■■■┃┃ ┃"
"┃■■■■■■■■■■■┃┗━━━━┛"
"┃■■■■■■■■■■■┃ LEVEL "
"┃■■■■■■■■■■■┃┏━━━━┓"
"┃■■■■■■■■■■■┃┃ 0 ┃"
"┃■■■■■■■■■■■┃┗━━━━┛"
"┃■■■■■■■■■■■┃ SCORE "
"┃■■■■■■■■■■■┃┏━━━━┓"
"┃■■■■■■■■■■■┃┃ 00000 ┃"
"┗━━━━━━━━━━━┛┗━━━━┛";
/* 七种图形的各种情况 */
/* 第一维为图形种类,第二维为图形的方向,三四维为图形的4*4的填充方式 */
const char bk[7][4][4][4] =
{
{
{ { 0,1,1,0 },{ 1,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,0,0,0 },{ 1,1,0,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 0,1,1,0 },{ 1,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,0,0,0 },{ 1,1,0,0 },{ 0,1,0,0 },{ 0,0,0,0 } }
}
,
{
{ { 1,1,0,0 },{ 0,1,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 1,1,0,0 },{ 1,0,0,0 },{ 0,0,0,0 } },
{ { 1,1,0,0 },{ 0,1,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 1,1,0,0 },{ 1,0,0,0 },{ 0,0,0,0 } }
}
,
{
{ { 1,1,1,0 },{ 1,0,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,0,0,0 },{ 1,0,0,0 },{ 1,1,0,0 },{ 0,0,0,0 } },
{ { 0,0,1,0 },{ 1,1,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,1,0,0 },{ 0,1,0,0 },{ 0,1,0,0 },{ 0,0,0,0 } }
}
,
{
{ { 1,1,1,0 },{ 0,0,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,1,0,0 },{ 1,0,0,0 },{ 1,0,0,0 },{ 0,0,0,0 } },
{ { 1,0,0,0 },{ 1,1,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 0,1,0,0 },{ 1,1,0,0 },{ 0,0,0,0 } }
}
,
{
{ { 1,1,0,0 },{ 1,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,1,0,0 },{ 1,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,1,0,0 },{ 1,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,1,0,0 },{ 1,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } }
}
,
{
{ { 0,1,0,0 },{ 1,1,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 1,1,0,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 1,1,1,0 },{ 0,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,0,0,0 },{ 1,1,0,0 },{ 1,0,0,0 },{ 0,0,0,0 } }
}
,
{
{ { 1,1,1,1 },{ 0,0,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,0,0,0 },{ 1,0,0,0 },{ 1,0,0,0 },{ 1,0,0,0 } },
{ { 1,1,1,1 },{ 0,0,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 1,0,0,0 },{ 1,0,0,0 },{ 1,0,0,0 },{ 1,0,0,0 } }
}
};
/* 控制声音开启函数 */
void VoiceBeep( void )
{
if( voice ) /* 如果声音开启了 */
Beep( 1760, 10 ); /* 调用系统声音 */
}
/* 绘制得分 */
void DrawScoreLevel( void )
{
char tmp[6];
/* 输出得分 */
sprintf( tmp, "%05d", score );
OutputStringNoMove( 31, 19, tmp, 5 );
/* 输出等级 */
sprintf( tmp, "%1d", level );
OutputStringNoMove( 35, 15, tmp, 1 );
}
/* 绘制声音的开关 */
void DrawVoice( void )
{
OutputStringNoMove( 35, 3, voice?"Yes":"No ", 0 );
}
/* 绘制 "next框" 中的图形 */
void DrawNext( void )
{
int i, j;
/* next框由2*4的格子组成,绘制bk中每种图形的第一个形状 */
for( i=0; i<2; ++i )
{
for( j=0; j<4; ++j )
{
OutputStringNoMove( 28+j*2, 10+i, bk[next][0][i][j]== 0?" ":"■", 2 );
}
}
}
/* 游戏结束 */
void DrawOver( void )
{
OutputStringNoMove( 28, 10, "GAME", 0 );
OutputStringNoMove( 28, 11, "OVER", 0 );
}
/* 绘制图形 */
void Draw( WORD color )
{
int i, j;
for( i = 0; i < 4; ++i )
{
/* 判断是否绘制出界 */
if( (y +
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源内容:项目全套源码+完整文档 源码说明: 全部项目源码都是经过测试校正后百分百成功运行。 SpringBoot 毕业设计,SpringBoot 课程设计,基于SpringBoot+Vue开发的,含有代码注释,新手也可看懂。ssm整合开发,小程序毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计使用,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 项目都经过严格调试,确保可以运行! 1. 技术组成 前端:Vue/JSP/React/HTML+JS+CSS/ASP 后台框架代码:java/c/c++/php/VB/lun/Andorid/Python 开发环境:idea 数据库:MySql(建议用 5.7,8.0 有时候会有坑) 部署环境:Tomcat(建议用 7.x 或者 8.x b版本),maven
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![h](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/EXE.png)
共 2 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/e2742d83d05e4acba04853cc85eb835e_qq_43368615.jpg!1)
程序员小马软件开发定制
- 粉丝: 6539
- 资源: 2246
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)