跳到正文

个人记录

别踩黑块

zjy1437约 4 分钟
原文

这是 2025年10月20日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年10月12日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 4 分钟

版本

  1. v2当前
  2. v1
C++
#include <windows.h>
#include <iostream>
#include <conio.h>
#include <cstdio>
#include <random>
#include <ctime>
#include <cmath>
#define KEY 4
#define LEN 50
#define DIS 20

using namespace std;

mt19937 rng(time(0));

const int TOT=LEN+DIS+5;

int note[TOT],keyboard[4]={'d','f','j','k'};
int pow10[7]={1,10,100,1000,10000,100000,1000000};

int pts,Combo,maxCombo;
int lstNote=-1; 
int calScore()
{
	double sc1=900000.0/LEN*pts;
	double sc2=100000.0/LEN*maxCombo;
	return int(sc1+sc2);
}
void printScore(int score)
{
	int a[7]={0};
	for(int i=0;i<7;i++)
	{
		a[i]=(score/pow10[i])%10;
	}
	printf("Score: ");
	for(int i=6;i>=0;i--)
	{
		printf("%d",a[i]);
	}
	printf("\n");
}
int main()
{
	for(int i=1; i<=LEN; i++)
	{
		note[i]=rng()%4;
		//note[i]=(i+1)%2+1;
	}
	for(int i=LEN-DIS; i>=-DIS; i--)
	{
		system("cls");
		if(i!=LEN-DIS)
		{
			printf("%.2lf\%\n",100.0*(pts*1.0/(LEN-(i+DIS))));
		}
		printScore(calScore());
		if(Combo>=3)
		{
			printf("  COMBO\n %4d\n",Combo);
		}
		else
		{
			printf("\n\n");
		}
		if(i<=1)
		{
			for(int j=i; j<=1; j++)
			{
				printf("\n");
			}
		}
		for(int j=max(1,i); j<=i+DIS; j++)
		{
			for(int k=1; k<=note[j]; k++)
			{
				printf("  ");
			}
			printf("__\n");
		}
		for(int j=1; j<=KEY; j++)
		{
			printf("__");
		}
		printf("\n");
		for(int j=0;j<KEY;j++)
		{
			printf("%c ",keyboard[j]+('A'-'a'));
		}
		printf("\n");
		if(lstNote==0)
		{
			printf("\n\tMiss\n");
		}
		else if(lstNote==1)
		{
			printf("\n\tCatch\n");
		}
		char ch=_getch();
		if((ch==keyboard[0] && note[i+DIS]==0) || (ch==keyboard[1] && note[i+DIS]==1) || (ch==keyboard[2] && note[i+DIS]==2) || (ch==keyboard[3] && note[i+DIS]==3))
		{
			pts++;
			Combo++;
			maxCombo=max(maxCombo,Combo);
			lstNote=1;
		}
		else
		{
			Combo=0;
			lstNote=0;
		}
	}
	printf("Catch: %4d \t Miss: %4d",pts,LEN-pts);
	return 0;
}