CSC112 Spring 2016 Examples
#include "alpacaFracasPack.h"12AlpacaFracasPack::AlpacaFracasPack()3{4packPower = 0;5}678AlpacaFracasPack::~AlpacaFracasPack()9{10//delete all the alpacas!11for(auto itr=alpacaList.begin(); itr != alpacaList.end(); itr++) {12delete *itr;13}14}151617//Removes the first alpaca from the pack and returns it. Returns null if there is no alpaca18Alpaca *19AlpacaFracasPack::unload()20{21Alpaca *result;2223//handle empty lists24if(alpacaList.size() == 0) return NULL;2526//ok, we have an alpaca!27result = alpacaList[0];28alpacaList.erase(alpacaList.begin());2930return result;31}323334//Adds an alpaca to the pack returns true on success and false if this alpaca would push35//the points limit over the max points ormax alpacas36bool37AlpacaFracasPack::load(Alpaca *a)38{39//check legality40if(packPower + a->getPower() > MAX_POINTS) {41return false;42}4344//welcome to the fold!45packPower += a->getPower();46alpacaList.push_back(a);47return true;48}4950//returns the number of remaining alpacas51int52AlpacaFracasPack::packSize()53{54return alpacaList.size();55}565758//returns the number of remaining power points in the pack59unsigned int60AlpacaFracasPack::power()61{62unsigned int result=0;6364for(auto itr=alpacaList.begin(); itr!=alpacaList.end(); itr++) {65result += (*itr)->getPower();66}6768return result;69}707172//returns the power points at the time of pack creation73unsigned int74AlpacaFracasPack::originalPower()75{76return packPower;77}787980//allows access to the alpacas in the pack note that this does not return by reference.81//you cannot change the alpacas around!82Alpaca *83AlpacaFracasPack::operator[](unsigned int i)84{85//handle the possibility of an invalid index86if(i < alpacaList.size()) {87return alpacaList[i];88}8990//if we make it here, the index was invalid91return NULL;92}939495