博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一个打砖块的小游戏1.0 KILL THE BLOCKS !
阅读量:4704 次
发布时间:2019-06-10

本文共 5458 字,大约阅读时间需要 18 分钟。

1 /********************************************  2  * 程序名称:MR.DUAN 的打砖块(KILL THE BLOCKS !)  3  * 作  者:WindAutumn 
4 * 最后修改:2012-8-11-PM 5 * 版 本 号:1.0 6 * 7 *// 好像有个BUG。。。间歇性发作,可能是编译器问题吧,不管了。。。 8 * 9 * *****************************************/ 10 11 #include
12 #include
13 #include
14 15 #define PI 3.1415926 16 #define LEFT 0 17 #define RIGHT34 18 #define UP 0 19 #define DOWN24 20 #define X_OFFSET 2 21 #define Y_OFFSET 1 22 #define BLOCK_MAP 0xffff// 砖块地图 23 24 unsigned short block[10]= {
0}; 25 char blocks[10][16]= {
0}; 26 int arm_head=10+X_OFFSET, arm_tail=18+X_OFFSET; 27 28 void HideCursor(HANDLE hBlock); 29 void GotoXY(HANDLE hBlock, int x, int y); 30 void InitScreen(HANDLE hBlock); 31 void GameStart(); 32 void GameOver(HANDLE hBlock, int mode); 33 void PrintBlock(HANDLE hBlock); 34 void ChangeArm(HANDLE hBlock); 35 void PrintBall(HANDLE hBlock); 36 void KillBlock(HANDLE hBlock, int x, int y); 37 38 void main() 39 { 40 system("color 7b");// 默认颜色,白色底色 41 SetConsoleTitle("KILL THE BLOCKS !");// 设置控制台标题 42 GameStart();// 开始游戏 43 } 44 45 void GameStart() 46 { 47 int i; 48 49 HANDLE hBlock = GetStdHandle(STD_OUTPUT_HANDLE); 50 HideCursor(hBlock);// 隐藏光标 51 InitScreen(hBlock);// 初始化屏幕 52 for(i=0; i<10; i++) 53 block[i]=BLOCK_MAP; 54 PrintBlock(hBlock);// 绘制砖块地图 55 56 GotoXY(hBlock, arm_head, DOWN - 1);// 以下3行打印托盘 57 for(i=0; i<(arm_tail-arm_head)/2+1; i++) 58 printf("□"); 59 60 PrintBall(hBlock);// 对小球的控制 61 } 62 63 void InitScreen(HANDLE hBlock)// 初始化屏幕 64 { 65 int i; 66 SetConsoleTextAttribute(hBlock, FOREGROUND_INTENSITY | FOREGROUND_BLUE | BACKGROUND_BLUE |BACKGROUND_GREEN | BACKGROUND_RED); 67 // 白的背景色,亮蓝色前景色 68 GotoXY(hBlock, 0, 0); 69 printf("╔"); 70 for(i=1; i
LEFT+2)// 托盘往左走142 {143 arm_head -= 2;144 GotoXY(hBlock, arm_head, DOWN-1);145 printf("□");146 GotoXY(hBlock, arm_tail, DOWN-1);147 printf(" ");148 arm_tail -= 2;149 }150 if(key_direct == 'd'&&arm_tail < RIGHT-2)// 托盘向右走151 {152 arm_tail += 2;153 GotoXY(hBlock, arm_tail, DOWN-1);154 printf("□");155 GotoXY(hBlock, arm_head, DOWN-1);156 printf(" ");157 arm_head += 2;158 }159 }160 }161 162 void PrintBall(HANDLE hBlock)163 {164 int k,flag=0;165 int x = (arm_head+arm_tail)/2, y =DOWN - 2;// 球的坐标166 int tempx = x,tempy = y;167 int degree =90;// 初始角度168 169 GotoXY(hBlock, x, y);// 初始球坐标170 printf("□");171 while(1)172 {173 if(x == LEFT+2 || x == RIGHT-2)174 degree = (degree<=180)?(180-degree):(540-degree);// 碰左右边的角度计算175 if(y == UP+1)176 degree = 360 - degree;// 碰上边的角度计算177 if(y == DOWN-2)178 {179 if(!(x>=arm_head&&x<=arm_tail))// 没有碰上托盘的情况180 GameOver(hBlock,0);// 失败181 else if(degree > 180)182 {183 if(x == (arm_head+arm_tail)/2)184 degree = 360 - degree;// 计算碰托盘之后角度185 else186 degree = 360 - degree + 15 * ((arm_head+arm_tail)/2 - x);187 }188 189 }190 switch(degree)// 根据角度确定方块移动方向191 {192 case 360:193 case 0:194 case 30 :195 tempx = x+2;196 tempy = y-1;197 break;198 case 60 :199 tempx = x+2;200 tempy = y-1;201 break;202 case 90 :203 tempx = x ;204 tempy = y-1;205 break;206 case 120 :207 tempx = x-2;208 tempy = y-1;209 break;210 case 150 :211 tempx = x-2;212 tempy = y-1;213 break;214 case 180:215 case 210 :216 tempx = x-2;217 tempy = y+1;218 break;219 case 240 :220 tempx = x-2;221 tempy = y+1;222 break;223 case 270 :224 tempx = x ;225 tempy = y+1;226 break;227 case 300 :228 tempx = x+2;229 tempy = y+1;230 break;231 case 330 :232 tempx = x+2;233 tempy = y+1;234 break;235 }236 237 GotoXY(hBlock, tempx, tempy);// 下一个点在哪?238 printf("□");239 GotoXY(hBlock, x, y);// 消除上一个点240 printf(" ");241 x = tempx;242 y = tempy;243 244 ChangeArm(hBlock);245 KillBlock(hBlock,x,y);246 for(k=0; k<10; k++)// 如果每行非0就置flag为1247 if(block[k]!=(unsigned short)0x0000)248 flag=1;249 if(flag==0)// 如果flag为0则游戏胜利250 GameOver(hBlock,1);251 flag=0;252 GotoXY(hBlock,50,20);// 打印坐标,角度信息253 printf("%3d,%2d,%2d",degree,x,y);254 Sleep(100);// 暂停0.1s *********************important255 }256 }257 258 void KillBlock(HANDLE hBlock, int x, int y)259 {260 int i,j;261 unsigned short temp;262 i=y-1;263 j=(x-2)/2;264 if(blocks[i][j] == 1)265 {266 blocks[i][j] = 0;267 temp = ~(0x0001<

 

转载于:https://www.cnblogs.com/doodle777/p/3160011.html

你可能感兴趣的文章
Oracle学习之常见错误整理
查看>>
数据库插入数据乱码问题
查看>>
altium annotate 选项设置 complete existing packages
查看>>
【模式识别与机器学习】——SVM举例
查看>>
【转】IT名企面试:微软笔试题(1)
查看>>
IO流入门-第十章-DataInputStream_DataOutputStream
查看>>
DRF的分页
查看>>
Mysql 模糊匹配(字符串str中是否包含子字符串substr)
查看>>
python:open/文件操作
查看>>
流程控制 Day06
查看>>
Linux下安装Tomcat
查看>>
windows live writer 2012 0x80070643
查看>>
tomcat 和MySQL的安装
查看>>
git常用操作
查看>>
京东SSO单点登陆实现分析
查看>>
u-boot启动第一阶段
查看>>
MySQL批量SQL插入性能优化
查看>>
定义列属性:null,default,PK,auto_increment
查看>>
用户画像展示
查看>>
C#中StreamReader读取中文出现乱码
查看>>