|
| 1 | +# Instructions |
| 2 | + |
| 3 | +This exercise takes you to the world of Troy. |
| 4 | +The lives of its people are full of wonder and magic. |
| 5 | +Many humans in Troy possess _powers_, that are used frequently in their daily lives. |
| 6 | +Powers are used to re-shape the world or influence Troy's fauna and other people. |
| 7 | +Magic also manifests in _unique artifacts_, that are highly sought after by adventurers, artisans and sages. |
| 8 | + |
| 9 | +In this exercise you are going to write code to model the humans of Troy, their possessed artifacts and power interactions. |
| 10 | + |
| 11 | +You have six tasks. |
| 12 | +The first one is related to creating a human, the other five are about handling powers and artifacts. |
| 13 | + |
| 14 | +## 1. Bring humans to the world of Troy |
| 15 | + |
| 16 | +For your model of Troy humans are the most important feature. |
| 17 | +Your model human should be able to possess a _unique artifact_. |
| 18 | +They should also have the ability to manifest a _power_. |
| 19 | +These powers might affect other humans, so you also want to model if a human is influenced by some other power. |
| 20 | + |
| 21 | +You are provided with basic implementations of `artifact` and `power` structs. |
| 22 | +Implement a `human` struct (or class) that has a _smart-pointer_ to an `artifact` as `possession` member variable. |
| 23 | +Each artifact can only be possessed by a single human at any given time. |
| 24 | + |
| 25 | +The `human` should also have variables for their `own_power` and `influenced_by`, which should be _smart-pointers_ to `powers`. |
| 26 | +Each `power` might be owned by a single human, but also influence other humans at the same time. |
| 27 | + |
| 28 | +By default, humans are born without any artifact and neither own any powers nor are they influenced by them. |
| 29 | + |
| 30 | +```cpp |
| 31 | +human mindy_mccready{}; |
| 32 | +mindy_mccready.possession; |
| 33 | +// => nullptr |
| 34 | +mindy_mccready.own_power; |
| 35 | +// => nullptr |
| 36 | +mindy_mccready.influenced_by; |
| 37 | +// => nullptr |
| 38 | +``` |
| 39 | + |
| 40 | +## 2. Bring Artifacts into Troy |
| 41 | + |
| 42 | +Your model is boring without the interaction of its parts. |
| 43 | +You want to create unique artifacts and give them to certain humans. |
| 44 | + |
| 45 | +Define the function `give_new_artifact` which returns nothing but takes a `human` and a `string`. |
| 46 | +With the `string` it should define a new `artifact` object and set the `possession` pointer of the `human` accordingly. |
| 47 | +The function should not return anything. |
| 48 | + |
| 49 | +```cpp |
| 50 | +human erik_magnus_lehnsherr{}; |
| 51 | +give_new_artifact(erik_magnus_lehnsherr, "Mind shielding helmet"); |
| 52 | + |
| 53 | +erik_magnus_lehnsherr.possession->name; |
| 54 | +// "Mind shielding helmet" |
| 55 | +``` |
| 56 | +
|
| 57 | +## 3. Make items tradeable |
| 58 | +
|
| 59 | +The world of Troy is all about interaction. |
| 60 | +You want people to make trades by exchanging their possessions. |
| 61 | +
|
| 62 | +Write a function `exchange_artifacts` that returns nothing but takes two artifact smart-pointers to exchange the items. |
| 63 | +
|
| 64 | +```cpp |
| 65 | +human uchiha{}; |
| 66 | +give_new_artifact(uchiha, "konoha headband"); |
| 67 | +human uzumaki{}; |
| 68 | +give_new_artifact(uzumaki, "forehead protector"); |
| 69 | +
|
| 70 | +exchange_artifacts(uchiha.possession, uzumaki.possession); |
| 71 | +
|
| 72 | +uchiha.possession->name; |
| 73 | +// "forehead protector" |
| 74 | +uzumaki.possession->name; |
| 75 | +// "konoha headband" |
| 76 | +``` |
| 77 | + |
| 78 | +## 4. Give Power to the People |
| 79 | + |
| 80 | +The most exiting feature of Troy are the special powers, that people might wield. |
| 81 | +Some can smelt iron with their thoughts, while others can heal every wound instantly at nighttime. |
| 82 | + |
| 83 | +Define the function `manifest_power` which returns nothing but takes a `human` and a `string`. |
| 84 | +With the `string` it should define a new `power` object and set the `own_power` pointer of the `human` accordingly. |
| 85 | +The function should not return anything. |
| 86 | + |
| 87 | +```cpp |
| 88 | +human eleven {}; |
| 89 | +manifest_power(eleven, "psychokinesis"); |
| 90 | + |
| 91 | +eleven.own_power->effect; |
| 92 | +// "psychokinesis" |
| 93 | +``` |
| 94 | +
|
| 95 | +## 5. Use the Power |
| 96 | +
|
| 97 | +What use are the greatest powers, if you cannot use them. |
| 98 | +Your model concentrates on humans, so you want to track the influence of powers. |
| 99 | +
|
| 100 | +Write a _void_ function `use_power` that takes two humans, first: a caster and secondly: a target. |
| 101 | +The target's `influenced_by` pointer should be pointed to the power of the caster. |
| 102 | +
|
| 103 | +For simplicity, humans can only be influenced by a single power and this power stays in place even if the caster does not exist any longer. |
| 104 | +
|
| 105 | +```cpp |
| 106 | +human pamela_isley{}; |
| 107 | +manifest_power(pamela_isley, "control pheromones"); |
| 108 | +
|
| 109 | +human count_vertigo{}; |
| 110 | +use_power(pamela_isley, count_vertigo); |
| 111 | +count_vertigo.influenced_by->effect; |
| 112 | +// "control pheromones" |
| 113 | +``` |
| 114 | + |
| 115 | +## 6. Keep watch on the power's intensity |
| 116 | + |
| 117 | +Certain powers lose their potency or trigger certain effects in your simulation when they are applied to several humans. |
| 118 | +You want to track the number of people who are connected to each power. |
| 119 | + |
| 120 | +Define the function `power_intensity`, that takes a human and returns the intensity of their power as an _int_. |
| 121 | +If the person has no power, the return value should be `0`. |
| 122 | +Otherwise the intensity should reflect the caster and all currently influenced people. |
| 123 | + |
| 124 | +```cpp |
| 125 | +human jean_grey{}; |
| 126 | +manifest_power(jean_grey, "uplifting personality"); |
| 127 | + |
| 128 | +human scott{}; |
| 129 | +human logan{}; |
| 130 | +human ororo{}; |
| 131 | + |
| 132 | +use_power(jean_grey, ororo); |
| 133 | +use_power(jean_grey, logan); |
| 134 | +use_power(jean_grey, scott); |
| 135 | + |
| 136 | +power_intensity(jean_grey); |
| 137 | +// 4 |
| 138 | +``` |
0 commit comments