闲来无事,在网易云和童老师学了点打发时间小游戏
安利一下童晶老师的C语言教学,有C基础和对小游戏感兴趣的可以看看,做出来成就感爆棚~
分享链接:点击打开链接
飞翔的小鸟-C语言版
其中有个问题是:“小鸟”和“障碍物”在同一水平轴时,会出现“障碍物右移情况”;
但是不是太想改,虽然会变得简单,但是可以让图案看起来不是那么的“单调”;
PS:运行界面改成白底黑字会更好看一些,(习惯透明度80%);
源码(不带要写注释了~哈哈):
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <conio.h> #include <windows.h> int h,w; int c=0; int score=0;//得分 int xn_x,xn_y; int b1,b2,b3; char asd; void startup(){ h=15; w=25; xn_x=0; xn_y=w/3; b3=w; b1=h/4; b2=h/2; } void show(){ int i,j; char dad; if(c==0){ printf("======================================\n"); printf("= ---飞翔的小鸟--- =\n"); printf("= 空格------控制小鸟移动 =\n"); printf("= 不要开中文输入法 =\n"); printf("= =\n"); printf("= =\n"); printf("= 闪屏纯属正 =\n"); printf("= ----倾白白 =\n"); printf("======================================\n"); c++; dad=getch(); } system("cls"); for(i=0;i<h;i++){ for(j=0;j<=w;j++){ if(i==xn_x && j==xn_y) printf("卐"); else if(j==b3&&(i<=b1||i>=b2)) printf("█"); else printf(" "); } printf("\n"); } printf("当前得分:%d",score); } void wuguan(){ int randx; if(xn_y==b3){ if(xn_x>b1&&xn_x<b2) score++; else{ printf("你死了~~\n"); c=3; asd=getch(); } } xn_x++; if(b3==0){ b3=w; b1=rand()%(h-5); randx=b1; b2=randx+h/4+2; } else b3--; Sleep(150); } void youguan(){ char input; if(kbhit()){ input=getch(); if(input==' ')xn_x-=3; } } int main(){ startup();//数据 while(1){ show();//显示画面 wuguan();//与用户无关变量 youguan();//与用户有关变量 if(c==3)break; } return 0; }每天比昨天更好一些