Card.cpp
阿新 • • 發佈:2017-12-02
eset get att ring color else sign cin his
1 #include "Cards.h" 2 3 CARD::CARD(unsigned int amount,std::ifstream &i,std::string path) 4 { 5 this->Camount=amount; 6 std::string datain; 7 this->Cdata.push_back(datain); 8 i.open(path); 9 while(std::getline(i,datain)) 10 { 11 this->Cdata.push_back(datain);12 } 13 std::cout<<"Data has been loaded successfully."<<std::endl; 14 } 15 16 void CARD::Reset() 17 { 18 std::vector<std::string> reset; 19 this->Cdata=reset; 20 std::cout<<"DATARESET!!!"<<std::endl; 21 } 22 23 void CARD::Display() 24 { 25 std::cout<<"****************THE DATA OF THE CARDS*****************"<<std::endl; 26 for(int m=1;m<=this->Camount;m++) 27 { 28 std::cout<<"Name:"<<this->Cdata[3m-2]<<std::endl; 29 std::cout<<"Attack:"<<this->Cdata[3m-1]<<std::endl; 30 std::cout<<"HP"<<this->Cdata[3m]<<std::endl; 31 } 32 } 33 34 void CARD::Search() 35 { 36 std::string name; 37 while(0) 38 { 39 std::cout<<"Enter the card‘s name you want to search."<<std::endl; 40 std::cin>>name; 41 auto result=std::find(this->Cdata.begin(),this->Cdata.end(),name); 42 if(result==this->Cdata.end()) 43 { 44 std::cout<<"No data. Try again? Enter 1 or 0"<<std::endl; 45 int choice=0; 46 std::cin>>choice; 47 if(choice==1) 48 { 49 continue; 50 } 51 else 52 { 53 break; 54 } 55 } 56 else 57 { 58 auto attack=result+1; 59 auto HP=result+2; 60 std::cout<<"Name:"<<*result<<std::endl; 61 std::cout<<"Attack:"<<*attack<<std::endl; 62 std::cout<<"HP:"<<*HP<<std::endl; 63 std::cout<<"Search again?Enter 1 or 0"<<std::endl; 64 int choice2=0; 65 std::cin>>choice; 66 if(choice==1) 67 { 68 continue; 69 } 70 else 71 { 72 break; 73 }
(本來想用多個vector來儲存對應數據的,但是想想工作量巨大,於是打消了這個念頭)
Card.cpp