|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <stdio.h>
- #include "windows.h"
- #include <stdlib.h>
- #include <conio.h>
- //定义全局变量
- int high,width;//画面尺寸
- int bird_x,bird_y;//小鸟坐标
- int ball_vx,ball_vy;//小球速度
- int bar_y,bar_xdown,bar_xtop;//柱子
-
- 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 HideCursor()//隐藏光标
- {
- CONSOLE_CURSOR_INFO cursor_info={1,0};//第二个值为0表示隐藏光标
- SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
- }
- void startup()
- {
- high=15,width=25;
- bird_x=0,bird_y=width/3;
- bar_y=width,bar_xtop=high/4;
- bar_xdown=high/2;
-
-
- HideCursor();
- }
- void show()
- {
- gotoxy(0,0);//光标必须(0,0)
- //system("cls");
- int i,j;
- for(i=0;i<=high+1;i++){
- for(j=0;j<=width+1;j++){
- if(i==high+1)//显示下边框
- {
- printf("=");
- }
- else if(j==width+1)//显示右边框
- {
- printf("||");
- }
- else if((i==bird_x)&&(j==bird_y)) printf("@"); //显示小鸟
- if((j==bar_y)&&((i<=bar_xtop)||(i>=bar_xdown)))
- {
- printf("*");//输出障碍
- }
- else printf(" ");
- }
- printf("\n");
-
- }
- }
- void update_without()
- {
- bird_x++;
- Sleep(50);
-
-
- }
- void update_with()
- {
- char input;
- if(kbhit()){
- input =getch();
- if(input ==' ')
- {
- bird_x-=2;
-
- }
-
- }
-
- }
- int main()
- {
- system("title 反弹球消砖块");
- //gotoxy(0,0);//把光标移至画面左顶点(0,0)处
- startup();
- //循环,游戏运行
- while(1)
- {
- show();
- update_without();
- update_with();
-
- }
-
- return 0;
- }
复制代码
问题:
show函数里,障碍物*,画面||,会随着小鸟@的下落一起显示
- else if((i==bird_x)&&(j==bird_y)) printf("@"); //显示小鸟
- if((j==bar_y)&&((i<=bar_xtop)||(i>=bar_xdown)))//if之前没有加else 造成的,if...if,和else if有什么不一样?求解释。
- {
- printf("*");//输出障碍
- }
复制代码 |
|