C语言编译键盘钢琴,键盘小钢琴[C语言][自持]
键盘小钢琴[C语言][自制]
大一上最喜欢的一个作品
。刚开始只是一个能自动发出小星星音乐的小程序XD
效果图:
代码如下:
/*This is a small piano.这是一个小钢琴哦~*/
#include
#include //非缓冲输入
#include
#include
#pragma warning(disable:4996) //to use getche() in VS needs it
#define TICK 450
#define DOH 523
#define RAY 587
#define MI 659
#define FA 698
#define SOH 784
#define LA 880
#define TEE 980
#define DOHH 1060
#define RAYH 1175
#define MIH 1318
#define FAH 1397
#define SOHH 1568
#define LAH 1760
#define TEEH 1976
void welcome(void);
void display(void);
void playmusic1(void); //play music with color
void playmusic2(void); //play music without color
void thanks(void);
void choose1(void); //choose a type
void choose2(void); //choose a song
void song1(void);
void song2(void);
char a;
int choice,choice2;
int main(void)
{
welcome();
if (choice == 2)
{
printf("Enter numbers to play music:('p' to quit)\n");
while (1)
{
playmusic1();
if (a == 'p')
break;
}
}
else
{
printf("Please choose the song you want to play:\n"
"1.Castle In The Sky(天空之城)\n2.星の在り処(星之所在)\n");
choose2();
}
thanks();
return 0;
}
void welcome(void)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
printf("1-DOH 2-RAY 3-MI 数字1到7,字母Q\n"
"4-FA 5-SOH 6-LA WERTYU分别对应音阶\n"
"7-TEE Q-DOHH W-RAYH\n"
"E-MIH R-FAH T-SOH\n"
"Y-LAH U-TEEH\n");
display();
choose1();
}
void display(void)
{
int i;
for (i = 0; i < 80; i++)
printf("=");
}
void choose1(void)
{
printf("Choose a game type:\n1.play songs(弹奏模式)\t2.free play(自由模式)\n");
while ((scanf("%d", &choice)) != 1)
{
while (getchar() != '\n');
printf("Please enter a number ~");
}
display();
}
void choose2(void)
{
while ((scanf("%d", &choice2)) != 1)
{
while (getchar() != '\n')
printf("Please enter a number ~");
}
display();
if (choice2 == 1)
song1();
else song2();
printf("Enter numbers to play music:('p' to quit)\n");
while (1)
{
playmusic2();
if (a == 'p')
break;
}
}
void playmusic1(void) //发声并设置颜色
{
a = getch();
switch (a)
{
case '1':Beep(DOH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 30); printf("DOH "); break;
case '2':Beep(RAY, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 60); printf("RAY "); break;
case '3':Beep(MI, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 90); printf("MI "); break;
case '4':Beep(FA, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 120); printf("FA "); break;
case '5':Beep(SOH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 150); printf("SOH "); break;
case '6':Beep(LA, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 180); printf("LA "); break;
case '7':Beep(TEE, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 210); printf("TEE "); break;
case 'q':Beep(DOHH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 30); printf("DOHH "); break;
case 'w':Beep(RAYH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 60); printf("RAYH "); break;
case 'e':Beep(MIH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 90); printf("MIH "); break;
case 'r':Beep(FAH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 120); printf("FA "); break;
case 't':Beep(SOHH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 150); printf("SOH "); break;
case 'y':Beep(LAH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 180); printf("LA "); break;
case 'u':Beep(TEEH, TICK); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 210); printf("TEE "); break;
case '\n':break;
default :break;
}
}
void playmusic2(void) //发声
{
a = getch();
switch (a)
{
case '1':Beep(DOH, TICK); break;
case '2':Beep(RAY, TICK); break;
case '3':Beep(MI, TICK); break;
case '4':Beep(FA, TICK); break;
case '5':Beep(SOH, TICK); break;
case '6':Beep(LA, TICK); break;
case '7':Beep(TEE, TICK); break;
case 'q':Beep(DOHH, TICK); break;
case 'w':Beep(RAYH, TICK); break;
case 'e':Beep(MIH, TICK); break;
case 'r':Beep(FAH, TICK); break;
case 't':Beep(SOHH, TICK); break;
case 'y':Beep(LAH, TICK); break;
case 'u':Beep(TEEH, TICK); break;
case '\n':break;
default:break;
}
}
void thanks(void)
{
putchar('\n');
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
display();
printf("Thanks for playing~~~\n");
system("pause");
}
void song1(void) //天空之城
{
printf("67Q7QE7 3656Q5 3434Q3 \n");
}
void song2(void) //星之所在
{
printf("Q7QE7 656Q5 434Q75 67QEW Q7QE75 67QWE REWQ7E\n");
}
版权声明:欢迎转载(^ω^)~不过转载请注明原文出处:http://blog.csdn.net/catglory ლ(╹◡╹ლ)
C语言编译键盘钢琴,键盘小钢琴[C语言][自持]相关推荐
- c语言编译开头,#includestdio.h,为什么C语言代码开头都有这一行?
作者 闫小林 白天搬砖,晚上做梦.我有故事,你有酒么? #include是在程序编译之前要进行处理的的内容,因此也称为预处理命令. 先介绍下include,include是一个计算机专业术语,指C/C ...
- golang语言编译的二进制可执行文件为什么比 C 语言大(转载)
最近一位朋友问我"为什么同样的hello world 入门程序"为什么golang编译出来的二进制文件,比 C 大,而且大很多.我做了个测试,来分析这个问题.C 语言的hello ...
- c语言编译时检查逻辑错误吗,C语言陷阱与技巧20节,自定义“编译时”assert方法,在代码编译阶段检查“逻辑”错误...
在C语言程序开发中,程序员写代码时应该考虑的"面面俱到",这样才能写出功能稳定的程序.例如,在实现 open() 函数时,先完成它的功能固然是重要的,但是程序员还需要考虑各种&qu ...
- 单片机c语言编译软件6,eUIDE下载-单片机c语言编译器 v1.07.32.23 官方版 - 安下载...
eUIDE是一款专业的单片机c语言编译器,EM78系列集成开发环境是面向项目的ELAN EM78系列微控制器的开发工具,它包括UICE开发在线仿真器和eUIDE软件工具:eUIDE是基于PC端的UIC ...
- c语言有啥简单的小程序,c语言-简单小程序-简单算法
<c语言-简单小程序-简单算法>由会员分享,可在线阅读,更多相关<c语言-简单小程序-简单算法(19页珍藏版)>请在人人文库网上搜索. 1.以下小程序都在 TC2.0 中运行通 ...
- c语言编译自顶向下程序设计,广东工业大学C语言程序设计考试试卷(3份)
内容简介: 广东工业大学C语言程序设计考试试卷(06,A) 一.判断题(正确打"√",错误打"×")(每题1分,共10分) 1.C程序是以函数为单位进行编译的. ...
- c语言编译如何去掉warning,16种C语言编译警告(Warning)类型的解决方法
当编译程序发现程序中某个地方有疑问,可能有问题时就会给出一个警告信息.警告信息可能意味着程序中隐含的大错误,也可能确实没有问题.对于警告的正确处理方式应该是:尽可能地消除之.对于编译程序给出的每个警告 ...
- c语言编译 创建卡号信息表,C语言超市会员信息管理系统源程序
#include //编译预处理指令,引入头文件 #include #include #include #define MAX 10 ...
- C语言编译发现注释错误,在对C语言程序进行编译时,可以发现注释行中的拼写错误。...
对中些设括哪备都包水压试验. 各适条件用于什么,语言程译品的在产主要种计算有几方法. 门客南王汉淮编著文的汉代学及其集体刘安一书是西术散,序进行编现注"女奔月"等及寓就是天&quo ...
- C语言编译能否被七整除,求c语言高手输出1000以内既能被5整除又能被7整除
公告: 为响应国家净网行动,部分内容已经删除,感谢读者理解. 话题:求c语言高手 输出1000以内既能被5整除又能被7整除的数,要求五个数回答:int main(){int num =0;for(in ...
最新文章
- Set Up Optimization
- SQLite的事务和锁
- 手机qq浏览器怎么设置上下翻页按钮 手机qq浏览器设置上下翻页按钮的方法
- 一个简单的重命名,在git中也有这么多学问
- 4. Linux 系统目录
- IDM下载---一键安装版
- 如何找回QQ聊天记录、语音、图片?
- python linspace函数_等差数列与linspace函数
- 类案检索功能优化建议(一)——开发路径辨析
- Excel的序列号转换的算法
- 计算机科学技术的广告语,赞美科技的句子-十大经典深入人心科技类广告语
- 如何使用QT实现左右滑动的按钮
- 场地测量的方法和程序_施工测量的基本方法
- android 有哪些设备id,Android之设备ID(Device ID)
- 使用scrapy框架做武林中文网的爬虫
- python程序设计与算法基础第二版课后答案_python算法与程序设计基础答案
- MapGuide 初步
- glTF学习笔记(0)——概述
- QGC地面站中视频流配置及gstreamer安装
- go操作mysql(原生database/sql, sqlx库)GORM