c语言大作业-弹跳小球

前言,我是一名大一新生

c语言入门新手

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

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

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

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

接不住死亡

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

话不多说,上代码。

#include <stdio.h>
#include <stdlib.h> 
#include <Windows.h> 
#include <conio.h>
/*玩法简介
使用键盘AD控制板子移动,数字键1~3控制难度等级 ,0解锁地狱级 
/*光标隐藏函数*/ 
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("\t\t得分:%d\t当前刷新速度%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<move;i++)
printf(" "); 
for (i = move; i < move+5; i++)   
printf("#");
for(i=move+5;i<=right;i++)
printf(" ") ;
printf("\n");
/*扫描键盘改变sleep函数值来改变小球运行速度*/ 
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<move-1))
{
printf("真菜,死掉了5s后重新开始");
Sleep(5000);
}
if((y>move+5)&&(y<right))
{
printf("真菜,死掉了5s后重新开始");
Sleep(5000);
}
}
}


return 0;
}

 

 

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值