栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c语言大作业-弹跳小球

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c语言大作业-弹跳小球

前言,我是一名大一新生

c语言入门新手

这是我第一次分享代码,记录一下我大学c语言学习过程

这个弹跳小球代码是我们小组的大作业

主要实现的功能是,小球在框内弹跳,碰壁响铃反馈

底部玩家使用键盘ad控制板子移动,接住得分

接不住死亡

很简单对吧,希望各位大佬能为我的代码提一点意见

话不多说,上代码。

#include 
#include  
#include  
#include 
 
void HideCursor()  
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible=FALSE;
cursor.dwSize=sizeof(cursor);
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle,&cursor);
}
int main(void)
{
int i, j,change;
int move=20;
int c = 200;
int a = 0;
int x = 0;
int y = 5;
int left = 0;
int right = 50;
int top = 0;
int bottom = 20;
int velocity_x = 1;
int velocity_y = 1;
char die[5] ;
HideCursor(); //调用光标隐藏函数 

while (1)
{
 
x = x + velocity_x;               //x的移动
y = y + velocity_y;
system("cls");                   //清屏函数,形成运动效果
for (i = 0; i <= right; i++)    //在每次运行的第一行. 画一排#作为上边界
printf("#");
printf("tt得分:%dt当前刷新速度%d ms",a,c); //记录得分 
printf("n");

for (i = 0; i < x; i++)
{
printf("*");                     //第一个字符为*  即左边框
for (j = 0; j < right - 1; j++)  // 用循环画空格
printf(" ");
printf("*n");               //用* 再画一个右边框
}

printf("*");                      //左边框
for (j = 0; j < y - 1; j++)       //小球之前的空格
printf(" ");
printf("o");                      //小球
for (; j < right - 2; j++)       //小球右边的空格
printf(" ");
printf("*n");                     //右边框

for (i > x+1; i < bottom; i++)
{
printf("*");
for (j = 0; j < right - 1; j++)
printf(" ");
printf("*n");
}
 
if(kbhit()!=0) //注;初始速度为100ms 
{
change=getch();
}
if(change=='a')
move-=2;
if(change=='d')
move+=2;

for(i=0;i printf(" "); 
for (i = move; i < move+5; i++)   
printf("#");
for(i=move+5;i<=right;i++)
printf(" ") ;
printf("n");
 
if(kbhit()!=0) //注;初始速度为200ms 
{
change=getch();
}
if(change=='0') 
c=1;
if(change=='1') //一级速度50ms 
c=50; 
if(change=='2') //二级速度100ms
c=200; 
if(change=='3')  //三级速度200ms
c=200;

Sleep(c);                   //小球运行速度控制 
if ((x == top) || (x == bottom))
{
velocity_x = -velocity_x;
printf("a");

}
if (x == bottom)
a++;
if ((y == left) || (y == right-1))
{
velocity_y = -velocity_y;            //碰壁响铃
printf("a");

}
if(x==bottom)
{
if((y>0)&&(y {
printf("真菜,死掉了5s后重新开始");
Sleep(5000);
}
if((y>move+5)&&(y {
printf("真菜,死掉了5s后重新开始");
Sleep(5000);
}
}
}


return 0;
}

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/868998.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号