别踩黑块

· · 个人记录

#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;
}