Aqui les dejo un sencillo programa en C que simula un piano de 7 teclas coincidentes con el do, re, mi, fa, sol, la, si.
Para los sonidos empleo los beep del PC.
codigo:
#include <winbgim.h>
#include <iostream>
#include <math.h>
#include <windows.h>
/* DEFINICION DE LAS TECLAS
NOMENCLATURA: TeclaColor -> ejemplo: TAZUL
SETFILLSTYLE: (tipo, color)
BAR (X inicial, Y inicial, X final, Y final
BEEP (frecuencia en Herzios, Duracion en Milisegundos*/
#define temp 500 //Duracion en milisegundos de las notas
#define tneg 150 //longitud de las teclas negras
#define Si setfillstyle(1,BLANCO);bar(600,0,698,300);setfillstyle(1,NEGRO);bar(600,0,610,tneg);settextstyle(5,0,4);outtextxy(633,305,"si");//Beep(800,temp);
#define La setfillstyle(1,BLANCO);bar(500,0,598,300);setfillstyle(1,NEGRO);bar(500,0,510,tneg);bar(588,0,598,tneg);settextstyle(5,0,4);outtextxy(530,305,"la");//Beep(704,temp);
#define Sol setfillstyle(1,BLANCO);bar(400,0,498,300);setfillstyle(1,NEGRO);bar(488,0,498,tneg);bar(400,0,410,tneg);settextstyle(5,0,4);outtextxy(430,305,"sol");//Beep(660,temp);
#define Fa setfillstyle(1,BLANCO);bar(300,0,398,300);setfillstyle(1,NEGRO);bar(388,0,398,tneg);bar(300,0,310,tneg);settextstyle(5,0,4);outtextxy(330,305,"Fa");//Beep(594,temp);
#define Mi setfillstyle(1,BLANCO);bar(200,0,298,300);setfillstyle(1,NEGRO);bar(200,0,210,tneg);bar(288,0,298,tneg);settextstyle(5,0,4);outtextxy(230,305,"mi");//Beep(528,temp);
#define Re setfillstyle(1,BLANCO);bar(100,0,198,300);setfillstyle(1,NEGRO);bar(188,0,198,tneg);bar(100,0,110,tneg);settextstyle(5,0,4);outtextxy(130,305,"re");//Beep(495,temp);
#define Do setfillstyle(1,BLANCO);bar(0,0,98,300);setfillstyle(1,NEGRO);bar(88,0,98,tneg);settextstyle(5,0,4);outtextxy(30,305,"do");//Beep(420,temp);
/* DEFINICION DE LOS COLORES */
#define AZUL 1
#define VERDE 2
#define ROJO 4
#define MAGENTA 5
#define MARRON 6
#define GRIS 7
#define VERDECLARO 10
#define AMARILLO 14
#define BLANCO 15
#define NEGRO 0
/*Sonidos*/
#define si Beep(800,temp);
#define la Beep(704,temp);
#define sol Beep(660,temp);
#define fa Beep(594,temp);
#define mi Beep(528,temp);
#define re Beep(495,temp);
#define doo Beep(450,temp);
/* ############################################################################
FUNCIONES */
void IniciarWinbgim(); // inicia la pantalla de la WINBGIM
void Menu();
void Inicio();
void Juego();
void Instrucciones();
void Open();
void Autor();
void Bye();
/* ############################################################################
CUERPOS DE LAS FUNCIONES */
void IniciarWinbgim()
{
initwindow(698,400); // abre la pantalla de la WINBGIM a x=698, y=600
}
void Menu()
{
setfillstyle(1,NEGRO);bar(0,0,698,400);
setfillstyle(4,BLANCO);bar(0,0,698,100);
setfillstyle(5,BLANCO);bar(0,150,698,250);
setcolor(ROJO);
settextstyle(2,0,15);
outtextxy(20,100,"BepPiano");
setcolor(BLANCO);
settextstyle(1,0,1);
outtextxy(280,280,"1- Tocar"); // ascii 49
outtextxy(280,310,"2- Instrucciones"); // ascii 50
outtextxy(280,340,"3- Autor"); // ascii 51
int aux=0;
while (aux==0)
{
int menu=(int)getch();
//printf("%d",menu);
switch (menu)
{
case 49:
Inicio();
aux=1;
case 50:
Instrucciones();
aux=1;
case 51:
Autor();
aux=1;
case 27:
Bye();
aux=1;
}
}
}
void Open()
{
// variables necesarias para el rectangulo blanco en apertura de la presentacion
int x1=359;
int y1=200;
int x2=359;
int y2=200;
while (x1>=0) //bucle para aumentar las coordenadas del rectangulo
{
setcolor(BLANCO);
rectangle(x1,y1,x2,y2);
x1--;
x2++;
y1--;
y2++;
delay (1);
}
}
void Inicio()
{
// barrido negro para borrar pantalla y poner las teclas
int lx1=0;
int ly1=0;
int ly2=400;
while (lx1<=698)
{
setcolor(NEGRO);
line(lx1,ly1,lx1,ly2);
lx1++;
delay(1);
while(lx1==98)
{
Do;
doo;
break;
}
while(lx1==198)
{
Re;
re;
break;
}
while(lx1==298)
{
Mi;
mi;
break;
}
while(lx1==398)
{
Fa;
fa;
break;
}
while(lx1==498)
{
Sol;
sol;
break;
}
while(lx1==598)
{
La;
la;
break;
}
while(lx1==698)
{
Si;
si;
break;
}
}
Juego();
}
void Juego()
{
int melodia[99];
int c,t; // c es el total de teclas que puedes pulsar y t el tiempo que
//permanecen los textos de las notas en pantalla
t=200;
for (c=0; c<888; c++)
{
int tecla=(int)getch();
//printf("%d",tecla);
switch (tecla)
{
case 97: // tecla A nota DO
setfillstyle(1,GRIS);bar(0,0,98,300);setfillstyle(1,NEGRO);bar(88,0,98,tneg);
setcolor(BLANCO);
settextstyle(5,0,4);
outtextxy(40,320,"do");
doo;
delay(t);
setfillstyle(1,BLANCO);bar(0,0,98,300);setfillstyle(1,NEGRO);bar(88,0,98,tneg);
setcolor(NEGRO);
outtextxy(40,320,"do");
break;
case 115:
setfillstyle(1,GRIS);bar(100,0,198,300);setfillstyle(1,NEGRO);bar(188,0,198,tneg);bar(100,0,110,tneg);
setcolor(BLANCO);
settextstyle(5,0,4);
outtextxy(140,320,"re");
re;
delay(t);
setfillstyle(1,BLANCO);bar(100,0,198,300);setfillstyle(1,NEGRO);bar(188,0,198,tneg);bar(100,0,110,tneg);
setcolor(NEGRO);
outtextxy(140,320,"re");
break;
case 100:
setfillstyle(1,GRIS);bar(200,0,298,300);setfillstyle(1,NEGRO);bar(200,0,210,tneg);bar(288,0,298,tneg);
setcolor(BLANCO);
settextstyle(5,0,4);
outtextxy(240,320,"mi");
mi;
delay(t);
setfillstyle(1,BLANCO);bar(200,0,298,300);setfillstyle(1,NEGRO);bar(200,0,210,tneg);bar(288,0,298,tneg);
setcolor(NEGRO);
outtextxy(240,320,"mi");
break;
case 102:
setfillstyle(1,GRIS);bar(300,0,398,300);setfillstyle(1,NEGRO);bar(388,0,398,tneg);bar(300,0,310,tneg);
setcolor(BLANCO);
settextstyle(5,0,4);
outtextxy(340,320,"fa");
fa;
delay(t);
setfillstyle(1,BLANCO);bar(300,0,398,300);setfillstyle(1,NEGRO);bar(388,0,398,tneg);bar(300,0,310,tneg);
setcolor(NEGRO);
outtextxy(340,320,"fa");
break;
case 106:
setfillstyle(1,GRIS);bar(400,0,498,300);setfillstyle(1,NEGRO);bar(488,0,498,tneg);bar(400,0,410,tneg);
setcolor(BLANCO);
settextstyle(5,0,4);
outtextxy(440,320,"sol");
sol;
delay(t);
setfillstyle(1,BLANCO);bar(400,0,498,300);setfillstyle(1,NEGRO);bar(488,0,498,tneg);bar(400,0,410,tneg);
setcolor(NEGRO);
outtextxy(440,320,"sol");
break;
case 107:
setfillstyle(1,GRIS);bar(500,0,598,300);setfillstyle(1,NEGRO);bar(500,0,510,tneg);bar(588,0,598,tneg);
setcolor(BLANCO);
settextstyle(5,0,4);
outtextxy(540,320,"la");
la;
delay(t);
setfillstyle(1,BLANCO);bar(500,0,598,300);setfillstyle(1,NEGRO);bar(500,0,510,tneg);bar(588,0,598,tneg);
setcolor(NEGRO);
outtextxy(540,320,"la");
break;
case 108:
setfillstyle(1,GRIS);bar(600,0,698,300);setfillstyle(1,NEGRO);bar(600,0,610,tneg);
setcolor(BLANCO);
settextstyle(5,0,4);
outtextxy(640,320,"si");
si;
delay(t);
setfillstyle(1,BLANCO);bar(600,0,698,300);setfillstyle(1,NEGRO);bar(600,0,610,tneg);
setcolor(NEGRO);
outtextxy(640,320,"si");
break;
case 27:
Bye();
}
}
}
void Instrucciones()
{
setfillstyle(1,NEGRO);bar(0,0,698,400);
setfillstyle(4,BLANCO);bar(0,0,698,100);
setfillstyle(5,BLANCO);bar(0,150,698,250);
setcolor(ROJO);
settextstyle(2,0,15);
outtextxy(20,100,"Instrucciones");
setcolor(BLANCO);
settextstyle(6,0,1);
outtextxy(10,280,"El BepPiano consta de 7 teclas correspondientes a las notas");
outtextxy(10,310,"do, re, mi, fa, sol, la, si. Para hacerlo sonar pulsa las teclas:");
outtextxy(10,340,"a=do, s=re, d=mi, f=fa, j=sol, k=la, l=si");
outtextxy(10,370,"La tecla Bloc Mayus a de estar desactivada (en minusculas).");
int menu=(int)getch();
Menu();
}
void Autor()
{
setfillstyle(1,NEGRO);bar(0,0,698,400);
setfillstyle(4,BLANCO);bar(0,0,698,100);
setfillstyle(5,BLANCO);bar(0,150,698,250);
setcolor(ROJO);
settextstyle(2,0,15);
outtextxy(20,100,"Autor");
setcolor(BLANCO);
settextstyle(6,0,1);
outtextxy(10,280,"BepPiano.");
outtextxy(10,310,"Creado por Radon");
outtextxy(10,340,"Code en e-r00t");
int menua=(int)getch();
Menu();
}
void Bye()
{
Open();
setfillstyle(1,NEGRO);
bar(0,0,698,400);
settextstyle(6,0,1);
outtextxy(100,200,"Adios!!!.");
delay(800);
exit(-1);
}
int main()
{
IniciarWinbgim();
Menu();
return 0;
}
esta compilado con el devc++
Autor: Radón