标签:ror amp error scanf long double ++ 防御 code
发现了一点2.0代码中的小问题(把别的装备卖空后当前的装备会突然消失),进行了一些小改动
以下为代码
1 #include<stdlib.h> 2 #include<stdio.h> 3 #include<time.h> //suiji 4 #include<string.h> 5 #include<windows.h> //SLEEP函数 6 struct Player //玩家结构体,并初始化player 7 { 8 char name[21]; 9 int attack; 10 int defense; 11 int health; 12 long int max_health; 13 int level; 14 int exp; 15 int range_exp; 16 long int max_exp; 17 }player={"勇者",50,40,100,100,1,0,0,100}; 18 struct Enemy //怪的结构体,并初始化各种怪 19 { 20 char name[20]; 21 char wupin[12]; 22 int attack; 23 int defense; 24 int health; 25 int money; 26 long int exp; 27 int wupin_sign; 28 int wupinpro; 29 int double_attack; 30 int miss; 31 }strongman={"森林巨人","黄金圣衣",40,50,350,200,100,1,2,1,0}, 32 witch={"森林女巫","银甲",25,15,100,50,50,2,2,1,1}, 33 xiyi={"森林蜥蜴","铁甲",18,10,50,30,35,3,3,2,2}, 34 big_strongman={"森林巨人王","巨人之臂",40*5,50*5,350*5,200*5,100*5,4,4,2,0}, 35 lion={"草原雄狮","绝世好剑",60,30,280,200,100,5,2,1,0}, 36 horse={"草原野马","碧血剑",28,12,90,50,50,6,2,1,1}, 37 bee={"草原黄蜂","长剑",17,11,60,30,35,7,3,2,2}, 38 shitu={"使徒","\0",60*8,30*8,280*8,200*8,100*8,9,1,1,0}, 39 guai={"\0","\0",0,0,0,0,0,0,0,0,0}; 40 struct Place 41 { 42 int bar,hotel,forest1,forest2,forest3,grass1,grass2,grass3,shop; 43 }place={1,2,3,4,5,6,7,8,9}; 44 45 int max_exp=0; 46 int choose_number=0,s=0,strongman_arm=0,battle=0,money=500,place_sign=9; 47 int cao=3,jijiubao=2,baiyao=2,superbaiyao=1,boom=3,dubiao=2,atom_boom=1; 48 int fang=0,fang1=10,fang1n=0,fang2=20,fang2n=0,fang3=40,fang3n=0,fang4=100,fang4n=0; 49 int gong=0,gong1=8,gong1n=0,gong2=15,gong2n=0,gong3=25,gong3n=0,gong4=60,gong4n=0; 50 char gongname[20]="无",fangname[20]="无"; 51 char proof; 52 53 void AddWupin(int); 54 int AttackResult(); 55 void BattleAct(); 56 void ChooseWupin(); 57 void DisplayState(); 58 void OrdinaryAct(); 59 int SuiJi(); 60 int SuiJi100(); 61 void WhetherLevelUp(); 62 void SlowDisplay(char *); 63 64 int main() 65 { 66 67 68 int i=0,j=0,k=0; 69 char player_name[21]; 70 SlowDisplay("这是一个勇者的世界! 雅莉萨斯国的罗茜公主被陌生人绑架了!\n\n 伟大的勇者啊~拿起你们的武器,营救公主!\n\n\n输入你的名字: (20个字符)\n\n\n"); 71 72 // sndPlaySound("res\\F005.wav",SND_LOOP); 73 scanf("%s",player_name); 74 strncpy(player.name,player_name,20); 75 if(strcmp(player.name,"EVA初号机")==0) 76 { 77 SlowDisplay("\n 隐身多年的 EVA初号机 啊! 你终于出来了!雅莉萨斯国正需要你的帮助,快去吧!\n\n\n\n\n\n\n 这时,一道白光射出,射到了 EVA初号机 的身上\n\n\n\n\n\n\n ......\n\n\n\n\n\n\n EVA初号机 吸收能量ing... 随即... 能力觉醒!!!\n\n\n\n\n\n\n"); 78 player.attack=100000; 79 player.defense=100000; 80 player.health=100000; 81 player.max_health=100000; 82 } 83 else 84 { 85 SlowDisplay("\n雅莉萨斯国国王:\n\n\n 勇者,欢迎你来到我的王国!但是,由于我的女儿被抢走了,烦请勇士帮我们一下吧!会有丰厚的报酬哦~~\n\n\n"); 86 printf("%s",player.name); 87 SlowDisplay(" :\n\n\n 您放心好了,我一定帮您把公主救出来!\n\n\n\n 国王大手一挥,你落到了这个世界,开始了拯救公主的征程。\n\n\n\n\n\n\n"); 88 } 89 getchar(); 90 91 OrdinaryAct(); 92 return 0; 93 } 94 95 int SuiJi() 96 { 97 srand((unsigned)time(NULL)); 98 return rand()%10; 99 } 100 101 102 int SuiJi100() 103 { 104 srand((unsigned)time(NULL)); 105 return rand()%100; 106 } 107 108 109 void ChooseWupin() //选择物品 并使用 110 { 111 printf("物品: 1,止血草%d个 2,急救包%d个 3,云南白药%d个 4,超级云南白药%d个 5,手雷%d个 6,毒标%d个 7,手抛式原子弹%d个 0,返回\n\n\n",cao,jijiubao,baiyao,superbaiyao,boom,dubiao,atom_boom); 112 switch(scanf("%d",&choose_number),choose_number) 113 { 114 case 1: 115 if(cao>0) 116 { 117 SlowDisplay("使用止血草,HP增加60\n\n\n"); 118 cao--; 119 if(player.health+60>player.max_health)player.health=player.max_health; 120 else player.health+=60; 121 } 122 else SlowDisplay("没有止血草了\n\n\n"); 123 break; 124 case 2: 125 if(jijiubao>0) 126 { 127 SlowDisplay("使用急救包,HP增加80\n\n\n"); 128 jijiubao--; 129 if(player.health+80>player.max_health)player.health=player.max_health; 130 else player.health+=80; 131 } 132 else SlowDisplay("没有急救包了\n\n\n"); 133 break; 134 case 3: 135 if(baiyao>0) 136 { 137 SlowDisplay("使用云南白药,HP增加120\n\n\n"); 138 baiyao--; 139 if(player.health+120>player.max_health)player.health=player.max_health; 140 else player.health+=120; 141 } 142 else SlowDisplay("没有云南白药了\n\n\n"); 143 break; 144 case 4: 145 if(superbaiyao>0) 146 { 147 SlowDisplay("使用超级云南白药,HP增加200\n\n\n"); 148 superbaiyao--; 149 if(player.health+200>player.max_health)player.health=player.max_health; 150 else player.health+=200; 151 } 152 else SlowDisplay("没有超级云南白药了\n\n\n"); 153 break; 154 case 5: 155 if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品 156 { 157 if(boom>0) 158 { 159 SlowDisplay("使用手雷,敌人HP减少100\n\n\n"); 160 boom--; 161 guai.health-=100; 162 AttackResult(); 163 } 164 } 165 else SlowDisplay("非战斗状态,不能使用手雷!\n\n\n"); 166 break; 167 case 6: 168 if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品 169 { 170 if(dubiao>0) 171 { 172 SlowDisplay("使用毒标,敌人HP减少200\n\n\n"); 173 dubiao--; 174 guai.health-=200; 175 AttackResult(); 176 } 177 } 178 else SlowDisplay("非战斗状态,不能使用毒标!\n\n\n"); 179 break; 180 case 7: 181 if(battle) //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品 182 { 183 if(atom_boom>0) 184 { 185 SlowDisplay("使用手抛式原子弹,敌人HP减少500\n\n\n"); 186 atom_boom--; 187 guai.health-=500; 188 AttackResult(); 189 } 190 } 191 else SlowDisplay("非战斗状态,不能使用手抛式原子弹!\n\n\n"); 192 break; 193 case 0:break; 194 default:printf("ChooseWupin error!\n\n\n"); 195 } 196 } 197 int AttackResult() //攻击结果:判断是否获胜 是否获得物品 和 是否升级 198 { 199 if(guai.health<=0) 200 { 201 battle=0; 202 printf("战斗胜利!获得金币%d,经验%d\n\n\n",guai.money,guai.exp); 203 player.exp+=guai.exp; 204 player.range_exp+=guai.exp; 205 money+=guai.money; 206 s=SuiJi(); 207 if(s<guai.wupinpro) 208 { 209 SlowDisplay("从敌人尸骸中发现"); 210 printf("%s\n\n\n",guai.wupin); 211 AddWupin(guai.wupin_sign); 212 } 213 WhetherLevelUp(); 214 if(strcmp(guai.name,"使徒")==0) 215 { 216 SlowDisplay("神秘老人(神色大变):\n\n\n 什么?你竟然打败了我的使徒?你到底是谁?怎么会这么厉害?\n\n\n"); 217 printf("%s",player.name); 218 SlowDisplay(" : \n\n\n 嘿嘿,反正你也快死了,我就告诉你一条消息吧。我就是传说中的勇者!你想打败我?没门!基于你的“良好”表现,我决定:杀了你,以绝后患!\n\n\n\n\n\n 这时,"); 219 printf("%s",player.name); 220 SlowDisplay("的手里发出一道白光,那白光直直的击中了老人,神秘老人和他手中的巨人之臂双双飞出,不过巨人之臂掉到了 "); 221 printf("%s",player.name); 222 SlowDisplay(" 的脚下,而神秘老人狠狠的撞到了岩石上,一口鲜血喷出......\n\n\n\n\n\n ......\n\n\n\n\n\n "); 223 printf("%s",player.name); 224 SlowDisplay("缓缓的走到神秘老人的面前,说:\n\n\n 现在,用你的生命来偿还吧!\n\n\n\n\n 老人惊恐的瞪着"); 225 printf("%s",player.name); 226 SlowDisplay(",然后化作一道白光,逃走了......\n\n\n\n\n 这时,一个铁笼出现在"); 227 printf("%s",player.name); 228 SlowDisplay("的面前,里面正关着泪流满面的公主。\n\n\n\n公主:\n\n\n 勇士,快来救我!\n\n\n"); 229 printf("%s",player.name); 230 SlowDisplay(" (皱眉头):\n\n\n 我该怎么救你呢?\n\n\n公主:\n\n\n 你把巨人之臂给我就行了。\n\n\n\n\n "); 231 printf("%s",player.name); 232 SlowDisplay("把巨人之臂通过铁笼的缝隙给了公主,公主用巨人之臂把锁的背面捅了两下,锁便开了,公主缓缓的走了出来,跟着你回到了皇宫^_^\n\n\n\n\n"); 233 puts("你完成了救出公主的任务,国王重赏了你!!!"); 234 getchar(); 235 getchar(); 236 exit(0); 237 } 238 return 1; //攻击有结果了返回1,否则返回0,用于判断是否继续做战斗行为 239 } 240 else 241 { 242 int s=SuiJi(); 243 244 245 if((guai.attack+s-player.defense/3)<0) 246 { 247 player.health-=1; 248 printf("%s反击,你的HP减少了 1\n\n",guai.name); 249 } 250 else 251 { 252 player.health-=guai.attack+s-player.defense/3; 253 printf("%s反击,你的HP减少了%d\n\n",guai.name,guai.attack+s-player.defense/3); 254 } 255 if(player.health<0) 256 { 257 if(strcmp(guai.name,"使徒")==0) 258 { 259 SlowDisplay("神秘老人(奸笑着):\n\n\n 嘿嘿,小子,想对付我的使徒你还嫩了点,现在,我要你的鲜血作为代价......哈哈哈哈哈哈...... \n\n\n"); 260 SlowDisplay("老人手一挥,使徒拿着钢刀冲过来......将刀对准了"); 261 printf("%s",player.name); 262 SlowDisplay("的脖子......然后......刀砍了下来......鲜血四溅......\n\n\n"); 263 battle=0; 264 printf("%s战死!金币掉落%d\n\n\n",player.name,player.level*500); 265 money-=player.level*500; 266 player.health=player.max_health/5; 267 SlowDisplay("\n\n\n\n\n\n\n 头好沉啊......怎么回事......我这是在哪里......\n 不对!我不是被使徒杀了吗?怎么复活了?不过把使徒杀了是我的任务!\n\n"); 268 SlowDisplay(" 你得到了国王的庇护,复活了!现在请重新开始任务吧!\n\n"); 269 } 270 else 271 { 272 battle=0; 273 printf("%s战死!金币掉落%d\n\n\n",player.name,player.level*500); 274 money-=player.level*500; 275 player.health=player.max_health/5; 276 } 277 OrdinaryAct();////////// 278 return 1; 279 } 280 } 281 return 0; 282 } 283 void AddWupin(int wupin_sign) 284 { 285 286 switch(wupin_sign) 287 { 288 case 1:fang4n++; break; 289 case 2:fang3n++; break; 290 case 3:fang2n++; break; 291 case 4:strongman_arm=1;break; 292 case 5:gong4n++; break; 293 case 6:gong3n++; break; 294 case 7:gong2n++; break; 295 default:printf("AddWupin error\n\n\n"); 296 } 297 298 } 299 void WhetherLevelUp() 300 { 301 int i=0,j=0; 302 int l1=player.range_exp/100; 303 int l2=player.range_exp/300; 304 int l3=player.range_exp/600; 305 if(player.level<=15&&l1>0) //15级以下,经验足够 都满足则升级 306 { 307 if(l1==1) 308 { 309 printf("%s",player.name); 310 SlowDisplay(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n"); 311 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 312 player.attack+=3; 313 player.defense+=2; 314 player.max_health+=20; 315 player.health=player.max_health; 316 player.level++; 317 player.range_exp=0; 318 player.exp=player.max_exp; 319 player.max_exp+=100; 320 } 321 else 322 { 323 printf("好厉害!连升%d级!",l1); 324 printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n",3*l1,2*l1,20*l1); 325 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 326 player.attack+=3*l1; 327 player.defense+=2*l1; 328 player.max_health+=20*l1; 329 player.health=player.max_health; 330 player.level+=l1; 331 player.range_exp=0; 332 player.exp=player.max_exp; 333 player.max_exp+=100*l1; 334 } 335 } 336 else if(player.level<=40&&l2>0) 337 { 338 if(l2==1) 339 { 340 printf("%s",player.name); 341 SlowDisplay(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n"); 342 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 343 player.attack+=3; 344 player.defense+=2; 345 player.max_health+=20; 346 player.health=player.max_health; 347 player.level++; 348 player.range_exp=0; 349 player.exp=player.max_exp; 350 player.max_exp+=300; 351 } 352 else 353 { 354 printf("好厉害!连升%d级!",l1); 355 printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n",3*l2,2*l2,20*l2); 356 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 357 player.attack+=3*l2; 358 player.defense+=2*l2; 359 player.max_health+=20*l2; 360 player.health=player.max_health; 361 player.level+=l2; 362 player.range_exp=0; 363 player.exp=player.max_exp; 364 player.max_exp+=300*l2; 365 } 366 } 367 else if(l3>0) 368 { 369 if(l3==1) 370 { 371 printf("%s",player.name); 372 SlowDisplay(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n"); 373 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 374 player.attack+=3; 375 player.defense+=2; 376 player.max_health+=20; 377 player.health=player.max_health; 378 player.level++; 379 player.range_exp=0; 380 player.exp=player.max_exp; 381 player.max_exp+=600; 382 } 383 else 384 { 385 printf("好厉害!连升%d级!",l1); 386 printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n",3*l3,2*l3,20*l3); 387 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 388 player.attack+=3*l3; 389 player.defense+=2*l3; 390 player.max_health+=20*l3; 391 player.health=player.max_health; 392 player.level+=l3; 393 player.range_exp=0; 394 player.exp=player.max_exp; 395 player.max_exp+=600*l3; 396 } 397 } 398 } 399 void OrdinaryAct() //正常行为菜单(移动,物品,对话,查看状态,装备,退出游戏) 400 { 401 402 while(1) 403 { 404 // \(1000); 405 // system("cls"); 406 puts("============================================================================="); 407 printf("要做什么?\n\n\n 1,移动 2,道具 3,对话 4,查看状态 5,装备 0,退出游戏\n\n\n"); 408 puts("============================================================================="); 409 switch(scanf("%d",&choose_number),choose_number) 410 { 411 case 1: //显示移动菜单 412 SlowDisplay("要去哪里?\n\n\n"); 413 printf("1,酒吧 2,旅馆 3,森林一层 4,森林二层 5,森林三层 6,草原一层 7,草原二层 8,草原三层\n9,商店\n\n\n"); 414 switch(scanf("%d",&choose_number),choose_number) 415 { 416 case 1:place_sign=place.bar; //记录目前位置-酒吧 417 // OrdinaryAct(); 418 break; 419 case 2:place_sign=place.hotel; //进入旅店 420 SlowDisplay("要住店吗? 200个金币 1,是 0,否\n\n\n"); 421 choose_number=1; 422 switch(scanf("%d",&choose_number),choose_number) 423 { 424 case 1:if(money-200<0) //判断钱是否够 425 { 426 SlowDisplay("Sorry,你的钱不够~\n\n\n"); 427 } 428 else 429 { 430 SlowDisplay("好好休息\n\tHP满\n\t\t第二天了\n\n"); 431 money-=200; //花费200住店费 432 player.health=player.max_health; //体力满 433 } 434 break; 435 case 0:SlowDisplay("下次再来!\n\n\n");break; 436 default:printf("hotel talk error!\n\n\n"); 437 } 438 place_sign=0; 439 break; 440 case 3: 441 place_sign=place.forest1; 442 s=SuiJi(); 443 if(s<7) 444 { 445 battle=1; 446 guai=xiyi; 447 printf("%s扑了过来!\n\n\n",guai.name); 448 BattleAct(); 449 } 450 else if(s<9) 451 { 452 battle=1; 453 guai=witch; 454 printf("%s扑了过来!\n\n\n",guai.name); 455 BattleAct(); 456 } 457 else 458 { 459 SlowDisplay("这里安全\n\n\n"); 460 //不用调用OAct函数,会自动执行OAct函数; 461 } 462 break; 463 case 4: 464 place_sign=place.forest2; 465 s=SuiJi(); 466 if(s<7) 467 { 468 battle=1; 469 guai=witch; 470 printf("%s扑了过来!\n\n\n",guai.name); 471 BattleAct(); 472 } 473 else if(s<9) 474 { 475 battle=1; 476 guai=strongman; 477 printf("%s扑了过来!\n\n\n",guai.name); 478 BattleAct(); 479 } 480 else 481 { 482 SlowDisplay("这里安全\n\n\n"); 483 } 484 break; 485 case 5: 486 place_sign=place.forest3; 487 s=SuiJi(); 488 if(s<7) 489 { 490 battle=1; 491 guai=strongman; 492 printf("%s扑了过来!\n\n\n",guai.name); 493 BattleAct(); 494 } 495 else if(s<9) 496 { 497 battle=1; 498 guai=big_strongman; 499 printf("%s扑了过来!\n\n\n",guai.name); 500 BattleAct(); 501 } 502 else 503 { 504 SlowDisplay("这里安全\n\n\n"); 505 } 506 break; 507 case 6: 508 place_sign=place.grass1; 509 s=SuiJi(); 510 if(s<7) 511 { 512 battle=1; 513 guai=bee; 514 printf("%s扑了过来!\n\n\n",guai.name); 515 BattleAct(); 516 } 517 else if(s<9) 518 { 519 battle=1; 520 guai=horse; 521 printf("%s扑了过来!\n\n\n",guai.name); 522 BattleAct(); 523 } 524 else 525 { 526 SlowDisplay("这里安全\n\n\n"); 527 } 528 break; 529 case 7: 530 place_sign=place.grass2; 531 s=SuiJi(); 532 if(s<7) 533 { 534 battle=1; 535 guai=horse; 536 printf("%s扑了过来!\n\n\n",guai.name); 537 BattleAct(); 538 } 539 else if(s<9) 540 { 541 battle=1; 542 guai=lion; 543 printf("%s扑了过来!\n\n\n",guai.name); 544 BattleAct(); 545 } 546 else 547 { 548 SlowDisplay("这里安全\n\n\n"); 549 } 550 break; 551 case 8: 552 place_sign=place.grass3; 553 s=SuiJi(); 554 if(s<7) 555 { 556 battle=1; 557 guai=lion; 558 printf("%s扑了过来!\n\n\n",guai.name); 559 BattleAct(); 560 } 561 else if(s<9) 562 { 563 battle=1; 564 if(strongman_arm) 565 { 566 SlowDisplay("神秘老人:\n\n\n 哈哈,年轻人,做的不错,不过...嘿嘿,你上当啦!巨人之臂我要了,公主你也别想带走!\n\n\n\n"); 567 printf("%s",player.name); 568 SlowDisplay(" :\n\n\n 你休想!我好不容易才拿到巨人之臂,你别想占我的便宜!\n\n\n神秘老人(脸色阴沉):\n\n\n 既然你这么不识相,那么也别怪我不客气了!使徒,上!\n\n\n\n"); 569 guai=shitu; 570 printf("%s扑了过来!\n\n\n",guai.name); 571 BattleAct(); 572 } 573 else SlowDisplay("神秘老人:\n\n\n 年轻人,你好啊.如果你有巨人之臂,我可以告诉你公主的下落哦~\n\n\n"); 574 } 575 else 576 { 577 SlowDisplay("这里安全\n\n\n"); 578 } 579 break; 580 case 9:place_sign=place.shop; 581 SlowDisplay("您好,请问您需要什么?\n\n 急救:1,止血草 500金币 2,急救包 600金币 3,云南白药 800金币 4,超级云南白药 1000金币\n 攻击:5,手雷 500金币 6,毒标 1000金币 7,手抛式原子弹 2500金币\n 0,我只看看,不买\n\n\n"); 582 //choose_number=1; 583 SlowDisplay("您目前有"); 584 printf("%d",money); 585 SlowDisplay("金币\n\n"); 586 switch(scanf("%d",&choose_number),choose_number) 587 { 588 case 1:if(money-500<0) //判断钱是否够 589 { 590 SlowDisplay(" 抱歉,你的钱好像不太够呢~\n\n去打怪吧\n\n\n"); 591 } 592 else 593 { 594 SlowDisplay("购买成功!\n\n谢谢光临!下次再来!~^_^~\n\n\n"); 595 money-=500; 596 cao++; 597 } 598 break; 599 case 2:if(money-600<0) //判断钱是否够 600 { 601 SlowDisplay(" 抱歉,你的钱好像不太够呢~\n\n去打怪吧\n\n\n"); 602 } 603 else 604 { 605 SlowDisplay("购买成功!\n\n谢谢光临!下次再来!~^_^~\n\n\n"); 606 money-=600; 607 jijiubao++; 608 } 609 break; 610 case 3:if(money-800<0) //判断钱是否够 611 { 612 SlowDisplay(" 抱歉,你的钱好像不太够呢~\n\n去打怪吧\n\n\n"); 613 } 614 else 615 { 616 SlowDisplay("购买成功!\n\n谢谢光临!下次再来!~^_^~\n\n\n"); 617 money-=800; 618 baiyao++; 619 } 620 break; 621 case 4:if(money-1000<0) //判断钱是否够 622 { 623 SlowDisplay(" 抱歉,你的钱好像不太够呢~\n\n去打怪吧\n\n\n"); 624 } 625 else 626 { 627 SlowDisplay("购买成功!\n\n谢谢光临!下次再来!~^_^~\n\n\n"); 628 money-=1000; 629 superbaiyao++; 630 } 631 break; 632 case 5:if(money-500<0) //判断钱是否够 633 { 634 SlowDisplay(" 抱歉,你的钱好像不太够呢~\n\n去打怪吧\n\n\n"); 635 } 636 else 637 { 638 SlowDisplay("购买成功!\n\n谢谢光临!下次再来!~^_^~\n\n\n"); 639 money-=500; 640 boom++; 641 } 642 break; 643 case 6:if(money-1000<0) //判断钱是否够 644 { 645 SlowDisplay(" 抱歉,你的钱好像不太够呢~\n\n去打怪吧\n\n\n"); 646 } 647 else 648 { 649 SlowDisplay("购买成功!\n\n谢谢光临!下次再来!~^_^~\n\n\n"); 650 money-=1000; 651 dubiao++; 652 } 653 break; 654 case 7:if(money-2500<0) //判断钱是否够 655 { 656 SlowDisplay(" 抱歉,你的钱好像不太够呢~\n\n去打怪吧\n\n\n"); 657 } 658 else 659 { 660 SlowDisplay("购买成功!\n\n谢谢光临!下次再来!~^_^~\n\n\n"); 661 money-=2500; 662 atom_boom++; 663 } 664 break; 665 case 0:SlowDisplay("谢谢光临!下次再来!~^_^~\n\n\n");break; 666 default:printf("好像没有这个货物呢\n\n\n"); 667 } 668 break; 669 default:printf("choose map error!\n\n\n"); 670 } 671 break; 672 case 2: ChooseWupin();break; //显示道具,并可以使用. 673 case 3: //对话选项 674 if(place_sign==place.bar) 675 { 676 SlowDisplay("要和谁说话?\n\n\n1,红发女郎 2,赏金猎人 3,酒吧老板\n\n\n"); //显示对话人物 677 switch(scanf("%d",&choose_number),choose_number) 678 { 679 case 1: 680 SlowDisplay("红发女郎:\n\n\n 吧台边那个Hunter好帅啊!(~脸红~)\n\n\n听说他经常外出打猎,外面的路他应该很熟悉的!\n\n\n"); 681 break; 682 case 2: 683 if(fang1n<1&&gong1n<1) 684 { 685 SlowDisplay("赏金猎人:\n\n\n 你要救公主啊!好胆量!\n\n\n 不过外面的丛林和草原很险恶,而且越深越危险,这是匕首和布衣,对你会有些帮助的,拿去吧!\n\n\n"); 686 printf("%s心想:(哇,这位大叔人真好啊!\n\n\n)",player.name); 687 gong1n++; 688 fang1n++; 689 } 690 else SlowDisplay("赏金猎人:\n\n\n 加油吧,年轻人!\n\n\n 不要被外面丛林和草原所吓倒!\n\n\n"); 691 break; 692 case 3: 693 printf("要喝点什么?\n\n\n 1,二锅头25金币 HP+20 2,XO酒80金币 HP+50 3,人头马面150金币 HP+100 0,返回\n\n\n"); 694 choose_number=1; 695 while(choose_number) 696 { 697 switch(scanf("%d",&choose_number),choose_number) 698 { 699 case 1:if(money<25) 700 { 701 SlowDisplay("钱不够!"); 702 } 703 else 704 { 705 if(player.health+20<=player.max_health) 706 { 707 SlowDisplay("HP+20."); 708 money-=25; 709 player.health+=20; 710 } 711 else 712 { 713 SlowDisplay("HP满了"); 714 player.health=player.max_health; 715 } 716 } 717 break; 718 case 2:if(money<80) 719 { 720 SlowDisplay("钱不够!"); 721 } 722 else 723 { 724 if(player.health+50<=player.max_health) 725 { 726 SlowDisplay("HP+50."); 727 money-=80; 728 player.health+=50; 729 } 730 else 731 { 732 SlowDisplay("HP满了"); 733 player.health=player.max_health; 734 } 735 } 736 break; 737 case 3:if(money<150) 738 { 739 SlowDisplay("钱不够!"); 740 } 741 else 742 { 743 if(player.health+100<=player.max_health) 744 { 745 SlowDisplay("HP+100."); 746 money-=150; 747 player.health+=100; 748 } 749 else 750 { 751 SlowDisplay("HP满了"); 752 player.health=player.max_health; 753 } 754 } 755 break; 756 case 0:SlowDisplay("下次再来!\n");break; 757 default:SlowDisplay("输入错误\n\n\n"); 758 } 759 } 760 } 761 } 762 else if(place_sign==place.hotel) 763 SlowDisplay("“老板娘!我...”\n\n\n“我忙着呢,没空理你~”\n\n\n"); 764 else SlowDisplay("这里好像没人可以聊天\n\n\n"); 765 break; 766 case 4: DisplayState(); break; //显示状态 767 case 5: //装备 768 printf("攻装: 1,匕首:%d个 2,长剑:%d个 3,碧血剑:%d个 4,绝世好剑:%d个\n\n\n",gong1n,gong2n,gong3n,gong4n); 769 printf("防装: 5,布衣:%d个 6,铁甲:%d个 7,银甲:%d个 8,黄金圣衣:%d个 9,售卖装备\n\n\n\t0,返回\n\n\n",fang1n,fang2n,fang3n,fang4n); 770 SlowDisplay("选择要装备的武器或防具:\n\n\n"); 771 switch(scanf("%d",&choose_number),choose_number) 772 { 773 case 1:if(gong1n>=1) 774 { 775 SlowDisplay("拿起了匕首\n\n\n"); 776 gong=gong1; 777 strcpy(gongname,"匕首"); 778 } 779 else SlowDisplay("你没有匕首可以装备\n\n\n"); 780 break; 781 case 2:if(gong2n>=1) 782 { 783 SlowDisplay("拿起了长剑\n\n\n"); 784 gong=gong2; 785 strcpy(gongname,"长剑"); 786 } 787 else SlowDisplay("你没有长剑可以装备\n\n\n"); 788 break; 789 case 3:if(gong3n>=1) 790 { 791 SlowDisplay("拿起了碧血剑\n\n\n"); 792 gong=gong3; 793 strcpy(gongname,"碧血剑"); 794 } 795 else SlowDisplay("你没有碧血剑可以装备\n\n\n"); 796 break; 797 case 4:if(gong4n>=1) 798 { 799 SlowDisplay("拿起了绝世好剑\n\n\n"); 800 gong=gong4; 801 strcpy(gongname,"绝世好剑"); 802 } 803 else SlowDisplay("你没有绝世好剑可以装备\n\n\n"); 804 break; 805 case 5:if(fang1n>=1) 806 { 807 SlowDisplay("穿上了布衣\n\n\n"); 808 fang=fang1; 809 strcpy(fangname,"布衣"); 810 } 811 else SlowDisplay("你没有布衣可以装备\n\n\n"); 812 break; 813 case 6:if(fang2>=1) 814 { 815 SlowDisplay("穿上了铁甲\n\n\n"); 816 fang=fang2; 817 strcpy(fangname,"铁甲"); 818 } 819 else SlowDisplay("你没有铁甲可以装备\n\n\n"); 820 break; 821 case 7:if(fang3n>=1) 822 { 823 SlowDisplay("穿上了银甲\n\n\n"); 824 fang=fang3; 825 strcpy(fangname,"银甲"); 826 } 827 else SlowDisplay("你没有银甲可以装备\n\n\n"); 828 break; 829 case 8:if(fang4n>=1) 830 { 831 SlowDisplay("穿上了黄金圣衣\n\n\n"); 832 fang=fang4; 833 strcpy(fangname,"黄金圣衣"); 834 } 835 else SlowDisplay("你没有黄金圣衣可以装备\n\n\n"); 836 break; 837 case 9:SlowDisplay("请输入您要出售的装备编号\n\n\n"); 838 switch(scanf("%d",&choose_number),choose_number) 839 { 840 case 1:if(gong1n>=1) 841 { 842 SlowDisplay("出售了匕首,获得500金币\n\n\n"); 843 money+=500; 844 gong1n--; 845 if(gong1n<1&&gong==8) 846 { 847 gong=0; 848 strcpy(gongname,"无"); 849 } 850 } 851 else SlowDisplay("你还没有匕首\n\n\n"); 852 break; 853 case 2:if(gong2n>=1) 854 { 855 SlowDisplay("出售了长剑,获得1000金币\n\n\n"); 856 money+=1000; 857 gong2n--; 858 if(gong2n<1&&gong==15) 859 { 860 gong=0; 861 strcpy(gongname,"无"); 862 } 863 } 864 else SlowDisplay("你还没有长剑\n\n\n"); 865 break; 866 case 3:if(gong3n>=1) 867 { 868 SlowDisplay("出售了碧血剑,获得2500金币\n\n\n"); 869 money+=2500; 870 gong3n--; 871 if(gong3n<1&&gong==25) 872 { 873 gong=0; 874 strcpy(gongname,"无"); 875 } 876 } 877 else SlowDisplay("你还没有碧血剑\n\n\n"); 878 break; 879 case 4:if(gong4n>=1) 880 { 881 SlowDisplay("出售了绝世好剑,获得5000金币\n\n\n"); 882 money+=5000; 883 gong4n--; 884 if(gong4n<1&&gong==60) 885 { 886 gong=0; 887 strcpy(gongname,"无"); 888 } 889 } 890 else SlowDisplay("你还没有绝世好剑\n\n\n"); 891 break; 892 case 5:if(fang1n>=1) 893 { 894 SlowDisplay("出售了布衣,获得500金币\n\n\n"); 895 money+=500; 896 fang1n--; 897 if(fang1n<1&&fang==10) 898 { 899 fang=0; 900 strcpy(fangname,"无"); 901 } 902 } 903 else SlowDisplay("你还没有布衣\n\n\n"); 904 break; 905 case 6:if(fang2>=1) 906 { 907 SlowDisplay("出售了铁甲,获得1000金币\n\n\n"); 908 money+=1000; 909 fang2n--; 910 if(fang2n<1&&fang==20) 911 { 912 fang=0; 913 strcpy(fangname,"无"); 914 } 915 } 916 else SlowDisplay("你还没有铁甲\n\n\n"); 917 break; 918 case 7:if(fang3n>=1) 919 { 920 SlowDisplay("出售了银甲,获得2500金币\n\n\n"); 921 money+=2500; 922 fang3n--; 923 if(fang3n<1&&fang==40) 924 { 925 fang=0; 926 strcpy(fangname,"无"); 927 } 928 } 929 else SlowDisplay("你还没有银甲\n\n\n"); 930 break; 931 case 8:if(fang4n>=1) 932 { 933 SlowDisplay("出售了黄金圣衣,获得5000金币\n\n\n"); 934 money+=5000; 935 fang4n--; 936 if(fang4n<1&&fang==100) 937 { 938 fang=0; 939 strcpy(fangname,"无"); 940 } 941 } 942 else SlowDisplay("你还没有黄金圣衣\n\n\n"); 943 break; 944 default:printf("sell error!\n\n"); 945 } 946 break; 947 case 0:SlowDisplay("未更换装备\n\n\n");break; 948 default:printf("change error!"); 949 } 950 break; 951 case 0: 952 SlowDisplay("确定退出游戏?(Y/N)\n\n\n"); 953 getchar(); 954 proof=getchar(); 955 if(proof==‘y‘||proof==‘Y‘) 956 { 957 SlowDisplay("数据存储中..."); 958 //向文件中更新数据; 959 getchar(); 960 SlowDisplay("按回车退出"); 961 getchar(); 962 return; 963 } 964 else if(proof==‘n‘||proof==‘N‘)printf("继续游戏!\n\n\n"); 965 else SlowDisplay("继续!\n\n\n"); 966 break; 967 default:SlowDisplay("输入错误!\n\n\n"); 968 } 969 } 970 } 971 void DisplayState() 972 { 973 printf("%s 攻击力:%d+%d=%d 防御力:%d+%d=%d HP:%d/%d \n\n\n",player.name,player.attack,gong,player.attack+gong,player.defense,fang,player.defense+fang,player.health,player.max_health); 974 printf("武器: %s 防具: %s \n\n\n",gongname,fangname); 975 printf("等级:%d 经验:%d/%d 还需要%d经验升级 金币:%d \n\n\n",player.level,player.exp,player.max_exp,player.max_exp-player.exp,money); 976 } 977 void BattleAct() 978 { 979 while(1) 980 { 981 puts("============================================================================="); 982 printf("要怎么办?\n\n\n 1,攻击 2,物品 3,查看状态 4,逃跑\n\n\n"); 983 switch(scanf("%d",&choose_number),choose_number) 984 { 985 case 1: 986 s=SuiJi(); 987 printf("%s攻击! %sHP减少%d\n\n\n",player.name,guai.name,player.attack+s+gong-guai.defense/3); 988 guai.health-=player.attack+s+gong-guai.defense/3; 989 if(AttackResult())return; //如果攻击有结果(敌人或玩家战死)退出函数 990 else continue; 991 case 2: ChooseWupin();break; //选择物品,可以使用,战斗中允许使用攻击性物品 992 case 3:DisplayState();break; //显示状态 993 case 4: 994 s=SuiJi(); 995 if(s<4) //40%的概率可以逃跑 996 { 997 printf("%s逃跑了~\n\n\n",player.name); 998 if(strcmp(guai.name,"使徒")==0) 999 SlowDisplay("神秘老人:\n\n\n 哈哈,年轻人,还是觉得自己很弱吧,多历练历练再来救公主吧!哈哈哈哈哈哈哈.....\n\n\n\n"); 1000 battle=0; 1001 return; 1002 } 1003 else printf("%s逃跑失败!\n\n\n",player.name); 1004 break; 1005 default:SlowDisplay("输入错误,重新输入!\n\n\n"); 1006 } 1007 } 1008 } 1009 void SlowDisplay(char *p) 1010 { 1011 while(1) 1012 { 1013 if(*p!=0) 1014 printf("%c",*p++); 1015 else 1016 break; 1017 Sleep(60); 1018 } 1019 } 1020 1021 1022 //提示:四个手抛式原子弹可以炸死一个巨人王,五个可以炸死一个使徒!
标签:ror amp error scanf long double ++ 防御 code
原文地址:http://www.cnblogs.com/Semora-2004/p/7811398.html