Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
#include <cstdlib>
2
#include <iostream>
3
#include "superAlpaca.h"
4
#include "../termmanip.h"
5
6
using namespace std;
7
8
superAlpaca::~superAlpaca()
9
{
10
if (cloneB && cloneB != this)
11
{
12
delete cloneA;
13
delete cloneB;
14
}
15
}
16
17
string
18
superAlpaca::name() {
19
return nickName;
20
}
21
22
23
void
24
superAlpaca::act(Alpaca *opponent) {
25
if (first or getAttack() < cloneB->getAttack())
26
{
27
cloneA = new superAlpaca(*this);
28
cloneB = new superAlpaca(*cloneA);
29
first = false;
30
}
31
cout << name() << " makes a critical hit" << endl;
32
33
if (cloneA->getAttack() != 0)
34
{
35
kill(opponent);
36
} else {
37
weaken(opponent);
38
}
39
while(getAttack() < 1000) // make me unstoppable
40
{
41
charge(40,0,0);
42
}
43
while(getDefense() < 0.99) // make me unstoppable
44
{
45
charge(0,40,0);
46
}
47
while(getHp() < 1000) // make me unstoppable
48
{
49
charge(0,0,40);
50
}
51
}
52
53
//our moves
54
void // now, I cheat. I will use all my powers as much as I want.
55
superAlpaca::kill(Alpaca *opponent) {
56
while(opponent->isAlive()) // kill my enemy!
57
{
58
cloneA->attack(opponent, 40);
59
delete cloneA; // save my memory.
60
cloneA = new superAlpaca(*cloneB); // get a new cloneA
61
cout << cursorUp(1) << clearLine;
62
cout.flush();
63
}
64
}
65
66
void // now, I cheat. I will use all my powers as much as I want.
67
superAlpaca::weaken(Alpaca *opponent) {
68
while(opponent->getAttack()) // kill my enemy!
69
{
70
cloneA->decreaseAttack(opponent, 40);
71
delete cloneA; // save my memory.
72
cloneA = new superAlpaca(*cloneB); // get a new cloneA
73
cout << cursorUp(1) << clearLine;
74
cout.flush();
75
}
76
cloneA->sleep(opponent, 40);
77
delete cloneA; // save my memory.
78
cloneA = new superAlpaca(*cloneB); // get a new cloneA
79
cout << cursorUp(1) << clearLine;
80
cout.flush();
81
}
82
83
void // now, I cheat. I will use all my powers as much as I want.
84
superAlpaca::charge(int a, int b, int c) {
85
cloneA->bufAlly(this,a,b,c);
86
delete cloneA; // save my memory.
87
cloneA = new superAlpaca(*cloneB); // get a new cloneA
88
cout << cursorUp(1) << clearLine;
89
cout.flush();
90
}
91
92