/********************************************
* 程序名称:MR.DUAN 的打砖块(KILL THE BLOCKS !)
* 作  者:WindAutumn <duanxu@outlook.com>
* 最后修改:2012-8-11-PM
* 版 本 号:1.0
*
*// 好像有个BUG。。。间歇性发作,可能是编译器问题吧,不管了。。。
*
* *****************************************/ #include<stdio.h>
#include<Windows.h>
#include<conio.h> #define PI 3.1415926
#define LEFT 0
#define RIGHT34
#define UP 0
#define DOWN24
#define X_OFFSET 2
#define Y_OFFSET 1
#define BLOCK_MAP 0xffff// 砖块地图 unsigned short block[]= {};
char blocks[][]= {};
int arm_head=+X_OFFSET, arm_tail=+X_OFFSET; void HideCursor(HANDLE hBlock);
void GotoXY(HANDLE hBlock, int x, int y);
void InitScreen(HANDLE hBlock);
void GameStart();
void GameOver(HANDLE hBlock, int mode);
void PrintBlock(HANDLE hBlock);
void ChangeArm(HANDLE hBlock);
void PrintBall(HANDLE hBlock);
void KillBlock(HANDLE hBlock, int x, int y); void main()
{
system("color 7b");// 默认颜色,白色底色
SetConsoleTitle("KILL THE BLOCKS !");// 设置控制台标题
GameStart();// 开始游戏
} void GameStart()
{
int i; HANDLE hBlock = GetStdHandle(STD_OUTPUT_HANDLE);
HideCursor(hBlock);// 隐藏光标
InitScreen(hBlock);// 初始化屏幕
for(i=; i<; i++)
block[i]=BLOCK_MAP;
PrintBlock(hBlock);// 绘制砖块地图 GotoXY(hBlock, arm_head, DOWN - );// 以下3行打印托盘
for(i=; i<(arm_tail-arm_head)/+; i++)
printf("□"); PrintBall(hBlock);// 对小球的控制
} void InitScreen(HANDLE hBlock)// 初始化屏幕
{
int i;
SetConsoleTextAttribute(hBlock, FOREGROUND_INTENSITY | FOREGROUND_BLUE | BACKGROUND_BLUE |BACKGROUND_GREEN | BACKGROUND_RED);
// 白的背景色,亮蓝色前景色
GotoXY(hBlock, , );
printf("╔");
for(i=; i<RIGHT/; i++)
printf("═");
//printf("%2d",i);
printf("╗"); for(i=; i< DOWN; i++)
{
GotoXY(hBlock, , i);
//printf("%d",i);
printf("║");
GotoXY(hBlock, RIGHT, i);
printf("║");
} GotoXY(hBlock, , DOWN);
printf("╚");
for(i=; i<RIGHT/; i++)
printf("═");
printf("╝"); GotoXY(hBlock, , ); } void HideCursor(HANDLE hBlock)// 隐藏光标
{
CONSOLE_CURSOR_INFO cursor_info = {, };
SetConsoleCursorInfo(hBlock, &cursor_info);
} void GotoXY(HANDLE hBlock, int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(hBlock, coord);
} void PrintBlock(HANDLE hBlock)
{
int i,j;
for(i=; i<; i++)// 打印右侧数字视图
{
for(j=; j<; j++)
{
if(((block[i]<<j)&0x8000) == (unsigned short)0x8000)
blocks[i][j]=;
else blocks[i][j]=;
GotoXY(hBlock,+j,i);
printf("%d",blocks[i][j]);
}
}
for(i=; i<; i++)// 打印砖块
{
for(j=; j<; j++)
{
if(blocks[i][j]==)
{
GotoXY(hBlock,+*j,+i);
printf("□");
}
}
}
} void ChangeArm(HANDLE hBlock)
{
int key_direct=;
if(_kbhit())
{
key_direct = getch();
if(key_direct == 'a'&&arm_head > LEFT+)// 托盘往左走
{
arm_head -= ;
GotoXY(hBlock, arm_head, DOWN-);
printf("□");
GotoXY(hBlock, arm_tail, DOWN-);
printf(" ");
arm_tail -= ;
}
if(key_direct == 'd'&&arm_tail < RIGHT-)// 托盘向右走
{
arm_tail += ;
GotoXY(hBlock, arm_tail, DOWN-);
printf("□");
GotoXY(hBlock, arm_head, DOWN-);
printf(" ");
arm_head += ;
}
}
} void PrintBall(HANDLE hBlock)
{
int k,flag=;
int x = (arm_head+arm_tail)/, y =DOWN - ;// 球的坐标
int tempx = x,tempy = y;
int degree =;// 初始角度 GotoXY(hBlock, x, y);// 初始球坐标
printf("□");
while()
{
if(x == LEFT+ || x == RIGHT-)
degree = (degree<=)?(-degree):(-degree);// 碰左右边的角度计算
if(y == UP+)
degree = - degree;// 碰上边的角度计算
if(y == DOWN-)
{
if(!(x>=arm_head&&x<=arm_tail))// 没有碰上托盘的情况
GameOver(hBlock,);// 失败
else if(degree > )
{
if(x == (arm_head+arm_tail)/)
degree = - degree;// 计算碰托盘之后角度
else
degree = - degree + * ((arm_head+arm_tail)/ - x);
} }
switch(degree)// 根据角度确定方块移动方向
{
case :
case :
case :
tempx = x+;
tempy = y-;
break;
case :
tempx = x+;
tempy = y-;
break;
case :
tempx = x ;
tempy = y-;
break;
case :
tempx = x-;
tempy = y-;
break;
case :
tempx = x-;
tempy = y-;
break;
case :
case :
tempx = x-;
tempy = y+;
break;
case :
tempx = x-;
tempy = y+;
break;
case :
tempx = x ;
tempy = y+;
break;
case :
tempx = x+;
tempy = y+;
break;
case :
tempx = x+;
tempy = y+;
break;
} GotoXY(hBlock, tempx, tempy);// 下一个点在哪?
printf("□");
GotoXY(hBlock, x, y);// 消除上一个点
printf(" ");
x = tempx;
y = tempy; ChangeArm(hBlock);
KillBlock(hBlock,x,y);
for(k=; k<; k++)// 如果每行非0就置flag为1
if(block[k]!=(unsigned short)0x0000)
flag=;
if(flag==)// 如果flag为0则游戏胜利
GameOver(hBlock,);
flag=;
GotoXY(hBlock,,);// 打印坐标,角度信息
printf("%3d,%2d,%2d",degree,x,y);
Sleep();// 暂停0.1s *********************important
}
} void KillBlock(HANDLE hBlock, int x, int y)
{
int i,j;
unsigned short temp;
i=y-;
j=(x-)/;
if(blocks[i][j] == )
{
blocks[i][j] = ;
temp = ~(0x0001<<j);// 掩码
block[i]=block[i] & temp;// 将block信息与( 1111 1110 1111 1111 )进行与运算,消除bit位
GotoXY(hBlock,+j,i);// 刷新右侧数字区
printf("");
//GotoXY(hBlock,50,12+i);// 打印实时每行信息
//printf("%#x",block[j]);
}
} void GameOver(HANDLE hBlock, int mode)
{
GotoXY(hBlock,,);
if(mode)
printf("you win");
else
printf("you loss"); getch();
exit();
}

