-
Notifications
You must be signed in to change notification settings - Fork 5
/
subject.txt
86 lines (64 loc) · 2.88 KB
/
subject.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Assignment name : cpp_module_02
Expected files : Warlock.cpp Warlock.hpp
ASpell.hpp ASpell.cpp
ATarget.hpp ATarget.cpp
Fwoosh.hpp Fwoosh.cpp
Dummy.hpp Dummy.cpp
Fireball.hpp Fireball.cpp
Polymorph.hpp Polymorph.cpp
BrickWall.hpp BrickWall.cpp
SpellBook.hpp SpellBook.cpp
TargetGenerator.hpp TargetGenerator.cpp
--------------------------------------------------------------------------------
In the Warlock, SpellBook and TargetGenerator classes, the switch statement is
FORBIDDEN and its use would result in a -42.
Create the following two spells, on the same model as Fwoosh:
* Fireball (Name: "Fireball", Effects: "burnt to a crisp")
* Polymorph (Name: "Polymorph", Effects: "turned into a critter")
In addition to this, just so he won't have only dummy to attack, let's make a
new target for him, which will be the BrickWall (Type: "Inconspicuous Red-brick Wall").
Now, make a SpellBook class, in canonical form, that can't be copied or instantiated
by copy. It will have the following functions:
* void learnSpell(ASpell*), that COPIES a spell in the book
* void forgetSpell(string const &), that deletes a spell from the book, except
if it isn't there
* ASpell* createSpell(string const &), that receives a string corresponding to
the name of a spell, creates it, and returns it.
Modify the Warlock, now, make it have a spell book that will be created with
him and destroyed with him. Also make his learnSpell and forgetSpell functions
call those of the spell book.
The launchSpell function will have to use the SpellBook to create the spell
it's attempting to launch.
Make a TargetGenerator class, in canonical form, and as before,
non-copyable.
It will have the following functions:
* void learnTargetType(ATarget*), teaches a target to the generator
* void forgetTargetType(string const &), that makes the generator forget a
target type if it's known
* ATarget* createTarget(string const &), that creates a target of the
specified type
Phew, that's done. Now here's a test main. It's not very thorough, so make sure
to use your own aswell.
int main()
{
Warlock richard("Richard", "foo");
richard.setTitle("Hello, I'm Richard the Warlock!");
BrickWall model1;
Polymorph* polymorph = new Polymorph();
TargetGenerator tarGen;
tarGen.learnTargetType(&model1);
richard.learnSpell(polymorph);
Fireball* fireball = new Fireball();
richard.learnSpell(fireball);
ATarget* wall = tarGen.createTarget("Inconspicuous Red-brick Wall");
richard.introduce();
richard.launchSpell("Polymorph", *wall);
richard.launchSpell("Fireball", *wall);
}
~$ ./a.out | cat -e
Richard: This looks like another boring day.$
Richard: I am Richard, Hello, I'm Richard the Warlock!!$
Inconspicuous Red-brick Wall has been turned into a critter!$
Inconspicuous Red-brick Wall has been burnt to a crisp!$
Richard: My job here is done!$
~$