注册 登录
编程论坛 C语言论坛

求解答:贪吃蛇小游戏如何插入背景音乐?

永远没有永远 发布于 2019-12-24 15:39, 3989 次点击
求解答:贪吃蛇游戏如何插入背景音乐?
我做了一个贪吃蛇小游戏,求问如何插入音乐。
 用的编译器是C-free5。
 试过的代码如下:
#include <stdio.h>
 #include <Windows.h>
 #include <mmsystem.h>
 #pragma comment(lib, "WINMM.LIB")

 int main(  )
 {
     PlaySoundA( "E:\\作业\\计算机程序设计作业\\大作业\\u06wt232.wav", NULL, SND_FILENAME|SND_ASYNC );
     puts( " -------- " );
     system( "pause" );
     PlaySoundA( NULL, NULL, SND_FILENAME|SND_ASYNC );
     return 0;

 }


  #include <stdio.h>
  #include <windows.h>
  #include <mmsystem.h>
  #pragma comment(lib, "winmm.lib")
 int  main(){
  PlaySound (TEXT("E:\\作业\\计算机程序设计作业\\大作业\\u06wt232.wav"), NULL, SND_ASYNC | SND_NODEFAULT);
   
  while (1)
  {
    printf("program is running... here\n");   //这里跑你的程序,按 Ctrl-C  组合键,结束程序。
  Sleep(1000);  //休息1秒
}
exit(0);
  }


 #include<stdio.h>
 #include<stdlib.h>
 #include<windows.h>
 #include <mmsystem.h>//导入声音头文件
#pragma comment(lib,"Winmm.lib")
 int main()
 {
     sndPlaySound("E:\\作业\\计算机程序设计作业\\大作业\\u06wt232.wav",SND_ASYNC);
      while (1)
     {
        printf("program is running... here\n");
     }
 }


  

都会报错[Error] C:\Users\desty\Documents\C-Free\Temp\未命名3.cpp:8: undefined reference to `PlaySoundA@12'
 [Error] collect2: ld returned 1 exit status
求教感谢!
4 回复
#2
rjsp2019-12-24 16:46
mingw 认识 #pragma comment(lib, "WINMM.LIB") 吗?
自己加
#3
永远没有永远2019-12-24 17:10
试过了
是这样的
[Warning] D:\C-FREE~1\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\backward\backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

[Error] D:\C-FREE~1\mingw\bin\ld.exe: cannot find -lWINMM.LIB

[Error] collect2: ld returned 1 exit status
#4
rjsp2019-12-24 18:18
[Error] D:\C-FREE~1\mingw\bin\ld.exe: cannot find -lWINMM.LIB

link参数加  -lWINMM 试试,注意大小写,你自己查一查文件名是什么
#5
永远没有永远2019-12-24 19:34
非常感谢!
现在不报错了……
但是没声音
1