1. 程式人生 > >player.cpp

player.cpp

windows.h span per att temp opera ring cda stream

[第7次修改]

 1 #include <iostream>
 2 #include <vector>
 3 #include <Windows.h>
 4 #include "player.h"
 5 
 6 void PLAYER::damage_display(std::string attacker,std::string is_attacked,int damage)
 7 {
 8     std::cout<<std::endl;
 9     std::cout<<attacker<<""<<is_attacked<<"
造成了"<<damage<<"點傷害"<<std::endl; 10 Sleep(500); 11 } 12 13 void PLAYER::selectcard(CARD &c) 14 { 15 std::string nulldata("0"); 16 this->Pdata.push_back(nulldata); 17 std::vector<int> selected; 18 selected.push_back(0); 19 int num=0; 20 int times=0;
21 std::cout<<"請輸入你想選擇的卡片的序號(不同序號之間用空格分隔,輸入完畢按Ctrl+Z後按回車,最多6張,否則遊戲會崩潰哦,這是數組本身具有的問題。)"<<std::endl; 22 for(int n=1;n<=c.Camount;n++) 23 { 24 std::cout<<"["<<n<<"]"<<c.Cdata[3*n-2]<<std::endl; 25 } 26 if(std::cin>>num) 27 {
28 times++; 29 selected.push_back(num); 30 } 31 32 for(int m=1;m<=times;m++) 33 { 34 int index=selected[m]; 35 this->Pdata.push_back(c.Cdata[3*index-2]); 36 this->Pdata.push_back(c.Cdata[3*index-1]); 37 this->Pdata.push_back(c.Cdata[3*index]); 38 } 39 std::cout<<"[From Console] 數據裝載完畢!"<<std::endl; 40 } 41 42 void PLAYER::operate(AI &a,DISPLAY &d) 43 { 44 std::cout<<"請輸入想要發起攻擊的我方卡片序號."<<std::endl; 45 int index_p=0; 46 int index_e=0; 47 std::cin>>index_p; 48 std::cout<<"請輸入被攻擊的敵方卡片序號"<<std::endl; 49 std::cin>>index_e; 50 std::string damage_temp=this->Pdata[(index_p*3)-1]; 51 std::string hp_temp=a.Adata[index_e*3]; 52 int damage=dataChanger<int>(damage_temp); 53 int hp=dataChanger<int>(hp_temp); 54 std::string attacker=this->Pdata[index_p*3-2]; 55 std::string is_attacked=a.Adata[index_e*3-2]; 56 if(hp<damage) 57 { 58 std::string new_hp1("0"); 59 a.Adata[index_e*3]=new_hp1; 60 this->damage_display(attacker,is_attacked,damage); 61 } 62 else if(hp>=damage) 63 { 64 int hp_tempx=hp-damage; 65 std::string new_hp2=std::to_string(hp_tempx); 66 a.Adata[3*index_e]=new_hp2; 67 this->damage_display(attacker,is_attacked,damage); 68 } 69 }

player.cpp