网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月08日漏签0天
c语言吧 关注:798,959贴子:4,357,966
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 3回复贴,共1页
<<返回c语言吧
>0< 加载中...

弹跳球小游戏,求吧友帮忙看下为什么代码提示in function

  • 只看楼主
  • 收藏

  • 回复
  • 十残骷狱
  • 便当
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
这是源代码。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#define High 16 // 游戏画面尺寸
#define Width 16
#define radius 3 // 半径
// 全局变量
int position_x,position_y; // 挡板位置
int ball_x,ball_y; //小球位置
int ball_vx,ball_vy; //小球速度
int score; //得分
int left,right; //左右大小
void gotoxy(int x,int y) //光标移动到(x,y)位置
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
void startup() // 数据初始化
{
position_y = High;
position_x = Width/2;
ball_x=2/Width;
ball_y=1;
left=position_x-radius;
right=position_x+radius;
ball_vx=1;
ball_vy=1;
score = 0;
void show() // 显示画面
{
gotoxy(0,0); // 光标移动到原点位置,以下重画清屏
int i,j;
for (i=0;i<High;i++)
{
for (j=0;j<Width;j++)
{
if ((i==ball_y)&&(j==ball_x))
printf("O"); // 输出小球
else if (i==High) //输出下边界
printf("_");
else if (i==Width) //输出右边界
printf("|");
else if ((i==High)&&(j>=left)&&(j<=right))
printf("*"); // 输出挡板
else
printf(""); // 输出空格
}
printf("\n");
}
printf("得分:%d\n",score);
Sleep(20);
}
void updateWithoutInput() // 与用户输入无关的更新
{
if(ball_y==High)
{
if((ball_x>=left)&&(ball_x<=right))
{
score++;
ball_vx=-ball_vx;
}
else
{
printf("game over!!");
exit(0);
}
}
ball_x+=ball_vx;
ball_y+=ball_vy;
if (ball_x==0||ball_x==Width)
ball_vx=-ball_vx;
if (ball_y==High-1||ball_y==0)
ball_vy=-ball_vy;
sleep(50);
}
void updateWithInput() // 与用户输入有关的更新
{
char input;
if(kbhit()) // 判断是否有输入
{
input = getch(); // 根据用户的不同输入来移动,不必输入回车
if (input == 'a' )
{
position_x--;
left=position_x-radius;
right=position_x+radius;
}
else if (input == 'd')
{
position_x++;
left=position_x-radius;
right=position_x+radius;
}
}
int main()
{
startup(); // 数据初始化
while (1) // 游戏循环执行
{
show(); // 显示画面
updateWithoutInput(); // 与用户输入无关的更新
updateWithInput(); // 与用户输入有关的更新
}
return 0;
}


  • 嫣然一笑v
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
在吗,现在还有魔法士海贼王卡片吗?


2025-08-08 10:11:38
广告
不感兴趣
开通SVIP免广告
  • 嫣然一笑v
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
在吗,现在还有魔法士海贼王卡片吗?


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 3回复贴,共1页
<<返回c语言吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示