一个简单的打怪小游戏(改)

修改自https://exile-crime.blog.luogu.org/game-1

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 int num,w[7]={0,100,600,200,1250,300,2000},v[2]={70,10};
  4 long level;
  5 long long HP,attack,defence,nowHP,money,speed;
  6 long long monsHP,monsattack,monsdefence,monsdoub,monspeed;
  7 short job,choicevil,choicemed,choicesmith,choicewar,chance,kinds;
  8 bool gift;
  9 char name[6];
 10 char space;
 11 
 12 void welcomevillage() {
 13     cout<<"你好勇士,欢迎来到小镇。你可以在这里购买补给品,购买装备。"<<endl;
 14     cout<<"输入“1”进入药品商店"<<endl;
 15     cout<<"输入“2”进入铁匠铺"<<endl;
 16     cout<<"输入“3”进入战场"<<endl;
 17     cout<<"输入“4”查看当前信息"<<endl;
 18     cout<<"输入“5”重新开始"<<endl;
 19     cout<<"输入“6”退出游戏"<<endl;
 20 }
 21 
 22 void medshop() {
 23     cout<<"你好勇士,欢迎来到药品商店。你可以在这里购买药品。"<<endl;
 24     cout<<"输入“1”购买小型生命药品,增加10点生命上限,50金币"<<endl;
 25     cout<<"输入“2”购买大型生命药品,增加70点生命上限,300金币"<<endl;
 26     cout<<"输入“3”退出药品商店"<<endl;
 27 }
 28 
 29 void smithshop() {
 30     cout<<"你好勇士,欢迎来到铁匠铺。你可以在这里购买武器或防具。"<<endl;
 31     cout<<"输入“1”购买铁剑,增加10点攻击,100金币"<<endl;
 32     cout<<"输入“2”购买精钢大剑,增加70点攻击,600金币"<<endl;
 33     cout<<"输入“3”购买铁甲,增加10点防御,200金币"<<endl;
 34     cout<<"输入“4”购买精钢锁甲,增加70点防御,1250金币"<<endl;
 35     cout<<"输入“5”购买皮靴,增加10点速度,300金币"<<endl;
 36     cout<<"输入“6”购买铁靴,增加70点速度,2000金币"<<endl;
 37     cout<<"输入“7”退出铁匠铺"<<endl;
 38 }
 39 
 40 void wararea() {
 41     cout<<""<<level<<"关,";
 42     gift=false;
 43     srand((unsigned)time(NULL));
 44     for(int i=1; i<=rand(); i++) srand(rand());
 45     chance=rand()*rand()%10000;
 46     if(level%50==0) {
 47         monsHP=100*(1.0+0.25*level);
 48         monsattack=50*(1.0+0.25*level);
 49         monsdefence=35*(1.0+0.25*level);
 50         monspeed=12*(1.0+0.25*level);
 51         monsdoub=50;
 52         cout<<"地狱级的大家伙要到了!"<<endl;
 53     } else if(level%10==0) {
 54         monsHP=100*(1.0+0.1*level);
 55         monsattack=40*(1.0+0.1*level);
 56         monsdefence=25*(1.0+0.1*level);
 57         monspeed=12*(1.0+0.1*level);
 58         monsdoub=10;
 59         cout<<"接下来是场硬仗!"<<endl;
 60     } else {
 61         monsHP=100.0*(1.0+0.03*level);
 62         monsattack=30.0*(1.0+0.03*level);
 63         monsdefence=20.0*(1.0+0.03*level);
 64         monspeed=12*(1.0+0.03*level);
 65         monsdoub=1;
 66         cout<<"加油!"<<endl;
 67     }
 68     if(chance>9996+rand()%4) {
 69         gift=true;
 70         kinds=rand()%4;
 71     }
 72     cout<<"要开始战斗吗?(输入“1”表示开始,“2”表示返回村庄)"<<endl;
 73 }
 74 
 75 void information() {
 76     cout<<"HP: "<<HP<<endl;
 77     cout<<"攻击: "<<attack<<endl;
 78     cout<<"防御: "<<defence<<endl;
 79     cout<<"金钱: "<<money<<endl;
 80     cout<<"速度: "<<speed<<endl;
 81     system("pause");
 82     cout<<endl;
 83     cout<<endl;
 84 }
 85 
 86 void unenoughmoney() {
 87     cout<<"很抱歉,您的金钱不足!"<<endl;
 88     system("pause");
 89 }
 90 
 91 int main() {
 92 restart:
 93     system("cls");
 94     level=1;
 95     money=150;
 96 choosejob:
 97     cout<<"请选择职业(输入“1”代表剑士,输入“2”代表弓箭手,输入“3”代表盾战士):";
 98     cin>>job;
 99     if(job==1) {
100         HP=100;
101         attack=61;
102         defence=52;
103         speed=40;
104         goto village;
105     } else if(job==2) {
106         HP=80;
107         attack=70;
108         defence=51;
109         speed=52;
110         goto village;
111     } else if(job==3) {
112         HP=120;
113         attack=47;
114         defence=83;
115         speed=32;
116         goto village;
117     } else {
118         cout<<"错误选择,";
119         goto choosejob;
120     }
121 village:
122     system("cls");
123     welcomevillage();
124     cin>>choicevil;
125     if(choicevil==1) {
126         system("cls");
127 medshop:
128         medshop();
129         cin>>choicemed;
130         if(choicemed==1) {
131             if(money>=50) {
132                 money-=50;
133                 HP+=10;
134             } else {
135                 unenoughmoney();
136             }
137         } else if(choicemed==2) {
138             if(money>=300) {
139                 money-=300;
140                 HP+=70;
141             } else {
142                 unenoughmoney();
143             }
144         } else if(choicemed==3) {
145             goto village;
146         } else {
147             system("cls");
148             cout<<"错误选择,";
149             goto medshop;
150         }
151     } else if(choicevil==2) {
152         system("cls");
153         smithshop:
154             smithshop();
155             cin>>choicesmith;
156             if(choicesmith>0&&choicesmith<7) {
157                 cout<<"请选择购买件数: ";
158                 cin>>num;
159                 if(money>=w[choicesmith]*num) {
160                     money-=w[choicesmith]*num;
161                     if(choicesmith<3)
162                         attack+=v[choicesmith%2]*num;
163                     else if(choicesmith>4)
164                         speed+=v[choicesmith%2]*num;
165                     else
166                         defence+=v[choicesmith%2]*num;
167                 } else {
168                     unenoughmoney();
169                 }
170             } else if(choicesmith==7) {
171                 goto village;
172             } else {
173                 system("cls");
174                 cout<<"错误选择,";
175                 goto smithshop;
176             }
177     } else if(choicevil==3) {
178         system("cls");
179 wararea:
180         wararea();
181         cin>>choicewar;
182         if(choicewar==1) {
183             nowHP=HP;
184             while(1) {
185                 if(attack-monsdefence<=0&&monsattack-defence<=0) {
186                     cout<<"你无法攻击怪物!它也无法攻击你!战斗结束!"<<endl;
187                     break;
188                 } else {
189                     if(speed>monspeed) {
190                         if(attack>monsdefence) {
191                             monsHP-=attack-monsdefence;
192                             cout<<"你攻击了怪物!你对它造成"<<attack-monsdefence<<"点伤害!它现在还有"<<monsHP<<"点生命!"<<endl;
193                         } else {
194                             cout<<"你无法攻击怪物!它的防御太厉害了!它现在还有"<<monsHP<<"点生命!"<<endl;
195                         }
196                         if(monsHP<=0) {
197                             cout<<"你赢了!获得"<<level*10*monsdoub<<"枚金币!";
198                             money+=level*10*monsdoub;
199                             level++;
200                             if(gift) {
201                                 cout<<"你获得了怪物携带的异宝!";
202                                 if(kinds==0) {
203                                     cout<<"你获得了绝世宝剑!攻击增加100!"<<endl;
204                                     attack+=100;
205                                 } else if(kinds==1) {
206                                     cout<<"你获得了绝世宝甲!防御增加100!"<<endl;
207                                     defence+=100;
208                                 } else if(kinds==2) {
209                                     cout<<"你获得了绝世圣丹!生命增加100!"<<endl;
210                                     HP+=100;
211                                 } else {
212                                     cout<<"你获得了绝世宝靴!速度增加100!"<<endl;
213                                     speed+=100;
214                                 }
215                             } else {
216                                 cout<<endl;
217                             }
218                             break;
219                         }
220                         if(monsattack>defence) {
221                             nowHP-=monsattack-defence;
222                             cout<<"怪物攻击了你!它对你造成"<<monsattack-defence<<"点伤害!你现在还有"<<nowHP<<"点生命!"<<endl;
223                         } else {
224                             cout<<"怪物无法攻击你!你的防御太厉害了!你现在还有"<<nowHP<<"点生命!"<<endl;
225                         }
226                         if(nowHP<=0) {
227                             cout<<"你输了!下次再挑战吧!"<<endl;
228                             break;
229                         }
230                     } else {
231 
232                         if(monsattack>defence) {
233                             nowHP-=monsattack-defence;
234                             cout<<"怪物攻击了你!它对你造成"<<monsattack-defence<<"点伤害!你现在还有"<<nowHP<<"点生命!"<<endl;
235                         } else {
236                             cout<<"怪物无法攻击你!你的防御太厉害了!你现在还有"<<nowHP<<"点生命!"<<endl;
237                         }
238                         if(nowHP<=0) {
239                             cout<<"你输了!下次再挑战吧!"<<endl;
240                             break;
241                         }
242                         if(attack>monsdefence) {
243                             monsHP-=attack-monsdefence;
244                             cout<<"你攻击了怪物!你对它造成"<<attack-monsdefence<<"点伤害!它现在还有"<<monsHP<<"点生命!"<<endl;
245                         } else {
246                             cout<<"你无法攻击怪物!它的防御太厉害了!它现在还有"<<monsHP<<"点生命!"<<endl;
247                         }
248                         if(monsHP<=0) {
249                             cout<<"你赢了!获得"<<level*10*monsdoub<<"枚金币!";
250                             money+=level*10*monsdoub;
251                             level++;
252                             if(gift) {
253                                 cout<<"你获得了怪物携带的异宝!";
254                                 if(kinds==0) {
255                                     cout<<"你获得了绝世宝剑!攻击增加100!"<<endl;
256                                     attack+=100;
257                                 } else if(kinds==1) {
258                                     cout<<"你获得了绝世宝甲!防御增加100!"<<endl;
259                                     defence+=100;
260                                 } else if(kinds==2) {
261                                     cout<<"你获得了绝世圣丹!生命增加100!"<<endl;
262                                     HP+=100;
263                                 } else {
264                                     cout<<"你获得了绝世宝靴!速度增加100!"<<endl;
265                                     speed+=100;
266                                 }
267                             } else {
268                                 cout<<endl;
269                             }
270                             break;
271                         }
272                     }
273                 }
274             }
275             system("pause");
276         } else if(choicewar==2) {
277             goto village;
278         } else {
279             system("cls");
280             cout<<"错误选择,";
281             goto wararea;
282         }
283     } else if(choicevil==4) {
284         system("cls");
285         information();
286     } else if(choicevil==5) {
287         goto restart;
288     } else if(choicevil==6) {
289         return 0;
290     } else {
291         system("cls");
292         cout<<"错误选择,";
293     }
294     goto village;
295     return 0;
296 }

猜你喜欢

转载自www.cnblogs.com/zcxqiangwudi/p/9366460.html