一个打砖块的小游戏1.0 KILL THE BLOCKS !的更多相关文章

  1. 软件工程:黄金G点小游戏1.0

    我们要做的是黄金G点小游戏: N个同学(N通常大于10),每人写一个0~100之间的有理数 (不包括0或100),交给裁判,裁判算出所有数字的平均值,然后乘以0.618(所谓黄金分割常数),得到G值. ...

  2. python写的battle ship小游戏 - 1.0

    最近学python,这是今天写的一个小游戏. from random import randint class Board(object): board = [] def __init__(self, ...

  3. 一个很有意思的小游戏:Dig2China

    最近通关了一个小游戏,游戏故事是这样的:一个美国小男孩想要去中国,他决定从自家后院往下挖,横穿地心去中国,期间经历了很多次失败.但是,每次尝试都能收获一批钱,用这些钱升级钻地机,调整自己的工具,终于在 ...

  4. 一听就懂:用Python做一个超简单的小游戏

    写它会用到 while 循环random 模块if 语句输入输出函数

  5. HTML5存储(带一个粗糙的打怪小游戏案例)

    本地存储localStorage设置存储内容setItem(key,value) localStorage.setItem('leo','23'); 更新存储内容对象[key]=value对象.key ...

  6. 一个控制台贪吃蛇小游戏(wsad控制移动)

    /******************************************** * 程序名称:MR.DUAN 的贪吃蛇游戏(链表法) * 作 者:WindAutumn <flutti ...

  7. 2D命令行小游戏Beta1.0

    前提: 遇到许多问题,没有参考大佬一些方法是敲不出来的...Orz using System; using System.Collections.Generic; using System.Linq; ...

  8. 简单的鼠标操作<一个填充格子的小游戏>

    #include "graphics.h" #include "conio.h" void main(){ // 初始化界面 initgraph(, ); ; ...

  9. Unity小游戏制作 - 暗影随行

    用Unity制作小游戏 - 暗影惊吓 最近玩了一个小游戏,叫做暗影惊吓,虽然是一个十分简单的小游戏,但是感觉还是十分有趣的.这里就用Unity来实现一个类似的游戏. 项目源码:DarkFollow 主 ...

随机推荐

  1. Win7下启用IIS7

    1.进入“控制面板-->程序”: 2.点击“打开或关闭Windows功能” 3.选择“Internet信息服务”相关选项,如下: 点击“确定”后,请稍等.. 5.启用成功后,可在浏览器访问:ht ...

  2. Java笔记-快速失败and安全失败

    参考资料:http://blog.csdn.net/chenssy/article/details/38151189 快速失败 fail-fast 安全失败 fail-safe java.util包下 ...

  3. 一个处理Date与String的工具类

    public class DateUtil { private DateUtil(){ } public static final String hhmmFormat="HH:mm" ...

  4. CentOS 基础安装

    1. 下载了 CentOS 的最小安装版本 与 VMware,基础安装流程参考百度经验:http://jingyan.baidu.com/article/eae0782787b4c01fec54853 ...

  5. Objective-C释解 Target-Action模式

    Objective-C释解 Target-Action模式   Target-Action模式是ObjC里非常常见的对象之间方法调用的方式,不过ObjC把方法调用叫做Send Message. 一帮情 ...

  6. 统计指定时间段的访问真正WEB页面(去除静态请求)的IP的TOP100排行

    最近就在磨这个脚本以达到SEO同事要求哈. awk -v b=[21/Apr/2015:15:46 -v a=[21/Apr/2015:16:46 '$4 > b && $4 & ...

  7. chrome_php logger 的实现原理

    chrome_php是什么 1.chrome_php 是什么? 一款 Chrome 下用来配合调试 PHP 的工具,可以通过,console来查看php的信息 1.2用法 用法特别简单,有一个chro ...

  8. Sublime 2 Installation for Linux

    Linux You can download the package and uncompress it manually. Alternatively, you can use the comman ...

  9. Matlab:回归分析(1)

    1.多元线性回归 %数据的输入 x = [ ]; y = [ ]; %转换为列向量 X = [ones(,) x']; Y = y'; %回归分析及检验 [b, bint, r, rint, stat ...

  10. JDK 高性能编程之容器

    高性能编程在对不同场景下对于容器的选择有着非常苛刻的条件,这里记录下前人总结的经验,并对源码进行调试 JDK高性能编程之容器 读书笔记内容部分来源书籍深入理解JVM.互联网等 先放一个类图util,点 ...