码迷,mamicode.com
首页 > 其他好文 > 详细

Card.cpp

时间:2017-12-02 00:45:08      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:out   amount   clu   sea   cin   car   find   span   fst   

 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

标签:out   amount   clu   sea   cin   car   find   span   fst   

原文地址:http://www.cnblogs.com/lostmatch/p/7944850.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!