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 71 SlowDisplay("這是一個勇者的世界! 雅莉薩斯國的羅茜公主被陌生人綁架了!\n\n 偉大的勇者啊~拿起大家的武器,營救公主!\n\n\n輸入你的名字: (20個字符)\n\n\n"); 72 73 // sndPlaySound("res\\F005.wav",SND_LOOP); 74 scanf("%s",player_name); 75 strncpy(player.name,player_name,20); 76 if(strcmp(player.name,"EVA初號機")==0) 77 { 78 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"); 79 player.attack=100000; 80 player.defense=100000; 81 player.health=100000; 82 player.max_health=100000; 83 } 84 else 85 { 86 SlowDisplay("\n雅莉薩斯國國王:\n\n\n 勇者,歡迎你來到個人王國!可是,因爲個人女兒被搶走了,煩請勇士幫咱們一下吧!會有豐厚的報酬哦~~\n\n\n"); 87 printf("%s",player.name); 88 SlowDisplay(" :\n\n\n 您放心好了,我必定幫您把公主救出來!\n\n\n\n 國王大手一揮,你落到了這個世界,開始了拯救公主的征程。\n\n\n\n\n\n\n"); 89 } 90 getchar(); 91 92 OrdinaryAct(); 93 return 0; 94 } 95 96 int SuiJi() 97 { 98 srand((unsigned)time(NULL)); 99 return rand()%10; 100 } 101 102 103 int SuiJi100() 104 { 105 srand((unsigned)time(NULL)); 106 return rand()%100; 107 } 108 109 110 void ChooseWupin() //選擇物品 並使用 111 { 112 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); 113 switch(scanf("%d",&choose_number),choose_number) 114 { 115 case 1: 116 if(cao>0) 117 { 118 SlowDisplay("使用止血草,HP增長60\n\n\n"); 119 cao--; 120 if(player.health+60>player.max_health)player.health=player.max_health; 121 else player.health+=60; 122 } 123 else SlowDisplay("沒有止血草了\n\n\n"); 124 break; 125 case 2: 126 if(jijiubao>0) 127 { 128 SlowDisplay("使用急救包,HP增長80\n\n\n"); 129 jijiubao--; 130 if(player.health+80>player.max_health)player.health=player.max_health; 131 else player.health+=80; 132 } 133 else SlowDisplay("沒有急救包了\n\n\n"); 134 break; 135 case 3: 136 if(baiyao>0) 137 { 138 SlowDisplay("使用雲南白藥,HP增長120\n\n\n"); 139 baiyao--; 140 if(player.health+120>player.max_health)player.health=player.max_health; 141 else player.health+=120; 142 } 143 else SlowDisplay("沒有云南白藥了\n\n\n"); 144 break; 145 case 4: 146 if(superbaiyao>0) 147 { 148 SlowDisplay("使用超級雲南白藥,HP增長200\n\n\n"); 149 superbaiyao--; 150 if(player.health+200>player.max_health)player.health=player.max_health; 151 else player.health+=200; 152 } 153 else SlowDisplay("沒有超級雲南白藥了\n\n\n"); 154 break; 155 case 5: 156 if(battle) //在戰鬥中(battle=1),不然(battle=0)不能使用攻擊性物品 157 { 158 if(boom>0) 159 { 160 SlowDisplay("使用手雷,敵人HP減小100\n\n\n"); 161 boom--; 162 guai.health-=100; 163 AttackResult(); 164 } 165 } 166 else SlowDisplay("非戰鬥狀態,不能使用手雷!\n\n\n"); 167 break; 168 case 6: 169 if(battle) //在戰鬥中(battle=1),不然(battle=0)不能使用攻擊性物品 170 { 171 if(dubiao>0) 172 { 173 SlowDisplay("使用毒標,敵人HP減小200\n\n\n"); 174 dubiao--; 175 guai.health-=200; 176 AttackResult(); 177 } 178 } 179 else SlowDisplay("非戰鬥狀態,不能使用毒標!\n\n\n"); 180 break; 181 case 7: 182 if(battle) //在戰鬥中(battle=1),不然(battle=0)不能使用攻擊性物品 183 { 184 if(atom_boom>0) 185 { 186 SlowDisplay("使用手拋式原子彈,敵人HP減小500\n\n\n"); 187 atom_boom--; 188 guai.health-=500; 189 AttackResult(); 190 } 191 } 192 else SlowDisplay("非戰鬥狀態,不能使用手拋式原子彈!\n\n\n"); 193 break; 194 case 0:break; 195 default:printf("ChooseWupin error!\n\n\n"); 196 } 197 } 198 int AttackResult() //攻擊結果:判斷是否獲勝 是否得到物品 和 是否升級 199 { 200 if(guai.health<=0) 201 { 202 battle=0; 203 printf("戰鬥勝利!得到金幣%d,經驗%d\n\n\n",guai.money,guai.exp); 204 player.exp+=guai.exp; 205 player.range_exp+=guai.exp; 206 money+=guai.money; 207 s=SuiJi(); 208 if(s<guai.wupinpro) 209 { 210 SlowDisplay("從敵人屍骸中發現"); 211 printf("%s\n\n\n",guai.wupin); 212 AddWupin(guai.wupin_sign); 213 } 214 WhetherLevelUp(); 215 if(strcmp(guai.name,"使徒")==0) 216 { 217 SlowDisplay("神祕老人(神色大變):\n\n\n 什麼?你居然戰勝了個人使徒?你究竟是誰?怎麼會這麼厲害?\n\n\n"); 218 printf("%s",player.name); 219 SlowDisplay(" : \n\n\n 嘿嘿,反正你也快死了,我就告訴你一條消息吧。我就是傳說中的勇者!你想戰勝我?沒門!基於你的「良好」表現,我決定:殺了你,以絕後患!\n\n\n\n\n\n 這時,"); 220 printf("%s",player.name); 221 SlowDisplay("的手裏發出一道白光,那白光直直的擊中了老人,神祕老人和他手中的巨人之臂雙雙飛出,不過巨人之臂掉到了 "); 222 printf("%s",player.name); 223 SlowDisplay(" 的腳下,而神祕老人狠狠的撞到了岩石上,一口鮮血噴出......\n\n\n\n\n\n ......\n\n\n\n\n\n "); 224 printf("%s",player.name); 225 SlowDisplay("緩緩的走到神祕老人的面前,說:\n\n\n 如今,用你的生命來償還吧!\n\n\n\n\n 老人驚恐的瞪着"); 226 printf("%s",player.name); 227 SlowDisplay(",而後化做一道白光,逃走了......\n\n\n\n\n 這時,一個鐵籠出如今"); 228 printf("%s",player.name); 229 SlowDisplay("的面前,裏面正關着淚流滿面的公主。\n\n\n\n公主:\n\n\n 勇士,快來救我!\n\n\n"); 230 printf("%s",player.name); 231 SlowDisplay(" (皺眉頭):\n\n\n 我該怎麼救你呢?\n\n\n公主:\n\n\n 你把巨人之臂給我就好了。\n\n\n\n\n "); 232 printf("%s",player.name); 233 SlowDisplay("把巨人之臂經過鐵籠的縫隙給了公主,公主用巨人之臂把鎖的背面捅了兩下,鎖便開了,公主緩緩的走了出來,跟着你回到了皇宮^_^\n\n\n\n\n"); 234 puts("你完成了救出公主的任務,國王重賞了你!!!"); 235 getchar(); 236 getchar(); 237 exit(0); 238 } 239 return 1; //攻擊有結果了返回1,不然返回0,用於判斷是否繼續作戰鬥行爲 240 } 241 else 242 { 243 int s=SuiJi(); 244 245 246 if((guai.attack+s-player.defense/3)<0) 247 { 248 player.health-=1; 249 printf("%s反擊,你的HP減小了 1\n\n",guai.name); 250 } 251 else 252 { 253 player.health-=guai.attack+s-player.defense/3; 254 printf("%s反擊,你的HP減小了%d\n\n",guai.name,guai.attack+s-player.defense/3); 255 } 256 if(player.health<0) 257 { 258 if(strcmp(guai.name,"使徒")==0) 259 { 260 SlowDisplay("神祕老人(奸笑着):\n\n\n 嘿嘿,小子,想對付個人使徒你還嫩了點,如今,我要你的鮮血做爲代價......哈哈哈哈哈哈...... \n\n\n"); 261 SlowDisplay("老人手一揮,使徒拿着鋼刀衝過來......將刀對準了"); 262 printf("%s",player.name); 263 SlowDisplay("的脖子......而後......刀砍了下來......鮮血四濺......\n\n\n"); 264 battle=0; 265 printf("%s戰死!金幣掉落%d\n\n\n",player.name,player.level*500); 266 money-=player.level*500; 267 player.health=player.max_health/5; 268 SlowDisplay("\n\n\n\n\n\n\n 頭好沉啊......怎麼回事......我這是在哪裏......\n 不對!我不是被使徒殺了嗎?怎麼復活了?不過把使徒殺了是個人任務!\n\n"); 269 SlowDisplay(" 你獲得了國王的庇護,復活了!如今請從新開始任務吧!\n\n"); 270 } 271 else 272 { 273 battle=0; 274 printf("%s戰死!金幣掉落%d\n\n\n",player.name,player.level*500); 275 money-=player.level*500; 276 player.health=player.max_health/5; 277 } 278 OrdinaryAct();////////// 279 return 1; 280 } 281 } 282 return 0; 283 } 284 void AddWupin(int wupin_sign) 285 { 286 287 switch(wupin_sign) 288 { 289 case 1:fang4n++; break; 290 case 2:fang3n++; break; 291 case 3:fang2n++; break; 292 case 4:strongman_arm=1;break; 293 case 5:gong4n++; break; 294 case 6:gong3n++; break; 295 case 7:gong2n++; break; 296 default:printf("AddWupin error\n\n\n"); 297 } 298 299 } 300 void WhetherLevelUp() 301 { 302 int i=0,j=0; 303 int l1=player.range_exp/100; 304 int l2=player.range_exp/300; 305 int l3=player.range_exp/600; 306 if(player.level<=15&&l1>0) //15級如下,經驗足夠 都知足則升級 307 { 308 if(l1==1) 309 { 310 printf("%s",player.name); 311 SlowDisplay(" 升級!\n\n\n攻擊力+3, 防護力+2, HP上限+20\n\n\n"); 312 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 313 player.attack+=3; 314 player.defense+=2; 315 player.max_health+=20; 316 player.health=player.max_health; 317 player.level++; 318 player.range_exp=0; 319 player.exp=player.max_exp; 320 player.max_exp+=100; 321 } 322 else 323 { 324 printf("好厲害!連升%d級!",l1); 325 printf("攻擊力+%d, 防護力+%d, HP上限+%d\n\n\n",3*l1,2*l1,20*l1); 326 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 327 player.attack+=3*l1; 328 player.defense+=2*l1; 329 player.max_health+=20*l1; 330 player.health=player.max_health; 331 player.level+=l1; 332 player.range_exp=0; 333 player.exp=player.max_exp; 334 player.max_exp+=100*l1; 335 } 336 } 337 else if(player.level<=40&&l2>0) 338 { 339 if(l2==1) 340 { 341 printf("%s",player.name); 342 SlowDisplay(" 升級!\n\n\n攻擊力+3, 防護力+2, HP上限+20\n\n\n"); 343 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 344 player.attack+=3; 345 player.defense+=2; 346 player.max_health+=20; 347 player.health=player.max_health; 348 player.level++; 349 player.range_exp=0; 350 player.exp=player.max_exp; 351 player.max_exp+=300; 352 } 353 else 354 { 355 printf("好厲害!連升%d級!",l1); 356 printf("攻擊力+%d, 防護力+%d, HP上限+%d\n\n\n",3*l2,2*l2,20*l2); 357 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 358 player.attack+=3*l2; 359 player.defense+=2*l2; 360 player.max_health+=20*l2; 361 player.health=player.max_health; 362 player.level+=l2; 363 player.range_exp=0; 364 player.exp=player.max_exp; 365 player.max_exp+=300*l2; 366 } 367 } 368 else if(l3>0) 369 { 370 if(l3==1) 371 { 372 printf("%s",player.name); 373 SlowDisplay(" 升級!\n\n\n攻擊力+3, 防護力+2, HP上限+20\n\n\n"); 374 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 375 player.attack+=3; 376 player.defense+=2; 377 player.max_health+=20; 378 player.health=player.max_health; 379 player.level++; 380 player.range_exp=0; 381 player.exp=player.max_exp; 382 player.max_exp+=600; 383 } 384 else 385 { 386 printf("好厲害!連升%d級!",l1); 387 printf("攻擊力+%d, 防護力+%d, HP上限+%d\n\n\n",3*l3,2*l3,20*l3); 388 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100; 389 player.attack+=3*l3; 390 player.defense+=2*l3; 391 player.max_health+=20*l3; 392 player.health=player.max_health; 393 player.level+=l3; 394 player.range_exp=0; 395 player.exp=player.max_exp; 396 player.max_exp+=600*l3; 397 } 398 } 399 } 400 void OrdinaryAct() //正常行爲菜單(移動,物品,對話,查看狀態,裝備,退出遊戲) 401 { 402 403 while(1) 404 { 405 // \(1000); 406 // system("cls"); 407 puts("============================================================================="); 408 printf("要作什麼?\n\n\n 1,移動 2,道具 3,對話 4,查看狀態 5,裝備 0,退出遊戲\n\n\n"); 409 puts("============================================================================="); 410 switch(scanf("%d",&choose_number),choose_number) 411 { 412 case 1: //顯示移動菜單 413 SlowDisplay("要去哪裏?\n\n\n"); 414 printf("1,酒吧 2,旅館 3,森林一層 4,森林二層 5,森林三層 6,草原一層 7,草原二層 8,草原三層\n9,商店\n\n\n"); 415 switch(scanf("%d",&choose_number),choose_number) 416 { 417 case 1:place_sign=place.bar; //記錄目前位置-酒吧 418 // OrdinaryAct(); 419 break; 420 case 2:place_sign=place.hotel; //進入旅店 421 SlowDisplay("要住店嗎? 200個金幣 1,是 0,否\n\n\n"); 422 choose_number=1; 423 switch(scanf("%d",&choose_number),choose_number) 424 { 425 case 1:if(money-200<0) //判斷錢是否夠 426 { 427 SlowDisplay("Sorry,你的錢不夠~\n\n\n"); 428 } 429 else 430 { 431 SlowDisplay("好好休息\n\tHP滿\n\t\t次日了\n\n"); 432 money-=200; //花費200住店費 433 player.health=player.max_health; //體力滿 434 } 435 break; 436 case 0:SlowDisplay("下次再來!\n\n\n");break; 437 default:printf("hotel talk error!\n\n\n"); 438 } 439 place_sign=0; 440 break; 441 case 3: 442 place_sign=place.forest1; 443 s=SuiJi(); 444 if(s<7) 445 { 446 battle=1; 447 guai=xiyi; 448 printf("%s撲了過來!\n\n\n",guai.name); 449 BattleAct(); 450 } 451 else if(s<9) 452 { 453 battle=1; 454 guai=witch; 455 printf("%s撲了過來!\n\n\n",guai.name); 456 BattleAct(); 457 } 458 else 459 { 460 SlowDisplay("這裏安全\n\n\n"); 461 //不用調用OAct函數,會自動執行OAct函數; 462 } 463 break; 464 case 4: 465 place_sign=place.forest2; 466 s=SuiJi(); 467 if(s<7) 468 { 469 battle=1; 470 guai=witch; 471 printf("%s撲了過來!\n\n\n",guai.name); 472 BattleAct(); 473 } 474 else if(s<9) 475 { 476 battle=1; 477 guai=strongman; 478 printf("%s撲了過來!\n\n\n",guai.name); 479 BattleAct(); 480 } 481 else 482 { 483 SlowDisplay("這裏安全\n\n\n"); 484 } 485 break; 486 case 5: 487 place_sign=place.forest3; 488 s=SuiJi(); 489 if(s<7) 490 { 491 battle=1; 492 guai=strongman; 493 printf("%s撲了過來!\n\n\n",guai.name); 494 BattleAct(); 495 } 496 else if(s<9) 497 { 498 battle=1; 499 guai=big_strongman; 500 printf("%s撲了過來!\n\n\n",guai.name); 501 BattleAct(); 502 } 503 else 504 { 505 SlowDisplay("這裏安全\n\n\n"); 506 } 507 break; 508 case 6: 509 place_sign=place.grass1; 510 s=SuiJi(); 511 if(s<7) 512 { 513 battle=1; 514 guai=bee; 515 printf("%s撲了過來!\n\n\n",guai.name); 516 BattleAct(); 517 } 518 else if(s<9) 519 { 520 battle=1; 521 guai=horse; 522 printf("%s撲了過來!\n\n\n",guai.name); 523 BattleAct(); 524 } 525 else 526 { 527 SlowDisplay("這裏安全\n\n\n"); 528 } 529 break; 530 case 7: 531 place_sign=place.grass2; 532 s=SuiJi(); 533 if(s<7) 534 { 535 battle=1; 536 guai=horse; 537 printf("%s撲了過來!\n\n\n",guai.name); 538 BattleAct(); 539 } 540 else if(s<9) 541 { 542 battle=1; 543 guai=lion; 544 printf("%s撲了過來!\n\n\n",guai.name); 545 BattleAct(); 546 } 547 else 548 { 549 SlowDisplay("這裏安全\n\n\n"); 550 } 551 break; 552 case 8: 553 place_sign=place.grass3; 554 s=SuiJi(); 555 if(s<7) 556 { 557 battle=1; 558 guai=lion; 559 printf("%s撲了過來!\n\n\n",guai.name); 560 BattleAct(); 561 } 562 else if(s<9) 563 { 564 battle=1; 565 if(strongman_arm) 566 { 567 SlowDisplay("神祕老人:\n\n\n 哈哈,年輕人,作的不錯,不過...嘿嘿,你上當啦!巨人之臂我要了,公主你也別想帶走!\n\n\n\n"); 568 printf("%s",player.name); 569 SlowDisplay(" :\n\n\n 你休想!我好不容易纔拿到巨人之臂,你別想佔個人便宜!\n\n\n神祕老人(臉色陰沉):\n\n\n 既然你這麼不識相,那麼也別怪我不客氣了!使徒,上!\n\n\n\n"); 570 guai=shitu; 571 printf("%s撲了過來!\n\n\n",guai.name); 572 BattleAct(); 573 } 574 else SlowDisplay("神祕老人:\n\n\n 年輕人,你好啊.若是你有巨人之臂,我能夠告訴你公主的下落哦~\n\n\n"); 575 } 576 else 577 { 578 SlowDisplay("這裏安全\n\n\n"); 579 } 580 break; 581 case 9:place_sign=place.shop; 582 SlowDisplay("您好,請問您須要什麼?\n\n 急救:1,止血草 500金幣 2,急救包 600金幣 3,雲南白藥 800金幣 4,超級雲南白藥 1000金幣\n 攻擊:5,手雷 1000金幣 6,毒標 2000金幣 7,手拋式原子彈 5000金幣\n 0,我只看看,不買\n\n\n"); 583 //choose_number=1; 584 switch(scanf("%d",&choose_number),choose_number) 585 { 586 case 1:if(money-500<0) //判斷錢是否夠 587 { 588 SlowDisplay(" 抱歉,你的錢好像不太夠呢~\n\n去打怪吧\n\n\n"); 589 } 590 else 591 { 592 SlowDisplay("購買成功!\n\n謝謝光臨!下次再來!~^_^~\n\n\n"); 593 money-=500; 594 cao++; 595 } 596 break; 597 case 2:if(money-600<0) //判斷錢是否夠 598 { 599 SlowDisplay(" 抱歉,你的錢好像不太夠呢~\n\n去打怪吧\n\n\n"); 600 } 601 else 602 { 603 SlowDisplay("購買成功!\n\n謝謝光臨!下次再來!~^_^~\n\n\n"); 604 money-=600; 605 jijiubao++; 606 } 607 break; 608 case 3:if(money-800<0) //判斷錢是否夠 609 { 610 SlowDisplay(" 抱歉,你的錢好像不太夠呢~\n\n去打怪吧\n\n\n"); 611 } 612 else 613 { 614 SlowDisplay("購買成功!\n\n謝謝光臨!下次再來!~^_^~\n\n\n"); 615 money-=800; 616 baiyao++; 617 } 618 break; 619 case 4:if(money-1000<0) //判斷錢是否夠 620 { 621 SlowDisplay(" 抱歉,你的錢好像不太夠呢~\n\n去打怪吧\n\n\n"); 622 } 623 else 624 { 625 SlowDisplay("購買成功!\n\n謝謝光臨!下次再來!~^_^~\n\n\n"); 626 money-=1000; 627 superbaiyao++; 628 } 629 break; 630 case 5:if(money-1000<0) //判斷錢是否夠 631 { 632 SlowDisplay(" 抱歉,你的錢好像不太夠呢~\n\n去打怪吧\n\n\n"); 633 } 634 else 635 { 636 SlowDisplay("購買成功!\n\n謝謝光臨!下次再來!~^_^~\n\n\n"); 637 money-=1000; 638 boom++; 639 } 640 break; 641 case 6:if(money-2000<0) //判斷錢是否夠 642 { 643 SlowDisplay(" 抱歉,你的錢好像不太夠呢~\n\n去打怪吧\n\n\n"); 644 } 645 else 646 { 647 SlowDisplay("購買成功!\n\n謝謝光臨!下次再來!~^_^~\n\n\n"); 648 money-=2000; 649 dubiao++; 650 } 651 break; 652 case 7:if(money-5000<0) //判斷錢是否夠 653 { 654 SlowDisplay(" 抱歉,你的錢好像不太夠呢~\n\n去打怪吧\n\n\n"); 655 } 656 else 657 { 658 SlowDisplay("購買成功!\n\n謝謝光臨!下次再來!~^_^~\n\n\n"); 659 money-=5000; 660 atom_boom++; 661 } 662 break; 663 case 0:SlowDisplay("謝謝光臨!下次再來!~^_^~\n\n\n");break; 664 default:printf("好像沒有這個貨物呢\n\n\n"); 665 } 666 break; 667 default:printf("choose map error!\n\n\n"); 668 } 669 break; 670 case 2: ChooseWupin();break; //顯示道具,並可使用. 671 case 3: //對話選項 672 if(place_sign==place.bar) 673 { 674 SlowDisplay("要和誰說話?\n\n\n1,紅髮女郎 2,賞金獵人 3,酒吧老闆\n\n\n"); //顯示對話人物 675 switch(scanf("%d",&choose_number),choose_number) 676 { 677 case 1: 678 SlowDisplay("紅髮女郎:\n\n\n 吧檯邊那個Hunter好帥啊!(~臉紅~)\n\n\n據說他常常外出打獵,外面的路他應該很熟悉的!\n\n\n"); 679 break; 680 case 2: 681 if(fang1n<1&&gong1n<1) 682 { 683 SlowDisplay("賞金獵人:\n\n\n 你要救公主啊!好膽量!\n\n\n 不過外面的叢林和草原很險惡,並且越深越危險,這是匕首和布衣,對你會有些幫助的,拿去吧!\n\n\n"); 684 printf("%s心想:(哇,這位大叔人真好啊!\n\n\n)",player.name); 685 gong1n++; 686 fang1n++; 687 } 688 else SlowDisplay("賞金獵人:\n\n\n 加油吧,年輕人!\n\n\n 不要被外面叢林和草原所嚇倒!\n\n\n"); 689 break; 690 case 3: 691 printf("要喝點什麼?\n\n\n 1,二鍋頭25金幣 HP+20 2,XO酒80金幣 HP+50 3,人頭馬面150金幣 HP+100 0,返回\n\n\n"); 692 choose_number=1; 693 while(choose_number) 694 { 695 switch(scanf("%d",&choose_number),choose_number) 696 { 697 case 1:if(money<25) 698 { 699 SlowDisplay("錢不夠!"); 700 } 701 else 702 { 703 if(player.health+20<=player.max_health) 704 { 705 SlowDisplay("HP+20."); 706 money-=25; 707 player.health+=20; 708 } 709 else 710 { 711 SlowDisplay("HP滿了"); 712 player.health=player.max_health; 713 } 714 } 715 break; 716 case 2:if(money<80) 717 { 718 SlowDisplay("錢不夠!"); 719 } 720 else 721 { 722 if(player.health+50<=player.max_health) 723 { 724 SlowDisplay("HP+50."); 725 money-=80; 726 player.health+=50; 727 } 728 else 729 { 730 SlowDisplay("HP滿了"); 731 player.health=player.max_health; 732 } 733 } 734 break; 735 case 3:if(money<150) 736 { 737 SlowDisplay("錢不夠!"); 738 } 739 else 740 { 741 if(player.health+100<=player.max_health) 742 { 743 SlowDisplay("HP+100."); 744 money-=150; 745 player.health+=100; 746 } 747 else 748 { 749 SlowDisplay("HP滿了"); 750 player.health=player.max_health; 751 } 752 } 753 break; 754 case 0:SlowDisplay("下次再來!\n");break; 755 default:SlowDisplay("輸入錯誤\n\n\n"); 756 } 757 } 758 } 759 } 760 else if(place_sign==place.hotel) 761 SlowDisplay("「老闆娘!我...」\n\n\n「我忙着呢,沒空理你~」\n\n\n"); 762 else SlowDisplay("這裏好像沒人能夠聊天\n\n\n"); 763 break; 764 case 4: DisplayState(); break; //顯示狀態 765 case 5: //裝備 766 printf("攻裝: 1,匕首:%d個 2,長劍:%d個 3,碧血劍:%d個 4,絕世好劍:%d個\n\n\n",gong1n,gong2n,gong3n,gong4n); 767 printf("防裝: 5,布衣:%d個 6,鐵甲:%d個 7,銀甲:%d個 8,黃金聖衣:%d個\t\t0,返回\n\n\n",fang1n,fang2n,fang3n,fang4n); 768 SlowDisplay("選擇要裝備的武器或防具:\n\n\n"); 769 switch(scanf("%d",&choose_number),choose_number) 770 { 771 case 1:if(gong1n>=1) 772 { 773 SlowDisplay("拿起了匕首\n\n\n"); 774 gong=gong1; 775 strcpy(gongname,"匕首"); 776 } 777 else SlowDisplay("你沒有匕首能夠裝備\n\n\n"); 778 break; 779 case 2:if(gong2n>=1) 780 { 781 SlowDisplay("拿起了長劍\n\n\n"); 782 gong=gong2; 783 strcpy(gongname,"長劍"); 784 } 785 else SlowDisplay("你沒有長劍能夠裝備\n\n\n"); 786 break; 787 case 3:if(gong3n>=1) 788 { 789 SlowDisplay("拿起了碧血劍\n\n\n"); 790 gong=gong3; 791 strcpy(gongname,"碧血劍"); 792 } 793 else SlowDisplay("你沒有碧血劍能夠裝備\n\n\n"); 794 break; 795 case 4:if(gong4n>=1) 796 { 797 SlowDisplay("拿起了絕世好劍\n\n\n"); 798 gong=gong4; 799 strcpy(gongname,"絕世好劍"); 800 } 801 else SlowDisplay("你沒有絕世好劍能夠裝備\n\n\n"); 802 break; 803 case 5:if(fang1n>=1) 804 { 805 SlowDisplay("穿上了布衣\n\n\n"); 806 fang=fang1; 807 strcpy(fangname,"布衣"); 808 } 809 else SlowDisplay("你沒有布衣能夠裝備\n\n\n"); 810 break; 811 case 6:if(fang2>=1) 812 { 813 SlowDisplay("穿上了鐵甲\n\n\n"); 814 fang=fang2; 815 strcpy(fangname,"鐵甲"); 816 } 817 else SlowDisplay("你沒有鐵甲能夠裝備\n\n\n"); 818 break; 819 case 7:if(fang3n>=1) 820 { 821 SlowDisplay("穿上了銀甲\n\n\n"); 822 fang=fang3; 823 strcpy(fangname,"銀甲"); 824 } 825 else SlowDisplay("你沒有銀甲能夠裝備\n\n\n"); 826 break; 827 case 8:if(fang4n>=1) 828 { 829 SlowDisplay("穿上了黃金聖衣\n\n\n"); 830 fang=fang4; 831 strcpy(fangname,"黃金聖衣"); 832 } 833 else SlowDisplay("你沒有黃金聖衣能夠裝備\n\n\n"); 834 break; 835 case 0:SlowDisplay("未更換裝備\n\n\n");break; 836 default:printf("change error!"); 837 } 838 break; 839 case 0: 840 SlowDisplay("肯定推出遊戲?(Y/N)\n\n\n"); 841 getchar(); 842 proof=getchar(); 843 if(proof=='y'||proof=='Y') 844 { 845 SlowDisplay("數據存儲中..."); 846 //向文件中更新數據; 847 getchar(); 848 SlowDisplay("按回車退出"); 849 getchar(); 850 return; 851 } 852 else if(proof=='n'||proof=='N')printf("繼續遊戲!\n\n\n"); 853 else SlowDisplay("繼續!\n\n\n"); 854 break; 855 default:SlowDisplay("輸入錯誤!\n\n\n"); 856 } 857 } 858 } 859 void DisplayState() 860 { 861 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); 862 printf("武器: %s 防具: %s \n\n\n",gongname,fangname); 863 printf("等級:%d 經驗:%d/%d 還須要%d經驗升級 金幣:%d \n\n\n",player.level,player.exp,player.max_exp,player.max_exp-player.exp,money); 864 } 865 void BattleAct() 866 { 867 while(1) 868 { 869 puts("============================================================================="); 870 printf("要怎麼辦?\n\n\n 1,攻擊 2,物品 3,查看狀態 4,逃跑\n\n\n"); 871 switch(scanf("%d",&choose_number),choose_number) 872 { 873 case 1: 874 s=SuiJi(); 875 printf("%s攻擊! %sHP減小%d\n\n\n",player.name,guai.name,player.attack+s+gong-guai.defense/3); 876 guai.health-=player.attack+s+gong-guai.defense/3; 877 if(AttackResult())return; //若是攻擊有結果(敵人或玩家戰死)退出函數 878 else continue; 879 case 2: ChooseWupin();break; //選擇物品,可使用,戰鬥中容許使用攻擊性物品 880 case 3:DisplayState();break; //顯示狀態 881 case 4: 882 s=SuiJi(); 883 if(s<4) //40%的機率能夠逃跑 884 { 885 printf("%s逃跑了~\n\n\n",player.name); 886 battle=0; 887 return; 888 } 889 else printf("%s逃跑失敗!\n\n\n",player.name); 890 break; 891 default:SlowDisplay("輸入錯誤,從新輸入!\n\n\n"); 892 } 893 } 894 } 895 void SlowDisplay(char *p) 896 { 897 while(1) 898 { 899 if(*p!=0) 900 printf("%c",*p++); 901 else 902 break; 903 Sleep(50); 904 } 905 }