1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
| #include<iostream> #include<vector> #include<string> #include<fstream> #include<sstream> #include<iomanip> #include<map> #include<algorithm> #include<stdio.h> #include<time.h>
#define random(x) (rand()%x) using namespace std;
typedef struct//存储文档数据的结构体 { string sort; int day; int strength, money, time; map<string, int> foods; string sex; int satiety; int happiness; int cleanliness; int weight; }datas;
class player; class pet; class cat; class dog;
void interactCat(cat& pe, player& pl, int day); void interactdog(dog& pe, player& pl, int day); void getData(const string& filename, datas& data); void putData(const string& filename, datas data); void adopt(); void continueAdopt(datas da);
class food { private: string name; int payMoney; int addStrength; int addHappiness; int reduceCleanliness; public: food(string n, int p, int as, int ah, int rc) :name(n), payMoney(p), addStrength(as), addHappiness(ah), reduceCleanliness(rc) {}; string getName() { return name; }; int getPayMoney() { return payMoney; }; int getAddStrength() { return addStrength; }; int getAddHappiness() { return addHappiness; }; int getReduceCleanliness() { return reduceCleanliness; }; };
food petfood[5] = { {"粗糙的粮食",30,30,10,15}, {"精品粮食",60,50,40,5}, {"香肠",20,20,30,20}, {"辣条",10,20,5,30}, {"老八秘制小汉堡",28,66,-30,66} };
class player { private: int strength, money, time; map<string, int> foods; public: player(int s = 100, int m = 100, int t = 7, map<string, int> food = {}) :strength(s), money(m), time(t) {}; int getTime() { return time; }; int getStrength() { return strength; }; int getMoney() { return money; }; map<string, int> getFoods() {return foods; }; void show(); int teach(); int kfc(); int cutGrass(); int buyFood(); int feed(); void relax(); int playWithPet(); int cleanPet(); void sleep(); void change(); void foodGet(const map<string, int> f); };
void player::foodGet(const map<string, int> f) { foods = f; }
void player::change() { if (strength >= 100) strength = 100; if (strength <= 0) strength = 0; }
void player::show() { cout <<"玩家的属性值:"<< "strength:" << strength << " money:" << money << " time" << time << endl<<endl; }
int player::teach() { int flag = 1; if (time >= 2) { if (strength >= 30) { time -= 2; money += 50; strength -= 30; } else { cout << "体力不足" << endl; flag = 0; }
} else cout << "今天时间不够了" << endl << endl; return flag;
}
int player::kfc() { int flag = 1; if (time >= 4) { if (strength >= 70) { time -= 4; money += 120; strength -= 70; } else { cout << "体力不足" << endl; flag = 0; } } else cout << "今天时间不够了" << endl << endl; return flag; }
int player::cutGrass() { int flag = 1; if (time >= 1) {
if (strength >= 20) { time--; money += 20; strength -= 20; } else { cout << "体力不足" << endl; flag = 0; } } else cout << "今天时间不够了" << endl << endl; return flag; }
int player::buyFood() { int flag = 1; if (strength >= 20) { time--; strength -= 20; system("cls"); cout << "哈喽~ " << endl << endl << "欢迎光临小店!" << endl<<endl << "以下是食物清单~" << endl<<endl << "1号食物《粗糙的粮食》所需金钱:30 增加的体力:30 增加愉悦度:10 减少清洁度:15" << endl << endl << "2号食物《精品粮食》所需金钱 60 增加的体力:50 增加愉悦度:40 减少清洁度:5" << endl << endl << "3号食物《香肠》所需金钱 20 增加的体力:20 增加愉悦度:30 减少清洁度:20" << endl << endl << "4号食物《辣条》所需金钱 10 增加的体力:20 增加愉悦度:5 减少清洁度:30" << endl << endl << "5号食物《老八秘制小汉堡》所需金钱 28 增加的体力:66 增加愉悦度:-30 减少清洁度:6<<6" << endl << endl << "**请输入所要购买食物的序号**" << endl << endl; int sec; cin >> sec; money -= petfood[sec - 1].getPayMoney(); foods[petfood[sec - 1].getName()]++; } else { cout << "体力不足" << endl; flag = 0; } return flag; }
int player::feed() { time--; strength -= 20; int flag=0; system("cls"); cout << "有如下食物" << endl << endl; for (map<string, int>::iterator i = foods.begin(); i != foods.end(); i++) { if (i->second >= 1) { cout << i->first << ":" << i->second << endl << endl; flag = 1; } } if (flag == 0) { cout << "你没有食物!" << endl << endl; cout << "输入任意键按回车返回:"; cin >> flag; return -1; } else { cout << "选择喂食食物:(《-请看清你有哪些食物,再进行喂食!)" << endl << endl << "1号食物《粗糙的粮食》增加的体力:30 增加愉悦度:10 减少清洁度:15" << endl << endl << "2号食物《精品粮食》增加的体力:50 增加愉悦度:40 减少清洁度:5" << endl << endl << "3号食物《香肠》增加的体力:20 增加愉悦度:30 减少清洁度:20" << endl << endl << "4号食物《辣条》增加的体力:20 增加愉悦度:5 减少清洁度:30" << endl << endl << "5号食物《老八秘制小汉堡》增加的体力:66 增加愉悦度:-30 减少清洁度:66" << endl << endl; int sec; cin >> sec; foods[petfood[sec - 1].getName()]--; return sec - 1; }
}
void player::relax() { time--; strength += 50; if (strength > 100) strength = 100; }
int player::playWithPet() { int flag=1; if (strength >= 20) { time--; strength += 50; } else { cout << "体力不足" << endl; flag = 0; } return flag;
}
int player::cleanPet() { int flag = 1; if (strength >= 20) { time--; strength -= 30; } else { cout << "体力不足" << endl; flag = 0; } return flag; }
void player::sleep() { time = 7; strength = 100; }
class pet //该类为抽象类,用作cat类和dog类的基类 { protected: string sex; int satiety; int happiness; int cleanliness; int weight; public: pet(string s = "无", int sa = 0, int ha = 0, int cl = 0, int we = 0) : sex(s), satiety(sa), happiness(ha), cleanliness(cl), weight(we) {}; string getSex() { return sex; }; int getSatiety() { return satiety; }; int getHappiness() { return happiness; }; int getCleanliness() { return cleanliness; }; int getWeight() { return weight; }; virtual void change()=0; virtual void show()=0; virtual void play()=0; virtual void shout() = 0; void eat(int sec); virtual void cleanByBoss() = 0; virtual void unInterract() = 0; virtual int death() = 0; void balance(); void dayEnd(); };
void pet::balance() { if (happiness >= 100) happiness = 100; if (happiness <= 0) happiness = 0; if (satiety >= 100) satiety = 100; if (satiety <= 0) satiety = 0; if (cleanliness >= 100) cleanliness = 100; if (cleanliness <= 0) cleanliness = 0; }
void pet::eat(int sec) { if(sec!=-1) { satiety += petfood[sec].getAddStrength(); cleanliness -= petfood[sec].getReduceCleanliness(); happiness += petfood[sec].getAddHappiness(); }
}
void pet::dayEnd() { happiness += 30; cleanliness -= 5; satiety -= 60; }
class cat :public pet { public: cat(string s = "无", int sa = 0, int ha = 0, int cl = 0, int we = 0) :pet(s, sa, ha, cl, we) {}; virtual void show(); virtual void play(); virtual void shout(); virtual void change(); virtual void cleanByBoss(); virtual void unInterract(); virtual int death(); void cleanMyself(); int catchMouse(); };
void cat::show() { cout << "你可爱的小" << getSex() << "猫" << ":" << "属性值如下:" << " 饱食度:" << getSatiety() << " 愉悦度:" << getHappiness() << " 清洁度:" << getCleanliness() << " 体重:" << getWeight() << endl << endl; }
void cat::play() { if (happiness >= 30) { satiety -= 20; happiness += 30; cleanliness -= 10; } else { cout << "愉悦度不够,猫主子不想洗" << endl << endl; } }
void cat::shout() { cout << "喵喵~~ 喵~ 喵~ 喵~ " << endl << endl; }
void cat::cleanMyself() { srand((int)time(0)); if(random(10)<=2) cleanliness += 30; }
void cat::cleanByBoss() { if (happiness >= 90) { if (cleanliness >= 80) happiness -= 50; cleanliness = 100; } else { cout << "愉悦度不够,猫懒得理你" << endl << endl; } }
int cat::catchMouse() { srand((int)time(0)); if (random(10) <= 1) { if (satiety < 50) { satiety += 40; cleanliness -= 30; happiness += 5; } else { satiety -= 20; cleanliness -= 10; happiness += 40; } return 0; } return 1; }
void cat::unInterract() { satiety -= 20; cleanliness -= 5; }
void die() { cout << "对于死亡这个话题我们一直是缺席的,从小我们只学到了要热爱生命、珍惜生命,却从来没有人教过我们如何面对死亡......" << endl << endl
<< "而我们每一个养宠人都会更加刻意逃避这一天的到来......" << endl << endl
<< "”到饭点,倒完粮才意识到它已经不在了……“" << endl << endl
<< "”需要等 5 分钟才敢进家门。我得告诉自己,不会再有人迎接你了……“" << endl << endl
<< "”床终于变得宽敞了,似乎也变凉了......" << endl << endl
<< "“由于你的喂食不当你的宠物饿死了..." << endl; }
int cat::death() { int flag = 1;
if (happiness == 0) { cout << "由于你的疏于照顾,小猫一点也不高兴,永远的离开了你" << endl << endl; flag = 0; } else if (sex == "公") { if (weight < 4 || weight>16) { die(); flag = 0; } } else { if (weight < 2 || weight>10) { die(); flag = 0; } } return flag; }
void cat::change() { int flag = 1;
if (satiety == 0) { happiness -= 10; weight -= 1; } else if (satiety == 100) weight += 1;
if (sex == "公") { if (weight < 8 || weight>12) { happiness -= 10; } } else { if (weight < 4 || weight>8) { happiness -= 10; } }
if (cleanliness == 0) { happiness -= 30; } else if(cleanliness>80) { happiness += 10; }
if (happiness >= 100) happiness = 100; if (happiness <= 0) happiness = 0; if (satiety >= 100) satiety = 100; if (satiety <= 0) satiety = 0; if (cleanliness >= 100) cleanliness = 100; if (cleanliness <= 0) cleanliness = 0;
}
class dog :public pet { public: dog(string s = "无", int sa = 0, int ha = 0, int cl = 0, int we = 0) :pet(s, sa, ha, cl, we) {}; virtual void show(); virtual void play(); virtual void shout(); virtual void change(); virtual void cleanByBoss(); virtual void unInterract(); virtual int death(); };
void dog::show() { cout << "你可爱的小" << getSex() << "狗" << ":" << "属性值如下:" << " 饱食度:" << getSatiety() << " 愉悦度:" << getHappiness() << " 清洁度:" << getCleanliness() << " 体重:" << getWeight() << endl << endl; }
void dog::play() { if (happiness >= 30) { satiety -= 40; happiness += 70; cleanliness -= 10; } else { cout << "愉悦度达不到要求,狗子懒得理你" << endl << endl; } }
void dog::shout() { cout << "汪汪汪~~ 汪汪~ 汪汪~ " << endl << endl; }
void dog::cleanByBoss() { if (happiness >= 70) { cleanliness = 100; } else { cout << "愉悦度不够,狗子懒得洗" << endl << endl; } }
void dog::unInterract() { satiety -= 20; happiness -= 20; cleanliness -= 20; }
void dog::change() { if (satiety == 0) { happiness -= 10; weight -= 2; } else if (satiety == 100) weight += 2;
if (cleanliness == 0) { happiness -= 30; } else if (cleanliness > 80) { happiness += 10; }
if (weight < 30 || weight>60) { happiness -= 10; }
if (happiness >= 100) happiness = 100; if (happiness <= 0) happiness = 0; if (satiety >= 100) satiety = 100; if (satiety <= 0) satiety = 0; if (cleanliness >= 100) cleanliness = 100; if (cleanliness <= 0) cleanliness = 0; }
int dog::death() { int flag = 1; if (happiness == 0) { flag = 0; cout << "由于你的疏于照顾,狗子一点也不高兴,永远的离开了你" << endl << endl; } else { if (weight < 15 || weight>75) { die(); flag = 0; } } return flag; }
void info(int sec) { if (!sec) cout << "猫猫去捉鼠了,不能和它互动了哦!" << endl << endl; cout << "选择你的行动"<< endl << endl << "1.家教,消耗2个时间,获取50金钱,消耗30体力" << endl << endl << "2.麦当劳兼职,消耗个4时间,获取120金钱,消耗70体力" << endl << endl << "3.割草,消耗1个时间,获取20金钱,消耗20体力" << endl << endl << "4.购买宠物粮食,玩家消耗1个时间,20体力,根据具体宠物粮食消耗金钱。" << endl << endl << "5.休息,玩家消耗1个时间,恢复50体力。" << endl << endl; if (sec) { cout << "6.喂食:玩家消耗1个时间,20体力" << endl << endl << "7.和宠物玩耍:玩家消耗1个时间,50体力。(需愉悦度>=30)" << endl << endl << "8.清洗宠物:玩家消耗1个时间,30体力。(猫猫愉悦度需>=90才可以清洗,狗需>=70)" << endl << endl; } cout << "9.宠物系统说明。" << endl << endl; cout << "10.退出游戏并存档。" << endl << endl; cout << "请选择你的行动序号"<<endl << endl;
}
void infomation() { system("cls"); cout << "饱食度:宠物的饱食度为0时,会降低10点愉悦度,猫会降低1斤体重,狗会降低2斤体重。" << endl<<endl; cout << "宠物饱食度为100时,猫会提高1斤体重,狗会提高2斤体重。宠物被喂食会根据投喂的食物提高" << endl << endl; cout << "一定饱食度。宠物玩耍后会根据玩耍和宠物自身情况降低饱食度。" << endl << endl; cout << "愉悦度:愉悦度影响宠物对玩家的态度,愉悦度为0时,宠物会离开主人;愉悦度低于30时," << endl << endl; cout << "宠物不会和主人玩耍;愉悦度低于70时,宠物狗不会让主人清洗;宠物猫的愉悦度必须90以上,才会让主人清洗。" << endl << endl; cout << "体重:体重是衡量宠物的健康,公猫健康体重为8~12斤,初始时公猫为10斤,母猫健康体重为4~8斤,初始时母猫" << endl << endl; cout << "为6斤。公猫体重低于4斤,高于16斤将会因为健康不佳死亡,母猫体重低于2斤,高于10斤将会因为健康死亡。狗健康" << endl << endl; cout << "体重为30~60斤,初始时狗会有45斤体重。低于15斤,高于75斤,狗会因为健康死亡。宠物低于超出健康体重时,每个时" << endl << endl; cout << "间段都会降低10点愉悦度。" << endl << endl; cout << "清洁度:清洁度为0时,宠物愉悦度每个时间段降低30,清洁度高于80时,宠物愉悦度每个时间段升高10。" << endl << endl; cout << "宠物自动行为:" << endl << endl; cout << "猫的自洁:猫有30% 的可能性进行自洁,消耗1个时间,提高30清洁度;" << endl << endl; cout << "猫的随机抓老鼠:在任何时间段,猫有20% 的可能会去抓老鼠,此时主人是" << endl << endl; cout << "无法对猫进行交互的。消耗1个时间,如果此时猫的饱食度低于50,会吃掉老鼠" << endl << endl; cout << ",提高40饱食度,降低30清洁度,提高5愉悦度。如果此时猫的饱食度大于等于50" << endl << endl; cout << ",猫只会玩耍老鼠,降低20饱食度,降低10清洁度,提高40愉悦度。" << endl << endl; cout << "非主人交互时间:该时间段一般为主人买东西、打工或休息等无暇顾及宠物的时间段," << endl << endl; cout << "该时间段内宠物将降低20饱食度,另外,狗降低20点愉悦度,和20点清洁度。" << endl << endl; cout << "猫不会降低愉悦度,但是会降低5清洁度。" << endl << endl; cout << "每天结束时,宠物会强制进入休息,提高30愉悦度,降低5清洁度,降低60饱食度。" << endl << endl; }
void interactCat(cat& pe, player& pl,int day) { int flag = pe.catchMouse(); info(flag); int sec; cin >> sec; if (flag) { switch (sec) { case 1: if (pl.teach()) { pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); } break; case 2: if (pl.kfc()) { pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); } break; case 3: if (pl.cutGrass()) { pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); } break; case 4: if (pl.cutGrass()) { pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pl.buyFood(); } break; case 6: pe.shout(); pe.change(); pe.eat(pl.feed()); break; case 5: pl.relax(); pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); break; case 7: pe.change(); if (pl.playWithPet()) { pe.change(); pe.play(); } break; case 8: if (pl.cleanPet()) { pe.change(); pe.cleanByBoss(); } break; case 9: infomation(); break; case 10: datas da; da.cleanliness = pe.getCleanliness(); da.day = day; da.foods = pl.getFoods(); da.happiness = pe.getHappiness(); da.money = pl.getMoney(); da.satiety = pe.getSatiety(); da.sex = pe.getSex(); da.sort = "cat"; da.strength = pl.getStrength(); da.time = pl.getTime(); da.weight = pe.getWeight(); putData("data", da); exit(0); break; }
} else { switch (sec) { case 1: if (pl.teach()) { pe.change(); pe.unInterract(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pe.change(); } break; case 2: if (pl.kfc()) { pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pe.change(); if (pe.catchMouse()) pe.cleanMyself(); pe.unInterract(); pe.change(); } break; case 3: if (pl.cutGrass()) { pe.change(); pe.unInterract(); } break; case 4: if (pl.buyFood()) { pe.change(); pe.unInterract(); } break; case 5: pl.relax(); pe.change(); pe.unInterract(); break; case 9: infomation(); break; case 10: datas da; da.cleanliness = pe.getCleanliness(); da.day = day; da.foods = pl.getFoods(); da.happiness = pe.getHappiness(); da.money = pl.getMoney(); da.satiety = pe.getSatiety(); da.sex = pe.getSex(); da.sort = "cat"; da.strength = pl.getStrength(); da.time = pl.getTime(); da.weight = pe.getWeight(); putData("data", da); exit(0); break; } } }
void interactdog(dog& pe, player& pl,int day) { info(1); int sec; cin >> sec; switch (sec) { case 1: if (pl.teach()) { pe.change(); pe.unInterract(); pe.change(); pe.unInterract(); }
break; case 2: if (pl.kfc()) { pe.change(); pe.unInterract(); pe.change(); pe.unInterract(); pe.change(); pe.unInterract(); pe.change(); pe.unInterract(); } break; case 3: if (pl.cutGrass()) { pe.change(); pe.unInterract(); } break; case 4: if (pl.buyFood()) { pe.change(); pe.unInterract(); } break; case 6: pe.shout(); pe.change(); pe.eat(pl.feed()); break; case 5: pl.relax(); pe.change(); pe.unInterract(); break; case 7: if (pl.playWithPet()) { pe.change(); pe.play(); } break; case 8: if (pl.cleanPet()) { pe.change(); pe.cleanByBoss(); } break; case 9: infomation(); break; case 10: datas da; da.cleanliness = pe.getCleanliness(); da.day = day; da.foods = pl.getFoods(); da.happiness = pe.getHappiness(); da.money = pl.getMoney(); da.satiety = pe.getSatiety(); da.sex = pe.getSex(); da.sort = "cat"; da.strength = pl.getStrength(); da.time = pl.getTime(); da.weight = pe.getWeight(); putData("data", da); exit(0); break; } }
void adopt() { cout << "请选择你想养的宠物 (1)猫 or (2)狗" << endl; int sec; cin >> sec; player me; string sex; int secp; int a=80, b=80, c=80, d; if (sec == 1) { cout << "请好好对待这只小猫哦~" << endl << endl; cout << "你是想养只公猫猫还是只母猫猫" << endl << endl; cout << "(1) 公猫猫 (2) 母猫猫 " << endl << endl; int sec2; cin >> sec2; if (sec2 == 1) { sex = "公"; d = 10; } else { sex = "母"; d = 6; } } else { cout << "你是想养只公狗子还是只母狗子" << endl << endl; cout << "(1) 公狗子 (2) 母狗子 " << endl << endl; int sec2; cin >> sec2; if (sec2 == 1) { sex = "公"; d = 45; } else { sex = "母"; d = 45; } cout << "请好好对待这只小狗哦~" << endl << endl; secp = 1; } cat pecat(sex, a, b, c, d); dog pedog(sex, a, b, c, d);
int day = 0; string temp; while (day != 30) { if (sec==1) { int life = 1; system("cls"); while (me.getTime()>0) { system("cls"); cout << "今天是与萌宠相伴的第" << day + 1 << "天" << endl << endl; pecat.balance(); me.change(); me.show(); pecat.show(); interactCat(pecat, me,day); if (!pecat.death()) { life = 0; break; } cout << "任意输入按回车进入下一时间段" << endl << endl; cin >> temp; } if (!life) break; day++; me.sleep(); pecat.dayEnd(); } else { int life = 1; system("cls"); cout << "第" << day + 1 << "天开始了" << endl << endl; while (me.getTime() > 0) { system("cls"); cout << "今天是与萌宠相伴的第" << day + 1 << "天" << endl << endl; pedog.balance(); me.change(); me.show(); pedog.show(); interactdog(pedog, me,day); if (!pedog.death()) { life = 0; break; } cout << "任意输入按回车进入下一时间段" << endl << endl; cin >> temp; } if (!life) break; day++; me.sleep(); pedog.dayEnd(); } } if (day == 30) cout << "完结撒花,宠物寿终正寝!" << endl << endl; }
void continueAdopt(datas da) { player me(da.strength, da.money, da.time); me.foodGet(da.foods); if (da.sort == "cat") { cat pecat(da.sex, da.satiety, da.happiness, da.cleanliness, da.weight); int day = da.day; string temp; while (day != 30) { if (typeid(cat) == typeid(pecat)) { int life = 1; system("cls"); while (me.getTime() > 0) { system("cls"); cout << "今天是与萌宠相伴的第" << day + 1 << "天" << endl << endl; pecat.balance(); me.change(); me.show(); pecat.show(); interactCat(pecat, me,day); if (!pecat.death()) { life = 0; break; } cout << "任意输入按回车进入下一时间段" << endl << endl; cin >> temp; } if (!life) break; day++; me.sleep(); pecat.dayEnd(); } } if (day == 30) cout << "完结撒花,宠物寿终正寝!" << endl << endl; } if (da.sort == "dog") { dog pedog(da.sex, da.satiety, da.happiness, da.cleanliness, da.weight); int day = da.day; string temp; while (day != 30) { if (typeid(dog) == typeid(pedog)) { int life = 1; system("cls"); while (me.getTime() > 0) { system("cls"); cout << "今天是与萌宠相伴的第" << day + 1 << "天" << endl << endl; pedog.balance(); me.change(); me.show(); pedog.show(); interactdog(pedog, me,day); if (!pedog.death()) { life = 0; break; } cout << "任意输入按回车进入下一时间段" << endl << endl; cin >> temp; } if (!life) break; day++; me.sleep(); pedog.dayEnd(); } } if (day == 30) cout << "完结撒花,宠物寿终正寝!" << endl << endl; } }
void getData(const string& filename, datas& data) { ifstream fin(filename); if (fin.good()) { fin>>data.day>>data.sort>>data.strength>>data.money>>data.time>> data.sex>>data.satiety>>data.happiness>>data.cleanliness>>data.weight; string str; int num; while (fin >> str >> num) { data.foods[str] = num; } } fin.close(); }
void putData(const string& filename,datas data) { ofstream fout(filename); if (fout.good()) { fout<<data.day<<" "<<data.sort<<" "<< data.strength <<" "<< data.money <<" "<< data.time <<" "<< data.sex <<" "<< data.satiety <<" "<< data.happiness <<" "<< data.cleanliness <<" "<< data.weight; string str; int num; for(map<string,int>::iterator i=data.foods.begin();i!=data.foods.end();i++) { fout << i->first; fout << " " << i->second; } } fout.close(); }
int main() { cout <<"欢迎来到电子宠物养成系统~" << endl<<endl; cout << "选择(1)开始游戏或(2)读取存档"<<endl<<endl; cout << "请输入选择:" << endl; int sec; cin >> sec; if (sec == 1) { adopt(); } else { datas da; getData("data", da); continueAdopt(da); } }
|