Team Class

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.2 kB
7
Indexable
Never
class Team{
private:
    vector<character*> members;
    bool teamMark;
public:
    Team(){
        teamMark = false;
    };
    ~Team(){

        for (character* members : members) {
            delete members;
        }

    }
    // 獲得隊伍的大小
    size_t getSize() const {
        return members.size();
    }

    character* operator[](size_t index) const {
        if (index < members.size()) {
            return members[index];
        } else {
            // 如果索引越界,這裡可以進行錯誤處理,比如返回一個默認值或拋出異常
            // 這裡簡單返回 nullptr
            return nullptr;
        }
    }

    void setTeamMark(){teamMark = true; return;}
    //addClassWarrior();
    void addClassWizard(int x, int y);
    //addClassArcher();
    //addClassTank();
    //addClassBishop();
    void addClassKnight(int x, int y);
};

void Team::addClassWizard(int x, int y) {
    character* newWizard = new Wizard(x, y);  // 假設 Wizard 類別有符合的建構函式
    members.push_back(newWizard);
    
}

void Team::addClassKnight(int x, int y){
    character* newKnight = new Knight(x, y);
    members.push_back(newKnight);
}
Leave a Comment