做了个接球球程序,求鼓励。
c4droid吧
全部回复
仅看楼主
level 7
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include<time.h>
#define H 20
#define W 20
int i,j,n,hp1=3;
int l,jj,ball=0;
int y2=W/2-1;
int y1,y3;
int yy1,xx1;
char map[H][W];
void map1()
{
y1=y2-1;
y3=y2+1;
for (i = 0; i != H; ++i)
{
for (j = 0; j != W; ++j)
{
if ((i == 0) || (i == H - 1) || (j == 0) || (j == W - 1))
map[i][j] = '9';
else
map[i][j] = '0';
}
}
map[xx1][yy1]='3';
map[18][y1]='2';
map[18][y2]='2';
map[18][y3]='2';
}
void turn()
{
l=getch();
if(l==52)
{
map[18][y2--];
}
if(l==54)
{
map[18][y2++];
}
if(y2==1)
{
y2=2;
}
if(y2==18)
{
y2=17;
}
}
void draw()
{
printf("生命值%d 接了%d个球\n",hp1,ball);
for (i = 0; i != H; ++i)
{
for (j = 0; j != W; ++j)
switch (map[i][j])
{
case '0':
printf(" ");
break;
case '2':
printf("_");
break;
case '3':
printf("@");
break;
case '9':
printf("#");
break;
}
printf("\n");
}
}
void hp()
{
if(xx1==18)
{
if(yy1!=y1&&yy1!=y2&&yy1!=y3)
{
hp1=hp1-1;
}
else
{
ball=ball+1;
}
}
}
int main(void)
{
printf("接球球游戏\n4左6右\n");
printf("任意键开始");
getch();
srand((unsigned)time(NULL));
yy1=rand()%18+1;
while(1)
{
if(!kbhit())
{
usleep(140000-n*500);
xx1++;
map1();
clrscr();
draw();
hp();
}
else
{
map1();
turn();
clrscr();
draw();
hp();
}
if(hp1<=0)
{
clrscr();
draw();
printf("你死了");
break;
}
if(xx1==18)
{
xx1=0;
yy1=rand()%18+1;
n++;
}
}
}
2016年07月08日 11点07分 1
level 11
[大拇指]
2016年07月08日 11点07分 3
总算来人了
2016年07月08日 11点07分
谢谢
2016年07月08日 11点07分
level 9
[顶][顶][顶]
2016年07月08日 12点07分 4
谢谢
2016年07月08日 12点07分
level 12
2016年07月08日 12点07分 5
收到! [呵呵]
2016年07月09日 02点07分
level 12
👍👍👍👍👍
2016年07月08日 12点07分 6
level 8
给你一百个赞
2016年07月08日 13点07分 7
level 7
什么
2016年07月09日 11点07分 9
level 7
其实我还想加个❤加血了
2016年07月09日 11点07分 10
level 11
刚从c语言吧过来[滑稽]
2016年07月09日 12点07分 11
哈哈哈,c语言吧没人理我
2016年07月09日 13点07分
level 7
唯一值得骄傲的地方就是,本人初三[滑稽]
2016年07月09日 12点07分 12
我也一样,我会一点c一点java一点单片机一点C++
2016年07月27日 15点07分
厉害👍
2016年08月05日 23点08分
level 13
初三有什么值得骄傲的[咦]
三年级才值得骄傲
2016年07月09日 13点07分 13
666
2016年07月09日 14点07分
level 7
加了注释了,不知道全不全
2016年07月09日 14点07分 15
level 7
什么情况
2016年07月09日 14点07分 17
level 7
发出去都被莫名其妙的删了
2016年07月09日 14点07分 18
level 7
加了注释了
//文晟原创
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include<time.h>
#define H 20
//长度
#define W 20
//宽度
int i,j,l;
int hp1=3;
int n=0,ball=0;
int y2=W/2-1;//让平台生成在中间
int y1,y3;
int yy1,xx1;
char map[H][W];
void map1()//制作地图
{
y1=y2-1;
y3=y2+1;//让这两个边跟着平台移动
for (i = 0; i != H; ++i)
{
for (j = 0; j != W; ++j)
{
if ((i == 0) || (i == H - 1) || (j == 0) || (j == W - 1))//画墙壁
map[i][j] = '9';
else//画空地
map[i][j] = '0';
}
}
map[xx1][yy1]='3';
map[18][y1]='2';
map[18][y2]='2';
map[18][y3]='2';
}
void turn()//移动
{
l=getch();
if(l==52)
{
map[18][y2--];
}
if(l==54)
{
map[18][y2++];
}
if(y2==1)//不让平台过墙
{
y2=2;
}
if(y2==18)//同上
{
y2=17;
}
}
void draw()//画地图
{
printf("生命值%d 接了%d个球\n",hp1,ball);
for (i = 0; i != H; ++i)
{
for (j = 0; j != W; ++j)
switch (map[i][j])
{
case '0':
printf(" ");//空地
break;
case '2':
printf("_");//平台
break;
case '3':
printf("@");//球球
break;
case '9':
printf("#");//墙壁
break;
}
printf("\n");
}
}
void hp()//生命系统
{
if(xx1==18)
{
if(yy1!=y1&&yy1!=y2&&yy1!=y3)
{
hp1=hp1-1;
}//如果不掉在平台上血减1
else
{
ball=ball+1;
}//如果掉在平台上,加一个接球数量
}
}
int main(void)
{
printf("接球球游戏\n4左6右\n");
printf("任意键开始");
getch();
srand((unsigned)time(NULL));
yy1=rand()%18+1;//随机在顶端出现一个球
while(1)//开始
{
if(!kbhit())//如果没输入跳过turn
{
usleep(140000-n*500);//每次循环都会加速
xx1++;//让球掉下来
map1();
clrscr();
draw();
hp();
}
else//有输出就执行turn
{
map1();
turn();
clrscr();
draw();
hp();
}
if(hp1<=0)
{
clrscr();
draw();
printf("你死了");
break;
}
if(xx1==18)
{
xx1=0;
yy1=rand()%18+1;//如果掉落一个球就在顶端生成一个球
n++;//掉落的次数,用来加速
}
}
}
2016年07月09日 14点07分 19
1 2 3 4 尾页