跳到正文

个人记录

?!底力?! ?!弱弱?!

Yang_Xi约 7 分钟
原文
文章信息与版本

文章信息

收录
2026年7月5日
更新
2026年7月6日
篇幅
约 7 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
#define rtm ((long double)clock()/CLOCKS_PER_SEC) 
using namespace std;
int nw=0,nx[50],md=0,sc=0,gst=0,keys=4,high=10,bk=0,MAXbk=12;
string bks[]={"■","□","▲","△","▼","▽","●","○","◆","◇","★","☆"};
long double tm_=0,tm2=0,tm3=0;
int inp(){
	system("cls");
	cout<<"input the number...\n";
	int a;
	cin>>a;
	return a;
}
void pst(){
	cout<<"pause\n";
	cout<<"[q]:set keys\n";
	cout<<"[w]:set view\n";
	cout<<"[r]:restart\n";
}
void pgm(){
	cout<<"score: "<<sc<<' ';
	if(gst)cout<<"time: "<<rtm-tm_+tm2;
	else cout<<"ready to start";
	cout<<'\n';
	for(int i=high-1;i>=0;i--){
		int f=nx[(nw+i)%high];
		for(int i=1;i<=f;i++)cout<<"  ";
		cout<<bks[bk]; 
		for(int i=1;i<=keys-1-f;i++)cout<<"  ";
		cout<<'\n';
	}
	if(keys==2)cout<<"g h";
	else if(keys==4)cout<<"f g h j\n";
	else if(keys==6)cout<<"d f g h j k\n";
	else if(keys==8)cout<<"s d f g h j k l\n";
}
void pgo(){
	cout<<"game over\n";
	cout<<"score: "<<sc<<'\n';
	cout<<"time: "<<tm3-tm_+tm2<<'\n';
	cout<<"cps: "<<sc/(tm3-tm_+tm2)<<'\n';
	cout<<"keys: "<<keys<<'\n';
	cout<<"press esc to continue...";
}
void prt(){
	system("cls");
	if(md==2)pgo();
	else if(md==1)pst();
	else if(md==0)pgm();
}
void initg(){
	srand(time(0));
	for(int i=0;i<high;i++)nx[i]=rand()%keys;
	tm_=tm2=tm3=sc=0;
}
void stks(){
	system("cls");
	cout<<"keys: < "<<keys<<" > \n";
	cout<<"press enter to continue...";
	int f=_getch();
	if(f==75){
		if(keys>2)keys-=2;
	}
	else if(f==77){
		if(keys<8)keys+=2;
	}
	else if(f==13){
		initg();
		return;
	}
	stks();
}
void stvw(int x){
	system("cls");
	cout<<"high:  < "<<setw(2)<<high<<" >"<<(x==1?'*':' ')<<"\n";
	cout<<"block: < "<<bks[bk]<<" >"<<(x==2?'*':' ')<<"\n";
	cout<<"press enter to continue...";
	int f=_getch(),x2=x;
	if(f==13){
		initg();
		return;
	}
	else if(x==1){
		if(f==75){
			if(high>1)high--;
		}
		else if(f==77){
			if(high<30)high++;
		}
		else if(f==80)x2=2;
		else if(f==8){
			int k=inp();
			if(1<=k&&k<=30)high=k;
		}
	}//72
	else if(x==2){
		if(f==75){
			if(bk>0)bk--;
		}
		else if(f==77){
			if(bk<MAXbk-1)bk++;
		}
		else if(f==72)x2=1;
	}
	stvw(x2);
}
void res(){
	gst=0;
}
int main(){
	cout<<setfill(' ');
	initg();
	prt();
	while(1){
		int f=_getch();
		if(md==2){
			if(f==27){
				md=0;
				initg();
			}
		}
		else if(f==27){
			if(md==0){
				md=1;
				if(gst)tm2+=rtm-tm_;
			}
			else{
				md=0;
				tm_=rtm;
			}
		}
		else if(md==0){
			int k;
			if(keys==2){
				if(!(f=='g'||f=='h'))continue;
				if(f=='g')k=0;
				if(f=='h')k=1;
			}
			else if(keys==4){
				if(!(f=='f'||f=='g'||f=='h'||f=='j'))continue;
				if(f=='f')k=0;
				if(f=='g')k=1;
				if(f=='h')k=2;
				if(f=='j')k=3;
			}
			else if(keys==6){
				if(!(f=='d'||f=='f'||f=='g'||f=='h'||f=='j'||f=='k'))continue;
				if(f=='d')k=0;
				if(f=='f')k=1;
				if(f=='g')k=2;
				if(f=='h')k=3;
				if(f=='j')k=4;
				if(f=='k')k=5;
			}
			else if(keys==8){
				if(!(f=='s'||f=='d'||f=='f'||f=='g'||f=='h'||f=='j'||f=='k'||f=='l'))continue;
				if(f=='s')k=0;
				if(f=='d')k=1;
				if(f=='f')k=2;
				if(f=='g')k=3;
				if(f=='h')k=4;
				if(f=='j')k=5;
				if(f=='k')k=6;
				if(f=='l')k=7;
			}
			if(!gst&&k==nx[nw%high]){
				gst=1;
				tm_=rtm;
			}
			if(gst){
				if(k==nx[nw%high]){
					sc++;
					nx[(nw++)%high]=rand()%keys;
				}
				else md=2,tm3=rtm,res();
			}
		}
		else if(md==1){
			if(f=='q')stks();
			if(f=='w')stvw(1);
			if(f=='r')res(),md=0,initg();
		}
		prt();
//		cout<<f<<' ';
	}
	return 0;
}
原文