跳到正文

剪贴板

剪贴板 vb7kxr7v

原文
剪贴板信息

剪贴板信息

收录
更新

飞扬的小鸟简陋版,早期代码,去年12月的样子写的,突然翻出来了。改了一下,因为是早期的码,所以码风奇怪。放心,我的windows.h只是用来清屏和停顿的。想跳过开头把main里面的func2()注释了就行了。

正常版:

C++
#include <iostream>
#include <ctime>
#include <windows.h>
#include <sys/timeb.h>
#include <bitset>
#define key_down(a) ((GetAsyncKeyState(a) & 0x8000) ? 1:0)//判断键盘是否按下按键,按下按键就返回true,否则返回false,调用这个宏时,填入要监测的字母的大写字母就行了,记住,是大写字母
using namespace std;
long double func(){//获取时间戳
	timeb t;
	ftime(&t);
	return t.time+t.millitm/1000.0;
}
void func2(){
	for (int i=3;i>=1;--i){
		for (int j=0;j<5;++j){
			cout<<"                              "<<endl;
		}
		cout<<"              "<<i<<endl;
		Sleep(1000);
		system("cls");
	}
	for (int j=0;j<5;++j){
		cout<<"                              "<<endl;
	}
	cout<<"              开始游戏!"<<endl;
	Sleep(1000);
}
int main(){
    cout.tie(0);
	system("title 飞扬的小鸟");//控制台题目
	func2();//开头画面
	long long brid_y=5,zhuzi_x=0,defen=0;
	string h[12]={"                              "};
	while (true){
		for (int i=0;i<12;++i){
			h[i]="                              ";
		}
		int zhuzi_gao_up,zhuzi_gao_down;
		if (zhuzi_x==0){
			srand(time(0));
			int o=rand()%6;
			zhuzi_gao_up=o+6,zhuzi_gao_down=o+3;
			zhuzi_x=29;
		}
		cout<<"按下空格可以控制小鸟的飞行!\n松掉空格可以让小鸟下落!\n";
		cout<<"小鸟碰到柱子分数减少!\n";
		cout<<"按下b游戏结束!              得分:"<<defen<<endl;
		cout<<"——————————————————————————————\n";
		for (int i=0;i<12;++i){
			if (i<zhuzi_gao_down || i>zhuzi_gao_up){
				h[i][zhuzi_x-1]='|';
			}
		}
		if (h[brid_y-1][4]=='|'){
			defen-=2;
		}
		h[brid_y-1][4]='*';
		if (zhuzi_x==4 && h[brid_y-1][5]==' ') defen++;
		for (int t=0;t<12;++t){
			cout<<h[t]<<endl;
		}
		cout<<"——————————————————————————————\n";
		double start=func();
		bool flag=false,tflag=false;
		while (true){
			if (key_down('B') && !tflag){
				tflag=true;
			}
			if (key_down(' ') && !flag){
				brid_y--;
				flag=true;
			}
			if (key_down('B') && !tflag){
				tflag=true;
			}
			if (func()-start>=0.1) break;
			if (key_down('B') && !tflag){
				tflag=true;
			}
			if (key_down(' ') && !flag){
				brid_y--;
				flag=true;
			}
			if (key_down('B') && !tflag){
				tflag=true;
			}
		}
		if (tflag) break;
		if (!flag) brid_y++;
		if (brid_y>12) brid_y=12;
		if (brid_y<1) brid_y=1;
		system("cls");
		zhuzi_x-=1;
	}
	system("cls");
	cout<<"你的得分是:"<<defen<<endl;
	cout<<"本程序做了防误触功能,请自行退出~";
	while (1+1==2);//避免用户过于生气,提前先把控制台退了,就不能看到分数了,所以就造了个死循环
}

不正常版:

C++
#include <iostream>
#include <ctime>
#include <windows.h>
#include <sys/timeb.h>
#include <bitset>
#define key_down(a) ((GetAsyncKeyState(a) & 0x8000) ? 1:0)
using namespace std;
long double func(){
	timeb t;
	ftime(&t);
	return t.time+t.millitm/1000.0;
}
void func2(){
	for (int i=3;i>=1;--i){
		for (int j=0;j<5;++j){
			cout<<"                              "<<endl;
		}
		cout<<"              "<<i<<endl;
		Sleep(1000);
		system("cls");
	}
	for (int j=0;j<5;++j){
		cout<<"                              "<<endl;
	}
	cout<<"              开始游戏!"<<endl;
	Sleep(1000);
}
int main(){
	ios::sync_with_stdio(0);
    cout.tie(0);
	system("title 飞扬的小鸟");
	func2();
	long long brid_y=5,zhuzi_x=0,defen=0;
	string h[12]={"                              "};
	while (true){
		for (int i=0;i<12;++i){
			h[i]="                              ";
		}
		int zhuzi_gao_up,zhuzi_gao_down;
		if (zhuzi_x==0){
			srand(time(0));
			int o=rand()%6;
			zhuzi_gao_up=o+6,zhuzi_gao_down=o+3;
			zhuzi_x=29;
		}
		cout<<"按下空格可以控制小鸟的飞行!\n松掉空格可以让小鸟下落!\n";
		cout<<"小鸟碰到柱子分数减少!\n";
		cout<<"按下b游戏结束!              得分:"<<defen<<endl;
		cout<<"——————————————————————————————\n";
		for (int i=0;i<12;++i){
			if (i<zhuzi_gao_down || i>zhuzi_gao_up){
				h[i][zhuzi_x-1]='|';
			}
		}
		if (h[brid_y-1][4]=='|'){
			defen-=2;
		}
		h[brid_y-1][4]='*';
		if (zhuzi_x==4 && h[brid_y-1][5]==' ') defen++;
		for (int t=0;t<12;++t){
			cout<<h[t]<<endl;
		}
		cout<<"——————————————————————————————\n";
		double start=func();
		bool flag=false,tflag=false;
		while (true){
			if (key_down('B') && !tflag){
				tflag=true;
			}
			if (key_down(' ') && !flag){
				brid_y--;
				flag=true;
			}
			if (key_down('B') && !tflag){
				tflag=true;
			}
			if (func()-start>=0.1) break;
			if (key_down('B') && !tflag){
				tflag=true;
			}
			if (key_down(' ') && !flag){
				brid_y--;
				flag=true;
			}
			if (key_down('B') && !tflag){
				tflag=true;
			}
		}
		if (tflag) break;
		if (!flag) brid_y++;
		if (brid_y>12) brid_y=12;
		if (brid_y<1) brid_y=1;
		system("cls");
		zhuzi_x-=1;
	}
	system("cls");
	cout<<"你的得分是:"<<defen<<endl;
	cout<<"本程序做了防误触功能,请自行退出~";
	while (1+1==2);
}

为神马加了个ios::sync_with_stdio(0);就不正常啦QWQ