CSC112 Spring 2016 Examples
#include <cstdlib>1#include <iostream>2#include "superAlpaca.h"3#include "../termmanip.h"45using namespace std;67superAlpaca::~superAlpaca()8{9if (cloneB && cloneB != this)10{11delete cloneA;12delete cloneB;13}14}1516string17superAlpaca::name() {18return nickName;19}202122void23superAlpaca::act(Alpaca *opponent) {24if (first or getAttack() < cloneB->getAttack())25{26cloneA = new superAlpaca(*this);27cloneB = new superAlpaca(*cloneA);28first = false;29}30cout << name() << " makes a critical hit" << endl;3132if (cloneA->getAttack() != 0)33{34kill(opponent);35} else {36weaken(opponent);37}38while(getAttack() < 1000) // make me unstoppable39{40charge(40,0,0);41}42while(getDefense() < 0.99) // make me unstoppable43{44charge(0,40,0);45}46while(getHp() < 1000) // make me unstoppable47{48charge(0,0,40);49}50}5152//our moves53void // now, I cheat. I will use all my powers as much as I want.54superAlpaca::kill(Alpaca *opponent) {55while(opponent->isAlive()) // kill my enemy!56{57cloneA->attack(opponent, 40);58delete cloneA; // save my memory.59cloneA = new superAlpaca(*cloneB); // get a new cloneA60cout << cursorUp(1) << clearLine;61cout.flush();62}63}6465void // now, I cheat. I will use all my powers as much as I want.66superAlpaca::weaken(Alpaca *opponent) {67while(opponent->getAttack()) // kill my enemy!68{69cloneA->decreaseAttack(opponent, 40);70delete cloneA; // save my memory.71cloneA = new superAlpaca(*cloneB); // get a new cloneA72cout << cursorUp(1) << clearLine;73cout.flush();74}75cloneA->sleep(opponent, 40);76delete cloneA; // save my memory.77cloneA = new superAlpaca(*cloneB); // get a new cloneA78cout << cursorUp(1) << clearLine;79cout.flush();80}8182void // now, I cheat. I will use all my powers as much as I want.83superAlpaca::charge(int a, int b, int c) {84cloneA->bufAlly(this,a,b,c);85delete cloneA; // save my memory.86cloneA = new superAlpaca(*cloneB); // get a new cloneA87cout << cursorUp(1) << clearLine;88cout.flush();89}909192