c语言之小游戏:球球碰撞

c语言之小游戏:球球碰撞

首页休闲益智球球冲击更新时间:2024-04-10

C游戏代码介绍

#include<stdio.h> #include<stdlib.h> #include<windows.h> #include<conio.h> #include<time.h> #define N 20 int screen[N][N]; void start(int* flag,int* rate){ srand((unsigned)time(NULL)); screen[N-1][rand() ]=2; *flag=0;//判断是否被击中,初始为零 *rate=20;敌机移动速率 } void show(){ system("cls"); printf("jk操作\n"); //输出画面 inti,j; for(i=0;i<N;i ){ for(j=0;j<N;j ){ if(screen[i][j]==1) putchar('V'); if(screen[i][j]==2) putchar('A'); else putchar(''); } putchar('\n'); } Sleep(50); } void updatewithoutinput(int* flag,int*rate){ inti,j; //计时 staticint time=-1; time ; //敌机前进 for(i=N-1;i>=0;i--){ for(j=0;j<N;j ){ if(screen[i][j]==1){ screen[i][j]=0; screen[i 1][j]=1; } //敌机触底 if(i==N-2&&screen[i][j]==1){ screen[i][j]=0; } //敌机击中战机 if(screen[i][j]==2&&screen[i-1][j]==1){ *flag=1; putchar('\a'); } //刷新敌机 if(time%*rate==0&&i==0) screen[i][j]=rand()%2; } } } void updatewithinput(){ charinput;//保存键盘输入 if(kbhit()){//检测键盘输入 input=getch(); intj; for(j=0;j<N;j ){ if(input=='j'&&j>0&&screen[N-1][j]==2){ screen[N-1][j]=0; screen[N-1][j-1]=2; } if(input=='k'&&j<N-1&&screen[N-1][j]==2){ screen[N-1][j]=0; screen[N-1][j 1]=2; break;//防止错误多步操作 } } } } int main(){ intrate; intflag; begin: start(&flag,&rate); while(1){ if(flag) gotobegin;//重启游戏 show(); updatewithoutinput(&flag,&rate); updatewithinput();

查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved