实验五
1.猫猫狗狗
1 #include<string> 2 using namespace std; 3 #include<iostream> 4 #include"aa.h" 5 6 class MachinePets{ 7 public: 8 MachinePets(const string s):nickname(s){ 9 } 10 string getNickname()const{ 11 return nickname; 12 } 13 virtual void talk()=0; 14 private: 15 string nickname; 16 }; 17 18 class PetCats:public MachinePets{ 19 public: 20 PetCats(const string s):MachinePets(s){ 21 } 22 void talk(){ 23 cout<<getNickname()<<" says "<<endl; 24 string s = "D:\\myvideo\\cat.wav\\10652.wav";// "bt.wav"; 25 wchar_t wText[30] = { 0 }; 26 MByteToWChar(s.c_str(), wText, sizeof(wText) / sizeof(wText[0])); 27 PlaySound(wText, NULL, SND_FILENAME | SND_SYNC); 28 29 } 30 }; 31 32 class PetDogs:public MachinePets{ 33 public: 34 PetDogs(const string s):MachinePets(s){ 35 } 36 void talk(){ 37 cout<<getNickname()<<" says "<<"ma"<<endl; 38 string s = "D:\\myvideo\\dog.wav\\1022.wav";// "bt.wav"; 39 wchar_t wText[30] = { 0 }; 40 MByteToWChar(s.c_str(), wText, sizeof(wText) / sizeof(wText[0])); 41 PlaySound(wText, NULL, SND_FILENAME | SND_SYNC); 42 } 43 }; 44 45 void play(MachinePets *p) { 46 p->talk(); 47 } 48 49 int main(){ 50 PetCats cat("miku"); 51 PetDogs dog("da huang"); 52 53 play(&cat); 54 play(&dog); 55 56 return 0; 57 }
1 #ifndef AA_H 2 #define AA_H 3 #include <Windows.h> 4 #include <mmsystem.h> 5 6 #include <iostream> 7 #include <stdlib.h> 8 #include <time.h> 9 #include <assert.h> 10 11 #pragma comment(lib,"WinMM.Lib") 12 13 using namespace std; 14 15 16 BOOL MByteToWChar(LPCSTR lpcszStr, LPWSTR lpwszStr, DWORD dwSize) 17 { 18 // Get the required size of the buffer that receives the Unicode 19 // string. 20 DWORD dwMinSize; 21 dwMinSize = MultiByteToWideChar(CP_ACP, 0, lpcszStr, -1, NULL, 0); 22 assert(dwSize >= dwMinSize); 23 24 // Convert headers from ASCII to Unicode. 25 MultiByteToWideChar(CP_ACP, 0, lpcszStr, -1, lpwszStr, dwMinSize); 26 return TRUE; 27 } 28 29 30 #endif
2.
(1)#ifndef _CONTAINER
(2)numOfHeal--;
(3) p.bag.set(0,0); bag.set(p.bag.nOfHeal()+bag.nOfHeal(),p.bag.nOfMW()+bag.nOfHeal());
(4)void showinfo(player &p1, player &p2)
(5)public player
(6)cout<<setw(50)<<"you lose"<<endl;
(7)cout<<endl<<setw(50)<<"GAME OVER"<<endl;
在写的过程中,查找音频花去了不少时间,还有就是小细节问题,容易导致程序运行出错。
评论地址:
https://www.cnblogs.com/shy0825/
https://www.cnblogs.com/changtingzao/
https://www.cnblogs.com/elise00/