生活随笔
收集整理的這篇文章主要介紹了
项目: 用c++写一个养成类的游戏【QQ宠物】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
前言
用c++寫了一個類似與QQ寵物的養成類游戲,不過更像精武堂。
它是一個文字類的養成類游戲。
效果和代碼
效果圖如下:
#include<iostream>
#include<iomanip>
#include<windows.h>
#include<ctime>
#include <string>
#include<vector>
#include<algorithm>
#include <conio.h>
#include<mmsystem.h>
#pragma comment(lib,"Winmm.lib")
using namespace std
;
int i
,j
;
char choice
;
int money
=500;
int level
=0;
string value_father_name
;
string value_daughter_name
;
int value_birth_month
;
int value_birth_date
;
string value_daughter_constell
;
int value_daughter_baseinfo
[5];
string value_array_baseinfo_names
[5]={"體力","智力","魅力","道德","氣質"};
string constell_names
[12][2]={{"山羊座","水瓶座"},{"水瓶座","雙魚座"},{"雙魚座","白羊座"},{"白羊座","金牛座"},{"金牛座","雙子座"},{"雙子座","巨蟹座"},{"巨蟹座","獅子座"},{"獅子座","處女座"},{"處女座","天秤座"},{"天秤座","天蝎座"},{"天蝎座","射手座"},{"射手座","山羊座"}
};
int constell_dates
[]={20,19,21,20,21,22,23,23,23,24,23,22};
void people_menu()
{system("title QQ寵物");system("mode 40,25"); srand(time(NULL));mciSendString("open 背景.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);
}
void big_menu()
{system("cls");cout
<<"\n\n\n\n\n\n";cout
<<" 1、查看狀態\n\n";cout
<<" 2、安排行程\n\n";cout
<<" 3、與父親談話\n\n";cout
<<" 4、存檔\n\n";cout
<<" 5、讀檔\n\n";cout
<<" 6、幫助\n";mciSendString("stop bkmusic", NULL, 0, NULL);mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 背景.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);
}
void game()
{system("cls");int i
,j
;for(i
=1;i
<=29;i
++){system("cls");cout
<<"\n\n\n\n\n\n\n\n\n人物加載中";for(j
=1;j
<=i
;j
++){cout
<<"-";Sleep(5);}}cout
<<"\n\n 人物初始化完成\n";printf("\a");Sleep(350); system("cls");
}
void color(WORD c
);
void kongge(int sum
);
void chars(int sum
);
void print_linux();void color(WORD c
)
{SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE
), c
);
}
void kongge(int sum
)
{while (sum
--)printf(" ");
}
void chars(int sum
)
{while (sum
--)printf("#");
}void print_start()
{system("time /t");system("date /t");cout
<<endl
; kongge(17);chars(6);printf("\n");kongge(15);chars(11);printf("\n");kongge(14);chars(13);printf("\n");kongge(14);chars(2);color(0x04);chars(3);color(0x07);chars(2);color(0x04);chars(3);color(0x07);chars(3);printf("\n");kongge(14);chars(2);color(0x04);chars(1);color(0x07);chars(1);color(0x04);chars(1);color(0x07);chars(2);color(0x04);chars(1);color(0x07);chars(1);color(0x04);chars(1);color(0x07);chars(3);printf("\n");kongge(14);color(0x07);chars(4);color(0x06);chars(4);color(0x07);chars(5);printf("\n");kongge(14);color(0x07);chars(2);color(0x06);chars(8);color(0x07);chars(3);printf("\n");kongge(13);chars(3);color(0x08);chars(2);color(0x06);chars(4);color(0x08);chars(2);color(0x07);chars(4);printf("\n");kongge(12);color(0x07);chars(2);color(0x02);chars(11);color(0x07);chars(4);printf("\n");kongge(11);chars(2);color(0x02);chars(13);color(0x07);chars(4);printf("\n");kongge(10);chars(3);color(0x02);chars(13);color(0x07);chars(5);printf("\n");kongge(9);chars(3);color(0x02);chars(15);color(0x07);chars(5);printf("\n");kongge(8);chars(3);color(0x02);chars(16);color(0x07);chars(5);printf("\n");kongge(7);chars(4);color(0x02);chars(16);color(0x07);chars(5);printf("\n");kongge(7);chars(1);color(0x06);chars(2);color(0x07);chars(1);color(0x02);chars(14);color(0x02);chars(2);color(0x07);chars(4);color(0x06);chars(1);printf("\n");kongge(7);color(0x06);chars(4);color(0x07);chars(1);color(0x02);chars(13);color(0x06);chars(3);color(0x07);chars(2);color(0x06);chars(2);printf("\n");kongge(6);color(0x06);chars(5);color(0x07);chars(2);color(0x02);chars(10);color(0x07);chars(1);color(0x06);chars(9);printf("\n");kongge(2);color(0x06);chars(9);color(0x7);chars(1);color(0x02);chars(9);color(0x07);chars(2);color(0x06);chars(11);printf("\n");kongge(5);color(0x06);chars(8);color(0x07);chars(1);color(0x02);chars(6);color(0x07);chars(3);color(0x06);chars(10);printf("\n");kongge(3);color(0x06);chars(11);color(0x07);chars(9);color(0x06);chars(6);printf("\n");kongge(9);color(0x06);chars(4);color(0x07);chars(11);color(0x06);chars(3);printf("\n");color(0x06);
}
void choise_1()
{char a
;system("cls");cout
<<"\n\n你的信息: "<<endl
;cout
<<"姓名: "<<value_daughter_name
<<" 等級 : "<<level
<<endl
;printf("\n");cout
<<"生日: 1988-"<<value_birth_month
<<"-"<<value_birth_date
<<endl
;printf("\n");cout
<<"星座: "<<value_daughter_constell
<<endl
; printf("\n");cout
<<left
;for(i
=0;i
<5;i
++){cout
<<value_array_baseinfo_names
[i
]<<" : "<<setw(2)<<value_daughter_baseinfo
[i
];int solidCount
=value_daughter_baseinfo
[i
]/10;if(value_daughter_baseinfo
[i
]%10>=5){solidCount
++;}for(j
=0;j
<10;j
++) {if((j
+1)<=solidCount
)cout
<<"■"; elsecout
<<"□"; }cout
<<endl
<<endl
;}cout
<<"金錢:"<<money
<<endl
<<endl
; cout
<<"按任意鍵回到主菜單"; a
=getch();system("cls");
}void choise_2_1()
{int i
=0;int w
,d
;char a
;system("cls");w
=rand()%5+1;d
=rand()%2+1;if(money
>=60){cout
<<"\n\n經過一段時間的練武,你有了很大的進步"<<endl
<<endl
;cout
<<"\n屬性發生了如下變化:"<<endl
<<endl
;cout
<<" 體力 : "<<value_daughter_baseinfo
[0]<<"----->"<<value_daughter_baseinfo
[0]+w
;printf("\n\n");cout
<<" 道德 : "<<value_daughter_baseinfo
[3]<<"----->"<<value_daughter_baseinfo
[3]+d
;printf("\n\n");value_daughter_baseinfo
[0]+=w
;value_daughter_baseinfo
[3]+=d
;money
=money
-60;cout
<<"學習武術你花費了60金幣"<<endl
<<endl
;}else{cout
<<" \n\n\n你的金錢不足!\n";}cout
<<"\n 按任何鍵返回上一菜單";mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 1練武.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);a
=getch();system("cls");
}
void choise_2_2()
{int i
=0;int n1
,n2
,n3
,n4
,n5
;char a
;system("cls");n1
=rand()%2+1;n2
=rand()%4+1;n3
=rand()%1+1;n4
=rand()%3+1;n5
=rand()%2+1;if(money
>=200){cout
<<"\n\n經過一段時間的學習,你有了很大的進步"<<endl
<<endl
;cout
<<"\n屬性發生了如下變化:"<<endl
<<endl
;cout
<<" 體力 : "<<value_daughter_baseinfo
[0]<<"----->"<<value_daughter_baseinfo
[0]+n1
;printf("\n\n");cout
<<" 智力 : "<<value_daughter_baseinfo
[1]<<"----->"<<value_daughter_baseinfo
[1]+n2
;printf("\n\n");cout
<<" 魅力 : "<<value_daughter_baseinfo
[2]<<"----->"<<value_daughter_baseinfo
[2]+n3
;printf("\n\n");cout
<<" 道德 : "<<value_daughter_baseinfo
[3]<<"----->"<<value_daughter_baseinfo
[3]+n4
;printf("\n\n");cout
<<" 氣質 : "<<value_daughter_baseinfo
[4]<<"----->"<<value_daughter_baseinfo
[4]+n5
;printf("\n\n");value_daughter_baseinfo
[0]+=n1
;value_daughter_baseinfo
[1]+=n2
;value_daughter_baseinfo
[2]+=n3
;value_daughter_baseinfo
[3]+=n4
;value_daughter_baseinfo
[4]+=n5
;money
=money
-200;cout
<<"上學你花費了200金幣"<<endl
<<endl
;}else{cout
<<" \n\n\n你的金錢不足!\n";}cout
<<"\n 按任何鍵返回上一菜單";mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 2背書.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);a
=getch();system("cls");
}
void choise_2_3()
{int i
=0;int w
,d
;char a
;system("cls");w
=rand()%4+1;d
=rand()%3+1;if(money
>=100){cout
<<"\n\n經過一段時間禮法的學習,你有了很大的進步"<<endl
<<endl
;cout
<<"\n屬性發生了如下變化:"<<endl
<<endl
;cout
<<" 氣質 : "<<value_daughter_baseinfo
[4]<<"----->"<<value_daughter_baseinfo
[4]+w
;printf("\n\n");cout
<<" 道德 : "<<value_daughter_baseinfo
[3]<<"----->"<<value_daughter_baseinfo
[3]+d
;printf("\n\n");value_daughter_baseinfo
[4]+=w
;value_daughter_baseinfo
[3]+=d
;money
=money
-100;cout
<<"學習禮儀你花費了100金幣"<<endl
<<endl
;}else{cout
<<" \n\n\n你的金錢不足!\n";}cout
<<"\n 按任何鍵返回上一菜單";mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 3禮儀.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);a
=getch();system("cls");
}
void choise_2_4()
{int i
=0;int w
,d
;char a
;system("cls");w
=rand()%2+1;d
=rand()%3+1;if(money
>=80){cout
<<"\n\n出城修煉的一路,你斬妖除魔。"<<endl
<<endl
;cout
<<"\n屬性發生了如下變化:"<<endl
<<endl
;cout
<<" 體力 : "<<value_daughter_baseinfo
[0]<<"----->"<<value_daughter_baseinfo
[0]+w
;printf("\n\n");cout
<<" 魅力 : "<<value_daughter_baseinfo
[2]<<"----->"<<value_daughter_baseinfo
[2]+d
;printf("\n\n");value_daughter_baseinfo
[0]+=w
;value_daughter_baseinfo
[2]+=d
;money
=money
-80;cout
<<"修行的路上你花費了80金幣"<<endl
<<endl
;}else{cout
<<" \n\n\n你的金錢不足!\n";}cout
<<"\n 按任何鍵返回上一菜單";mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 4武打.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);a
=getch();system("cls");
}
void choise_2_5()
{char a
;int b
;b
=rand()%100+20;system("cls");cout
<<"\n\n經過一段時間的打工-------"<<endl
<<endl
;cout
<<"你獲得了"<<b
<<"金錢"<<endl
<<endl
; money
=money
+b
;cout
<<"\n 按任何鍵返回上一菜單";mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 5工作.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);a
=getch();system("cls");
}
void choise_2()
{char a
;system("cls");while(1){ mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL); printf("\n\n\n\n");cout
<<" 1.學習武藝"<<endl
<<endl
<<endl
;cout
<<" 2.上私塾"<<endl
<<endl
<<endl
;cout
<<" 3.學習禮法"<<endl
<<endl
<<endl
;cout
<<" 4.出城修煉"<<endl
<<endl
<<endl
;cout
<<" 5.打工賺錢"<<endl
<<endl
<<endl
; cout
<<"請選擇(按z回到主菜單):";a
=getch();switch(a
){case '1':choise_2_1();break;case '2':choise_2_2();break; case '3':choise_2_3();break;case '4':choise_2_4();break; case '5':choise_2_5();break;}if(a
=='z')break;system("cls");}system("cls");
}void choise_3(string value_daughter_name
)
{int a
;int i
=0; char b
;system("cls");a
=rand()%100;mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 交談.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); if(a
<=30) {cout
<<"\n\n\n\n父親 : "<< value_daughter_name
<<"你最近干的不錯"<<endl
<<endl
;cout
<<" 謝謝父親大人:你"<<endl
<<endl
;cout
<<"......."<<endl
<<endl
; cout
<<"\n在與父親的談話中你獲得了100零花錢"<<endl
;money
=money
+100; }if(a
>30&&a
<=80) {cout
<<"\n\n\n\n父親 : "<< value_daughter_name
<<"你要好好學習"<<endl
<<endl
;cout
<<" 知道了:你"<<endl
<<endl
;cout
<<"父親 : "<< value_daughter_name
<<"你的態度要端正"<<endl
<<endl
;cout
<<" 額額:你"<<endl
<<endl
;cout
<<"......."<<endl
<<endl
; cout
<<"\n你與父親談論的不愉快"<<endl
<<endl
;cout
<<"道德-5 氣質-3"<<endl
<<endl
;if(value_daughter_baseinfo
[3]>=5)value_daughter_baseinfo
[3]-=5;elsevalue_daughter_baseinfo
[3]=0;if(value_daughter_baseinfo
[4]>=3)value_daughter_baseinfo
[4]-=3;elsevalue_daughter_baseinfo
[4]=0;}if(a
>80) {cout
<<"\n\n\n父親 : "<< value_daughter_name
<<"最近看了一首歌挺不錯的。"<<endl
<<endl
;cout
<<"父親 : "<<"23歲的九局下半轉啊轉,"<<endl
<<endl
;cout
<<"父親 : "<<"我把帽子反戴還在期待逆轉"<<endl
<<endl
;cout
<<" 謝謝父親:你"<<endl
<<endl
;cout
<<" 我會努力學習的:你"<<endl
<<endl
; cout
<<"......."<<endl
<<endl
; cout
<<"你與父親談論的很開心愉快,談論中悟出了人生哲理。"<<endl
; cout
<<"全屬性個加2點"<<endl
;for(i
=0;i
<5;i
++){value_array_baseinfo_names
[i
]+=1;}}cout
<<"\n 按任何鍵返回主菜單";a
=getch();system("cls");
}void choise_45()
{char a
;system("cls");cout
<<"\n\n\n\n\n\n\n 維修中----------\n\n\n";cout
<<" 按任何鍵返回主菜單";mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 維修.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); a
=getch();system("cls");
}
void choise_6()
{char a
;system("cls");cout
<<"\n\n\n 游戲說明\n\n";cout
<<" 該游戲是一個養成類游戲,游戲的背景是\n\n";cout
<<"從1988年6月開始,你要通過操作企鵝來干一\n\n" ;cout
<<"些事情來提高企鵝的等級。\n\n\n"; cout
<<"按任意鍵回到主菜單"; mciSendString("stop bkmusic", NULL, 0, NULL); mciSendString("close bkmusic", NULL, 0, NULL);mciSendString("open 打字.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);a
=getch();system("cls");
}void birthday(int month
,int value_birth_month
,string value_father_name
)
{int a
;char b
;a
=rand()%300+200; system("cls");cout
<<"\n\n 彩蛋情節觸發\n"<<endl
; cout
<<"本月是你的生日。\n\n你的父親"<<value_daughter_name
<<"先生給你送了"<<a
<<"金幣。\n"<<endl
;cout
<<"按任意鍵回到主菜單"; money
=money
+a
;b
=getch();system("cls");
}void level_start()
{int i
=0;int temp
=999999; int a
[5];for(i
=0;i
<5;i
++){if(value_daughter_baseinfo
[i
]>0&&value_daughter_baseinfo
[i
]<10){a
[i
]=1;continue;}if(value_daughter_baseinfo
[i
]>=10&&value_daughter_baseinfo
[i
]<20){a
[i
]=2;continue;}if(value_daughter_baseinfo
[i
]>=20&&value_daughter_baseinfo
[i
]<32){a
[i
]=3;continue;}if(value_daughter_baseinfo
[i
]>=32&&value_daughter_baseinfo
[i
]<48){a
[i
]=4;continue;}if(value_daughter_baseinfo
[i
]>=48&&value_daughter_baseinfo
[i
]<66){a
[i
]=5;continue;}if(value_daughter_baseinfo
[i
]>=66&&value_daughter_baseinfo
[i
]<96){a
[i
]=6;continue;}if(value_daughter_baseinfo
[i
]>=96&&value_daughter_baseinfo
[i
]<120){a
[i
]=7;continue;}if(value_daughter_baseinfo
[i
]>=120){a
[i
]=8;continue;}}for(i
=0;i
<5;i
++){if(a
[i
]<temp
)temp
=a
[i
];}level
=temp
;
}
int main(void)
{char a
;people_menu();print_start();cout
<<"\n 按任意鍵進入游戲!"; a
=getch(); system("cls");system("color 03");system("title 游戲中"); value_daughter_baseinfo
[0]=rand()%10+1;value_daughter_baseinfo
[1]=rand()%10+3;value_daughter_baseinfo
[2]=rand()%10+6;value_daughter_baseinfo
[3]=rand()%10+5;value_daughter_baseinfo
[4]=rand()%10+6;cout
<<"\n\n\n\n\n\n";cout
<<" 父親的姓名 :";cin
>>value_father_name
;cout
<<endl
;cout
<<" 你的姓名 :";cin
>>value_daughter_name
;cout
<<endl
;cout
<<" 你的生日(月) :";cin
>>value_birth_month
;cout
<<endl
;cout
<<" 你的生日(日) :";cin
>>value_birth_date
;cout
<<endl
; value_daughter_constell
=constell_names
[value_birth_month
-1][value_birth_date
/constell_dates
[value_birth_month
-1]];for(int year
=1988;year
<=1988 + 9;year
++){for(int month
= (year
== 1988)? 6:1;month
<=12;month
++){if(month
== value_birth_month
){birthday(month
,value_birth_month
,value_father_name
);}big_menu();choice
=getch();switch(choice
){case '1':level_start();choise_1(); break;case '2':{choise_2();break;} case '3':choise_3(value_daughter_name
);break; case '4': choise_45();break;case '5': choise_45(); break;case '6': choise_6();break;default:system("cls");break;}}}return 0;
}
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的项目: 用c++写一个养成类的游戏【QQ宠物】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。