C语言简单钢琴

#include 
#include 
#include 
#include 
//低音
#define L1 262
#define L2 294
#define L3 330
#define L4 349
#define L5 392
#define L6 440
#define L7 493
//高音
#define N1 532
#define N2 588
#define N3 660
#define N4 698
#define N5 784
#define N6 880
#define N7 988
//半弦音
#define H1 1046
#define H2 1175
#define H3 1319
#define H4 1397
#define H5 1568
#define H6 1760
#define H7 1976
char mode='N';
void getS(char n)
{
	if(mode=='L')
	{
		switch(n)
		{
			case '1':Beep(L1,200);break;
			case '2':Beep(L2,200);break;
			case '3':Beep(L3,200);break;
			case '4':Beep(L4,200);break;
			case '5':Beep(L5,200);break;
			case '6':Beep(L6,200);break;
			case '7':Beep(L7,200);break;
		}
	}
	else if(mode=='N')
	{
		switch(n)
		{
			case '1':Beep(N1,200);break;
			case '2':Beep(N2,200);break;
			case '3':Beep(N3,200);break;
			case '4':Beep(N4,200);break;
			case '5':Beep(N5,200);break;
			case '6':Beep(N6,200);break;
			case '7':Beep(N7,200);break;
		}
		
	}
	else if(mode=='H')
	{
		switch(n)
		{
			case '1':Beep(H1,200);break;
			case '2':Beep(H2,200);break;
			case '3':Beep(H3,200);break;
			case '4':Beep(H4,200);break;
			case '5':Beep(H5,200);break;
			case '6':Beep(H6,200);break;
			case '7':Beep(H7,200);break;
		}
	}
}
void soundDis(char ch)
{
	switch(ch)
	{
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':getS(ch);break;
		case 'l':case'L':mode='L';break;
		case 'n':case'N':mode='N';break;
		case 'h':case'H':mode='H';break;
	}
	//Sleep(rand()%50);
}

void HideTheCursor()
{
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = FALSE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
int main()
{
	char ch;
	srand((unsigned)time(0));
	printf("L低音,N正常,H高音\n");
	HideTheCursor();
	while(1)
	{
		ch=getche();
		soundDis(ch);
	}
}

你可能感兴趣的:(C++)