SDL不使用SDL_mixer怎么才能播放声音? 能给代码加注释最好...谢谢了
一般SDL播放声音需要SDL_mixer来播放但是不需要SDL_mixer也是可以播放声音的只是比较复杂...希望大侠们帮个忙告诉我一下不用SDL_Mixer也能播放声音...
一般SDL 播放声音 需要 SDL_mixer 来播放 但是 不需要 SDL_mixer 也是可以 播放声音的 只是 比较复杂... 希望 大侠们帮个忙 告诉我一下 不用 SDL_Mixer 也能播放声音
展开
2011-04-20
展开全部
e”conio.h”#include”stdlib.
h”#include”dos.h”#include”time.h”
int a[16+1][30+1];/*数组用来存放地雷和数字的
*/多出一个是用来控制边界的
int flag1,flag2;/*长宽调整标志*/
int color_flag=1,lei_number=10,high=8,width=8,face_
flag=1;
struct time1/*调用时间函数*/
{unsigned char ti_min; unsigned char ti_hour; unsigned char
ti_hund; unsigned char ti_sec;}t;
void rect()
{ /*本模块的功能是在C界面上画边框,以增加C的
友好性和可观性*/
int i; textcolor(14); textbackground(color_flag);
clrscr();/*设置字体和背景颜色*/
gotoxy(1,2);putchar(201);/*左上角*/
for(i=1;i<79;i++)
/*直线*/
putchar(187);/*右上角*/
for(i=2;i<23;i++)
/*直线*/
gotoxy(80,24);putchar(188);/*右下角*/
for(i=1;i<79;i++)
/*竖线*/
gotoxy(1,24);putchar(200);/*右上角*/
for(i=2;i<23;i++)
/*竖线*/
gotoxy(30,1);cprintf(“WELCOMETO SAOLEI!”);
gotoxy(28,25);cprintf(“COPYRIGHT---LANGCY--
-2002”);}
void rect_s()
{ int i;/*根据长宽调整标志画边框*/
gotoxy(flag2-1,flag1-1);putchar(218);
gotoxy(flag2+width*2-1,flag1-1);putchar(191);
gotoxy(flag2-1,flag1+high);putchar(192);
gotoxy(flag2+width*2-1,flag1+high);putchar(217);
for(i=flag2;i<flag2+width*2-1;i++)
{gotoxy(i,flag1-1);putchar(196);
gotoxy(i,flag1+high);putchar(196);}
for(i=flag1;i<flag1+high;i++)
{gotoxy(flag2-1,i);putchar(179);
gotoxy(flag2+width*2-1,i);putchar(179);}}
void color()/*颜色选择*/
{ char ch; rect();
gotoxy(25,6);cprintf(”This is the color table!”);
gotoxy(30,8);cprintf(”1-black”); gotoxy(30,9);cprintf(”
2-blue”);
gotoxy(30,10);cprintf(”3-green”); gotoxy(30,11);cprintf
(”4-bluesky”);
gotoxy(30,12);cprintf(”5-red”); gotoxy(30,13);cprintf(”
6-pink”);
gotoxy(30,14); cprintf(”7-yellow”); gotoxy(30,15);
cprintf(”8-gray”);
gotoxy(30,16);cprintf(”ESC-main menu”);
gotoxy(25,18);cprintf(”Please choose the color numble:”);
while(1)
{ch=getch();
switch(ch)
{case’1’: color_flag=0;cprintf(”black!”);break;
case’2’: color_flag=1;cprintf(”blue!”);break;
case’3’: color_flag=2;cprintf(”green!”);break;
case’4’: color_flag=3;cprintf(”bluesky!”);break;
case’5’: color_flag=4;cprintf(”red!”);break;
case’6’: color_flag=5;cprintf(”pink!”);break;
case’7’: color_flag=6;cprintf(”yellow!”);break;
case’8’: color_flag=7;cprintf(”gray!”);break;
case 27: main();break;
case 13: main();break;
default :break;}}}
void size()/*选择大小*/
{ char ch; rect();
gotoxy(25,8);cprintf(”This is the lei_size table!”);
gotoxy(30,10);cprintf(”1--high=8,width=8”); gotoxy
(30,11);cprintf(”2--high=8,width=16”);
gotoxy(30,12);cprintf(”3--high=16,width=16”); go-
toxy(30,13);cprintf(”4--high=16,width=20”);
gotoxy(30,14);cprintf(”5--high=16,width=25”); go-
toxy(30,15);cprintf(”6--high=16,width=30”);
gotoxy(30,16);cprintf(”ESC-main menu”);
gotoxy(25,18);cprintf(”Please choose the lei_numble:”);
while(1)
{ch=getch();
switch(ch)
{ case’1’: high=8;width=8;cprintf(”high=8,width=
8”);break;
case’2’: high=8;width=16;cprintf(”high=8,width=
16”);break;
case’3’: high=16;width=16;cprintf(”high=16,width=
16”);break;
case’4’: high=16;width=20;cprintf(”high=16,width=
20”);break;
case’5’: high=16;width=25;cprintf(”high=16,width=
25”);break;
case’6’: high=16;width=30;cprintf(”high=16,width=
30”);break;
case 27: main();break;
case 13: main();break;
default :break; }}}
void lei_num()/*选择雷的数目*/
{ char ch; rect();
gotoxy(25,8);cprintf(”This is the lei_number table!”);
gotoxy(30,10);cprintf(”1-10”); gotoxy(30,11);cprintf(”
2-20”); gotoxy(30,12);cprintf(”3-40”);
gotoxy(30,13);cprintf(”4-50”); gotoxy(30,14);cprintf(”
5-80”); gotoxy(30,15);cprintf(”6-100”);
gotoxy(30,16);cprintf(”ESC-main menu”);
gotoxy(25,18);cprintf(”Please choose the lei_numble:”);
while(1)
{ch=getch();
switch(ch)
{ case’1’: lei_number=10;cprintf(”10”);break;
case’2’: lei_number=20;cprintf(”20”);break;
case’3’: lei_number=40;cprintf(”40”);break;
case’4’: lei_number=50;cprintf(”50”);break;
case’5’: lei_number=80;cprintf(”80”);break;
case’6’: lei_number=100;cprintf(”100”);break;
case 27: main();break;
case 13: main();break;
default :break; }}}
void face()/*选择图标*/
{ char ch; rect();
gotoxy(25,8);cprintf(”This is the face table!”);
gotoxy(30,10);cprintf(”1--smail face”); gotoxy(30,
11);cprintf(”2--heart”);
gotoxy(30,12);cprintf(”3--rectangle”); gotoxy(30,13);
cprintf(”4--flower”);
gotoxy(30,14);cprintf(”5--peach”); gotoxy(30,15);
cprintf(”6--music”);
gotoxy(30,16);cprintf(”ESC-main menu”);
gotoxy(25,18);cprintf(”Please choose the face:”);
while(1)
{ch=getch();
switch(ch)
{ case’1’:face_flag=1;printf(”smail face!”);break;
case’2’: face_flag=3;printf(”heart!”);break;
case’3’: face_flag=4;printf(”rectangle!”);break;
case’4’: face_flag=5;printf(”flower!”);break;
case’5’: face_flag=6;printf(”peach!”);break;
case’6’: face_flag=14;printf(”music!”);break;
case 27: main();break; case 13: main();break; default :
break;}}}
void fail()/*没有扫成功,重新再来*/
{ int i,j,t3,t4; char ch; flag1=(23-high)/2+2; flag2=
(80-2*width)/2;
for(i=1,t3=flag1;i<high+1;i++,t3++)
for(j=1,t4=flag2;j<width+1;j++,t4+=2)
{ gotoxy(t4,t3); if(a[i][j]==-1) putchar(15); else
printf(”%d”,a[i][j]); }
gotoxy(25,23);printf(”Do you want to continue? <y/n
>”);
ch=getch(); if(ch==’y’||ch==’Y’) saolei(); else
main();}
void succeed()/*扫雷成功,再来否*/
{ char ch; gotoxy(30,22);cprintf(”Congradulation! You
win!”);
gotoxy(25,23);printf(”Do you want to continue? <y/n
>”); ch=getch();
if(ch==’y’||ch==’Y’) saolei(); else main();}
saolei()/*扫雷函数*/
{ int i,j,countlei,left=lei_number,time_flag1,time_flag2;
int t1=1,t2=1,lei_flag=0,t3,t4; char ch; rect();
flag1=(23-high)/2+2; flag2=(80-2*width)/2;
for(i=0;i<high+1;i++)
for(j=0;j<width+1;j++)
a[i][j]=0;/*初始值*/
while(lei_flag<=lei_number)
{ t1=1+random(high);t2=1+random(width);
if(a[t1][t2]! =-1)
}/*随机赋地雷*/
for(i=1;i<high+1;i++)
for(j=1;j<width+1;j++)
{ if(a[i][j]! =-1)
{ countlei=0;/*由于上面已经考虑了边界,这里不需
判断边界*/
if(a[i-1][j-1]==-1) countlei++; if(a[i-1][j]=
=-1) countlei++;
if(a[i-1][j+1]==-1) countlei++;if(a[i][j-1]=
=-1) countlei++;
if(a[i][j+1]==-1) countlei++; if(a[i+1][j-1]=
=-1) countlei++;
if(a[i+1][j]==-1) countlei++; if(a[i+1][j+1]=
=-1) countlei++;
a[i][j]=countlei; } }/*计算各个地区周围的地雷的
数目*/
rect_s();/*画小边框*/
for(i=1,t3=flag1;i<high+1;i++,t3++)
for(j=1,t4=flag2;j<width+1;j++,t4+=2)
gotoxy(4,3);cprintf(”Left:%3d”,left); gotoxy(70,3);
cprintf(”Time:000”);
gettime(&t);/*从系统中取出时间*/
time_flag1=(int)t.ti_min*60+(int)t.ti_sec; i=1;j=1;
while(1)/*键盘操作*/
{ /*72-up,75-left,77-right,80-down,27-esc,13
-enter,32-space*/
gettime(&t);
time_flag2=(int)t.ti_min*60+(int)t.ti_sec-time_
flag1;
gotoxy(68,3);cprintf(”Time:%3d”,time_flag2);
gotoxy(flag2,flag1); ch=getch();
switch(ch) { case 72 : i--;flag1--; if(i<=0) {i+
+;flag1++;} /*判断越界*/
gotoxy(flag2,flag1); break;
case 75 : j--;flag2-=2; if(j<=0) {j++;flag2+=
2;} gotoxy(flag2,flag1); break; case 77 : j++;flag2+=
2;if(j>width) gotoxy(flag2,flag1);
break;
case 80 : i++;flag1++; if(i>high) {i--;flag1-
-;} gotoxy(flag2,flag1); break;
case 32 : if(a[i][j]==-1)
{ putchar(15);left--; if(left==0) succeed();go-
toxy(4,3);cprintf(”Left:%3d”,left);
gotoxy(flag2,flag1); } else fail(); break;
case 13 : if(a[i][j]! =-1)
if(a[i][j]==-1) fail(); break;
case 27 : main();break;
default : break;}}}
main()/*主函数*/
{ char ch; rect();
gotoxy(25,7);printf(”This is the main menu!”);
gotoxy(30,9);printf(”Enter-start!”); gotoxy(30,10);
printf(”1--Choose the color!”);
gotoxy(30,11);printf(”2--Choose the size!”); gotoxy
(30,12);printf(”3--Choose the lei_number!”);
gotoxy(30,13);printf(”4--Choose the face!”); gotoxy
(30,14);printf(”ESC--exit!”);
gotoxy(25,16);printf(”Please select what you want!”);
while(1)
{ch=getch();
switch(ch)
{case’1’: color();break;
case’2’: size();break;
case’3’: lei_num();break;
case’4’: face();break;
case 27: rect();
gotoxy(30,13);
printf(”Thank you ! Good Bye!”);
getch();
exit(0);break;
case 13:
saolei();break;
default :break;}}}
另外,站长团上有产品团购,便宜有保证
h”#include”dos.h”#include”time.h”
int a[16+1][30+1];/*数组用来存放地雷和数字的
*/多出一个是用来控制边界的
int flag1,flag2;/*长宽调整标志*/
int color_flag=1,lei_number=10,high=8,width=8,face_
flag=1;
struct time1/*调用时间函数*/
{unsigned char ti_min; unsigned char ti_hour; unsigned char
ti_hund; unsigned char ti_sec;}t;
void rect()
{ /*本模块的功能是在C界面上画边框,以增加C的
友好性和可观性*/
int i; textcolor(14); textbackground(color_flag);
clrscr();/*设置字体和背景颜色*/
gotoxy(1,2);putchar(201);/*左上角*/
for(i=1;i<79;i++)
/*直线*/
putchar(187);/*右上角*/
for(i=2;i<23;i++)
/*直线*/
gotoxy(80,24);putchar(188);/*右下角*/
for(i=1;i<79;i++)
/*竖线*/
gotoxy(1,24);putchar(200);/*右上角*/
for(i=2;i<23;i++)
/*竖线*/
gotoxy(30,1);cprintf(“WELCOMETO SAOLEI!”);
gotoxy(28,25);cprintf(“COPYRIGHT---LANGCY--
-2002”);}
void rect_s()
{ int i;/*根据长宽调整标志画边框*/
gotoxy(flag2-1,flag1-1);putchar(218);
gotoxy(flag2+width*2-1,flag1-1);putchar(191);
gotoxy(flag2-1,flag1+high);putchar(192);
gotoxy(flag2+width*2-1,flag1+high);putchar(217);
for(i=flag2;i<flag2+width*2-1;i++)
{gotoxy(i,flag1-1);putchar(196);
gotoxy(i,flag1+high);putchar(196);}
for(i=flag1;i<flag1+high;i++)
{gotoxy(flag2-1,i);putchar(179);
gotoxy(flag2+width*2-1,i);putchar(179);}}
void color()/*颜色选择*/
{ char ch; rect();
gotoxy(25,6);cprintf(”This is the color table!”);
gotoxy(30,8);cprintf(”1-black”); gotoxy(30,9);cprintf(”
2-blue”);
gotoxy(30,10);cprintf(”3-green”); gotoxy(30,11);cprintf
(”4-bluesky”);
gotoxy(30,12);cprintf(”5-red”); gotoxy(30,13);cprintf(”
6-pink”);
gotoxy(30,14); cprintf(”7-yellow”); gotoxy(30,15);
cprintf(”8-gray”);
gotoxy(30,16);cprintf(”ESC-main menu”);
gotoxy(25,18);cprintf(”Please choose the color numble:”);
while(1)
{ch=getch();
switch(ch)
{case’1’: color_flag=0;cprintf(”black!”);break;
case’2’: color_flag=1;cprintf(”blue!”);break;
case’3’: color_flag=2;cprintf(”green!”);break;
case’4’: color_flag=3;cprintf(”bluesky!”);break;
case’5’: color_flag=4;cprintf(”red!”);break;
case’6’: color_flag=5;cprintf(”pink!”);break;
case’7’: color_flag=6;cprintf(”yellow!”);break;
case’8’: color_flag=7;cprintf(”gray!”);break;
case 27: main();break;
case 13: main();break;
default :break;}}}
void size()/*选择大小*/
{ char ch; rect();
gotoxy(25,8);cprintf(”This is the lei_size table!”);
gotoxy(30,10);cprintf(”1--high=8,width=8”); gotoxy
(30,11);cprintf(”2--high=8,width=16”);
gotoxy(30,12);cprintf(”3--high=16,width=16”); go-
toxy(30,13);cprintf(”4--high=16,width=20”);
gotoxy(30,14);cprintf(”5--high=16,width=25”); go-
toxy(30,15);cprintf(”6--high=16,width=30”);
gotoxy(30,16);cprintf(”ESC-main menu”);
gotoxy(25,18);cprintf(”Please choose the lei_numble:”);
while(1)
{ch=getch();
switch(ch)
{ case’1’: high=8;width=8;cprintf(”high=8,width=
8”);break;
case’2’: high=8;width=16;cprintf(”high=8,width=
16”);break;
case’3’: high=16;width=16;cprintf(”high=16,width=
16”);break;
case’4’: high=16;width=20;cprintf(”high=16,width=
20”);break;
case’5’: high=16;width=25;cprintf(”high=16,width=
25”);break;
case’6’: high=16;width=30;cprintf(”high=16,width=
30”);break;
case 27: main();break;
case 13: main();break;
default :break; }}}
void lei_num()/*选择雷的数目*/
{ char ch; rect();
gotoxy(25,8);cprintf(”This is the lei_number table!”);
gotoxy(30,10);cprintf(”1-10”); gotoxy(30,11);cprintf(”
2-20”); gotoxy(30,12);cprintf(”3-40”);
gotoxy(30,13);cprintf(”4-50”); gotoxy(30,14);cprintf(”
5-80”); gotoxy(30,15);cprintf(”6-100”);
gotoxy(30,16);cprintf(”ESC-main menu”);
gotoxy(25,18);cprintf(”Please choose the lei_numble:”);
while(1)
{ch=getch();
switch(ch)
{ case’1’: lei_number=10;cprintf(”10”);break;
case’2’: lei_number=20;cprintf(”20”);break;
case’3’: lei_number=40;cprintf(”40”);break;
case’4’: lei_number=50;cprintf(”50”);break;
case’5’: lei_number=80;cprintf(”80”);break;
case’6’: lei_number=100;cprintf(”100”);break;
case 27: main();break;
case 13: main();break;
default :break; }}}
void face()/*选择图标*/
{ char ch; rect();
gotoxy(25,8);cprintf(”This is the face table!”);
gotoxy(30,10);cprintf(”1--smail face”); gotoxy(30,
11);cprintf(”2--heart”);
gotoxy(30,12);cprintf(”3--rectangle”); gotoxy(30,13);
cprintf(”4--flower”);
gotoxy(30,14);cprintf(”5--peach”); gotoxy(30,15);
cprintf(”6--music”);
gotoxy(30,16);cprintf(”ESC-main menu”);
gotoxy(25,18);cprintf(”Please choose the face:”);
while(1)
{ch=getch();
switch(ch)
{ case’1’:face_flag=1;printf(”smail face!”);break;
case’2’: face_flag=3;printf(”heart!”);break;
case’3’: face_flag=4;printf(”rectangle!”);break;
case’4’: face_flag=5;printf(”flower!”);break;
case’5’: face_flag=6;printf(”peach!”);break;
case’6’: face_flag=14;printf(”music!”);break;
case 27: main();break; case 13: main();break; default :
break;}}}
void fail()/*没有扫成功,重新再来*/
{ int i,j,t3,t4; char ch; flag1=(23-high)/2+2; flag2=
(80-2*width)/2;
for(i=1,t3=flag1;i<high+1;i++,t3++)
for(j=1,t4=flag2;j<width+1;j++,t4+=2)
{ gotoxy(t4,t3); if(a[i][j]==-1) putchar(15); else
printf(”%d”,a[i][j]); }
gotoxy(25,23);printf(”Do you want to continue? <y/n
>”);
ch=getch(); if(ch==’y’||ch==’Y’) saolei(); else
main();}
void succeed()/*扫雷成功,再来否*/
{ char ch; gotoxy(30,22);cprintf(”Congradulation! You
win!”);
gotoxy(25,23);printf(”Do you want to continue? <y/n
>”); ch=getch();
if(ch==’y’||ch==’Y’) saolei(); else main();}
saolei()/*扫雷函数*/
{ int i,j,countlei,left=lei_number,time_flag1,time_flag2;
int t1=1,t2=1,lei_flag=0,t3,t4; char ch; rect();
flag1=(23-high)/2+2; flag2=(80-2*width)/2;
for(i=0;i<high+1;i++)
for(j=0;j<width+1;j++)
a[i][j]=0;/*初始值*/
while(lei_flag<=lei_number)
{ t1=1+random(high);t2=1+random(width);
if(a[t1][t2]! =-1)
}/*随机赋地雷*/
for(i=1;i<high+1;i++)
for(j=1;j<width+1;j++)
{ if(a[i][j]! =-1)
{ countlei=0;/*由于上面已经考虑了边界,这里不需
判断边界*/
if(a[i-1][j-1]==-1) countlei++; if(a[i-1][j]=
=-1) countlei++;
if(a[i-1][j+1]==-1) countlei++;if(a[i][j-1]=
=-1) countlei++;
if(a[i][j+1]==-1) countlei++; if(a[i+1][j-1]=
=-1) countlei++;
if(a[i+1][j]==-1) countlei++; if(a[i+1][j+1]=
=-1) countlei++;
a[i][j]=countlei; } }/*计算各个地区周围的地雷的
数目*/
rect_s();/*画小边框*/
for(i=1,t3=flag1;i<high+1;i++,t3++)
for(j=1,t4=flag2;j<width+1;j++,t4+=2)
gotoxy(4,3);cprintf(”Left:%3d”,left); gotoxy(70,3);
cprintf(”Time:000”);
gettime(&t);/*从系统中取出时间*/
time_flag1=(int)t.ti_min*60+(int)t.ti_sec; i=1;j=1;
while(1)/*键盘操作*/
{ /*72-up,75-left,77-right,80-down,27-esc,13
-enter,32-space*/
gettime(&t);
time_flag2=(int)t.ti_min*60+(int)t.ti_sec-time_
flag1;
gotoxy(68,3);cprintf(”Time:%3d”,time_flag2);
gotoxy(flag2,flag1); ch=getch();
switch(ch) { case 72 : i--;flag1--; if(i<=0) {i+
+;flag1++;} /*判断越界*/
gotoxy(flag2,flag1); break;
case 75 : j--;flag2-=2; if(j<=0) {j++;flag2+=
2;} gotoxy(flag2,flag1); break; case 77 : j++;flag2+=
2;if(j>width) gotoxy(flag2,flag1);
break;
case 80 : i++;flag1++; if(i>high) {i--;flag1-
-;} gotoxy(flag2,flag1); break;
case 32 : if(a[i][j]==-1)
{ putchar(15);left--; if(left==0) succeed();go-
toxy(4,3);cprintf(”Left:%3d”,left);
gotoxy(flag2,flag1); } else fail(); break;
case 13 : if(a[i][j]! =-1)
if(a[i][j]==-1) fail(); break;
case 27 : main();break;
default : break;}}}
main()/*主函数*/
{ char ch; rect();
gotoxy(25,7);printf(”This is the main menu!”);
gotoxy(30,9);printf(”Enter-start!”); gotoxy(30,10);
printf(”1--Choose the color!”);
gotoxy(30,11);printf(”2--Choose the size!”); gotoxy
(30,12);printf(”3--Choose the lei_number!”);
gotoxy(30,13);printf(”4--Choose the face!”); gotoxy
(30,14);printf(”ESC--exit!”);
gotoxy(25,16);printf(”Please select what you want!”);
while(1)
{ch=getch();
switch(ch)
{case’1’: color();break;
case’2’: size();break;
case’3’: lei_num();break;
case’4’: face();break;
case 27: rect();
gotoxy(30,13);
printf(”Thank you ! Good Bye!”);
getch();
exit(0);break;
case 13:
saolei();break;
default :break;}}}
另外,站长团上有产品团购,便宜有保证
追问
= =. 播放音乐啊 大哥, 不是 扫雷
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询