c++ 小游戏 NO 7 打怪游戏(无聊)
生活随笔
收集整理的這篇文章主要介紹了
c++ 小游戏 NO 7 打怪游戏(无聊)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最后一章有驚喜:
int dadaj() {string c[10],dr[10],zb[20],daojv[11];cout<<"你好,歡迎"<<endl;int a=-1,h,x=0,dj=1,jy=0,p=150,s=0,ss=0,dh1=0,dg1=0,ddj=0,nd=1,cf=0,cd1=0,cd2=0,xl=0,drcf1=0,tx=-1;//b 地點//a 動作//h 血量//x 技能//hh 回合//d1 怪物序號//dj 等級//jy 經驗//p 經驗閾值//ss 傷害//s 提升十級//dh1 怪物血量//dg1 怪物傷害//ddj 怪物掉落經驗//bf baff//cf 財富//ys 元素 0.火 1.水 2.草 3.雷 4.冰//ys1 技能//ys2 敵人被克制//xl 血量j[1]=1;j[2]=2;j[3]=3;j[4]=4;zbcc[1]=1;zbcc[2]=1;daojv[1]="小回血藥";daojvsx[1]=50;cfdaojv[1]=50;daojvlb[1]=1;daojv[2]="中回血藥";daojvsx[2]=500;cfdaojv[2]=500;daojvlb[2]=1;daojv[3]="大回血藥";daojvsx[3]=5000;cfdaojv[3]=5000;daojvlb[3]=1;daojv[4]="小攻擊藥";daojvsx[4]=50;cfdaojv[4]=50;daojvlb[4]=2;daojv[5]="中攻擊藥";daojvsx[5]=500;cfdaojv[5]=500;daojvlb[5]=2;daojv[6]="大攻擊藥";daojvsx[6]=5000;cfdaojv[6]=5000;daojvlb[6]=2;cout<<"版本1.1"<<endl;while(1) {h=100+xl;cout<<"難度"<<nd<<endl;dh[1]=100+dh1;dg[1]=15+dg1;ys2[1]=3;drcf[1]=5+drcf1;dr[1]="北極獅王";dh[2]=200+dh1;dg[2]=20+dg1;ys2[2]=1;drcf[2]=10+drcf1;dr[2]="玫瑰妖精";c[1]="火拳";ys1[1]=1;cs[1]=50+ss;c[2]="水波";ys1[2]=2;cs[2]=30+ss;c[3]="汲取";ys1[3]=3;cs[3]=20+ss;c[4]="震雷";ys1[4]=4;cs[4]=40+ss;c[5]="冰凍";ys1[5]=4;cs[5]=35+ss;zb[1]="木劍";zbsx[1]=10;yszb[1]=0;cfzb[1]=10;lb[1]=0;zb[2]="布甲";zbsx[2]=25;yszb[2]=0;cfzb[2]=10;lb[2]=1;zb[3]="鐵劍";zbsx[3]=50;yszb[3]=0;cfzb[3]=50;lb[3]=0;zb[4]="鐵甲";zbsx[4]=75;yszb[4]=0;cfzb[4]=50;lb[4]=1;zb[5]="火之高興";zbsx[5]=100;cfzb[5]=200;yszb[5]=1;lb[5]=0;zb[6]="火甲";zbsx[6]=25;yszb[6]=1;cfzb[6]=200;lb[6]=1;zb[7]="霜之哀傷";zbsx[7]=100;cfzb[7]=200;yszb[7]=4;lb[7]=0;zb[8]="冰甲";zbsx[8]=25;yszb[8]=4;cfzb[8]=200;lb[8]=1;cout<<"1.野外 2.狀態 3.技能 4.商店 5.裝備 "<<endl;cin>>b[0];if(b[0]==1) {//戰斗cout<<"1.獅群 2.花圃"<<endl;cin>>b[1];if(b[1]==1) {cout<<"你遇到了北極獅王 "<<endl;}if(b[1]==2) {cout<<"你遇到了玫瑰妖精"<<endl;}while(dh[b[1]]>0&&h>0) {cout<<"1.攻擊 2.道具 3.逃跑"<<endl;cin>>a;if(a==1) {cout<<"1."<<c[j[1]]<<"2."<<c[j[2]]<<"3."<<c[j[3]]<<"4."<<c[j[4]]<<endl;cin>>x;dh[b[1]]=dh[b[1]]-cs[j[x]];bf[x]++;cout<<"hp-"<<cs[j[x]]<<endl;if(j[x]==3) {hh[0]=3;}if(ys1[j[x]]==ys2[b[1]]) {cout<<"敵人受到元素加成 hp-"<<cs[j[x]]/5<<endl;dh[b[1]]=dh[b[1]]-cs[j[x]]/5;}if(yszb[cd1]==ys2[b[1]]) {cout<<"敵人受到武器元素加成 hp-"<<dh[b[1]]/5<<endl;dh[b[1]]=dh[b[1]]-dh[b[1]]/5;}if(hh[0]>0) {cout<<"敵人被汲取生命 hp-"<<cs[2]/5<<endl;cout<<"你的血量增加了 hp+"<<cs[2]/5<<endl;dh[b[1]]=dh[b[1]]-cs[2]/5;h=h+cs[2]/5;hh[0]--;}if(hh[1]>0) {cout<<"敵人燃燒 hp-"<<(cs[2]+cs[0])/5<<endl;dh[b[1]]=dh[b[1]]-(cs[2]+cs[0])/5;hh[1]--;}if(bf[1]>=1&&bf[2]>=1) {dh[b[1]]=dh[b[1]]-(cs[0]+cs[1])/5;cout<<"形成蒸發 hp-"<<(cs[0]+cs[1])/5<<endl;bf[0]=0;bf[1]=0;}if(bf[4]>=1&&bf[2]>=1) {dh[b[1]]=dh[b[1]]-(cs[3]+cs[1])/5;cout<<"形成觸電 hp-"<<(cs[3]+cs[1])/5<<endl;bf[3]=0;bf[1]=0;}if(bf[4]>=1&&bf[1]>=1) {dh[b[1]]=dh[b[1]]-(cs[3]+cs[0])/5;cout<<"形成爆炸 hp-"<<(cs[3]+cs[0])/5<<endl;bf[0]=0;bf[3]=0;}if(bf[3]>=1&&bf[1]>=1) {dh[b[1]]=dh[b[1]]-(cs[2]+cs[0])/5;cout<<"形成燃燒 hp-"<<(cs[2]+cs[0])/5<<endl;hh[1]=3;bf[0]=0;bf[3]=0;}if(bf[5]>=1&&bf[1]>=1) {dh[b[1]]=dh[b[1]]-(cs[2]+cs[0])/5;cout<<"形成融化 hp-"<<(cs[4]+cs[0])/5<<endl;bf[0]=0;bf[4]=0;}if(bf[5]>=1&&bf[4]>=1) {dh[b[1]]=dh[b[1]]-(cs[2]+cs[0])/5;cout<<"形成超導 hp-"<<(cs[4]+cs[3])/5<<endl;bf[3]=0;bf[4]=0;}}if(a==2){for(i[0]=1;i[0]<=6;i[0]++){if(daojvcc[i[0]]>0){cout<<i[0]<<"."<<daojv[i[0]]<<"數量:"<<daojvcc[i[0]]<<endl;}}cin>>b[3];if(daojvcc[b[3]]>0){if(daojvlb[b[1]]==1){cout<<"血量+"<<daojvsx[b[3]]<<endl;h=h+daojvsx[b[3]];daojvcc[b[3]]--;}if(daojvlb[b[3]]==2){ss=ss+daojvsx[b[3]];cout<<"攻擊+"<<daojvsx[b[3]]<<endl;daojvcc[b[3]]--;}}}if(a==3){cout<<"你逃跑了"<<endl;}if(dh[b[1]]>0) {if(yszb[cd2]==ys2[b[1]]) {cout<<"敵人攻擊了你 hp-"<<dg[b[1]]-dg[b[1]]/5<<endl;cout<<"但是受到裝備元素加成 傷害下降了5分之1"<<endl;h=h-dg[b[1]]+dg[b[1]]/5;} else {h=h-dg[b[1]];cout<<"敵人攻擊了你 hp-"<<dg[b[1]]<<endl;}}}if(dh[b[1]]<=0) {cout<<"你打敗了"<<dr[b[1]]<<" "<<"經驗增加"<<100*b[1]+100+ddj<<" "<<"金幣增加"<<drcf[b[1]]<<endl;jy=jy+100*b[1]+ddj;cf=cf+drcf[b[1]];hh[0]=0;hh[1]=0;ss=ss-daojvsx[b[1]];}}if(b[0]==2) {cout<<"LV:"<<dj<<" 經驗:"<<jy<<" "<<zb[cd1]<<" "<<zb[cd2]<<" "<<"金幣"<<cf<<endl;}if(b[0]==3) {for(i[0]=1; i[0]<=7; i[0]++) {cout<<i[0]<<"."<<c[i[0]];}cout<<" "<<endl;cout<<"輸入技能編號(4個)"<<endl;for(i[0]=1; i[0]<=4; i[0]++) {cin>>j[i[0]];}}if(b[0]==4) {cout<<"金幣"<<cf<<endl;for(i[0]=1; i[0]<=8; i[0]++) {cout<<i[0]<<"."<<zb[i[0]]<<cfzb[i[0]]<<" ";}cout<<"按111去買道具"<<endl;cin>>b[1];if(cf<cfzb[b[1]])cout<<"窮鬼!"<<endl;if(b[1]!=111&&cf>=cfzb[b[1]]) {zbcc[b[1]]++;cf=cf-cfzb[b[1]];}for(i[0]=1; i[0]<=6; i[0]++) {cout<<i[0]<<"."<<daojv[i[0]]<<cfdaojv[i[0]]<<" ";}cout<<"按111離開"<<endl;cin>>b[2];if(b[2]==111)cout<<"窮鬼!"<<endl;if(cf<cfdaojv[b[2]])cout<<"窮鬼!"<<endl;if(b[2]!=111&&cf>=cfdaojv[b[2]]) {daojvcc[b[2]]++;cf=cf-cfdaojv[b[2]];}}if(b[0]==5) {for(i[0]=1; i[0]<=6; i[0]++) {if(zbcc[i[0]]>=1) {cout<<i[0]<<"."<<zb[i[0]]<<"有"<<zbcc[i[0]]<<"個 "<<" ";}}cout<<"按111離開,按1繼續"<<endl;cin>>b[3];if(b[3]==1) {cout<<"武器:(輸入編號)"<<endl;cin>>b[1];if(zbcc[b[1]]>0&&lb[b[1]]==0) {zbcc[b[1]]--;zbcc[cd1]++;ss=ss+zbsx[b[1]];cd1=b[1];} else {cout<<"你還沒有裝備"<<endl;}cout<<"防具:(輸入編號)"<<endl;cin>>b[2];if(zbcc[b[2]]>0&&lb[b[2]]==1) {zbcc[b[2]]--;zbcc[cd2]++;xl=xl+zbsx[b[2]];cd2=b[2];} else {cout<<"你還沒有裝備"<<endl;}}}if(jy>=p) { //等級jy=jy-p;p=p+500;dj++;ss=ss+5;h=h+10;cout<<"你升級了 傷害+5 血量+10"<<endl;}if(dj%10==0&&dj!=s) { //難度s=dj;dh1=dh1+50;dg1=dg1+5;ddj=ddj+200;nd++;drcf1=drcf1+5;cout<<"難度+1"<<endl;}if(h<=0) {cout<<"你死了,結束"<<endl;Sleep(2000);break;}}return 0; } void HindCursor() {HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO CursorInfo;GetConsoleCursorInfo(handle, &CursorInfo);CursorInfo.bVisible = false;SetConsoleCursorInfo(handle, &CursorInfo); } void gotoxy(int x, int y) {COORD pos; pos.X = y; pos.Y = x;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } void color(int a) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a); } struct Button {int x, y, color;const char *name;int len; }; void GetPos(POINT &pt) {HWND hwnd = GetForegroundWindow();GetCursorPos(&pt);ScreenToClient(hwnd, &pt);pt.y = pt.y / 16, pt.x = pt.x / 8;swap(pt.x, pt.y); } Button NewButton(int x, int y, int color, const char *name) {Button t;t.x = x, t.y = y, t.name = name;t.color = color;t.len = strlen(name);return t; } bool Preserve(Button A) {gotoxy(A.x, A.y), color(A.color), printf("%s", A.name);POINT pt;GetPos(pt);if (pt.x == A.x && (pt.y >= A.y&&pt.y <= A.y + A.len)){color(112), gotoxy(A.x, A.y), printf("%s", A.name);if (KEY_DOWN(MOUSE_MOVED)) return 1;}return 0; } struct Sprite {int width, height, x, y, Color, direction;string * body;void Draw(){color(Color);for (int i = 0; i < height; i++){gotoxy(x + i, y);for (int j = 0; j < width; j++) printf("%c", body[i][j]);}}void Clean(){for (int i = 0; i < height; i++){gotoxy(x + i, y);for (int j = 0; j < width; j++) printf(" ");}} }; Sprite NewSprite(string s[], int w, int h, int _color, int nx, int ny) {Sprite newsprite;newsprite.x = nx;newsprite.y = ny;newsprite.body = s;newsprite.width = w;newsprite.height = h;newsprite.Color = _color;newsprite.direction = 1;return newsprite; } bool CheckCollision(Sprite a, Sprite b) {int ax1 = a.x, ax2 = a.x + a.height - 1, ay1 = a.y, ay2 = a.y + a.width - 1;int bx1 = b.x, bx2 = b.x + b.height - 1, by1 = b.y, by2 = b.y + b.width - 1;if ((ax2 >= bx1 && ay2 >= by1 && ax1 <= bx1 && ay1 <= by1) ||(ax2 >= bx1 && ay1 <= by2 && ax1 <= bx1 && ay1 >= by1) ||(bx2 >= ax1 && by2 >= ay1 && bx1 <= ax1 && by1 <= ay1) ||(bx2 >= ax1 && by1 <= ay2 && bx1 <= ax1 && by1 >= ay1))return 1;return 0; } bool CheckIn(Sprite a, Sprite b) {int ax1 = a.x, ax2 = a.x + a.height - 1, ay1 = a.y, ay2 = a.y + a.width - 1;int bx1 = b.x, bx2 = b.x + b.height - 1, by1 = b.y, by2 = b.y + b.width - 1;if (ax1 <= bx1 && ay1 <= by1 && ax2 >= bx2 && ay2 >= by2) return 1;return 0; }老規矩,自行觀看,164贊出教程;
總結
以上是生活随笔為你收集整理的c++ 小游戏 NO 7 打怪游戏(无聊)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 雷达线性调频matlab,线性调频脉冲雷
- 下一篇: 从零开始写C++打怪小游戏(1)