| title |
Roll Checks, Reward and Punishment |
| actions |
|
| material |
| editor |
| language |
startingCode |
answer |
c# |
private static Alien Reward (Alien a) {
uint attribute = // random number between 0-2 (use D6)
uint value = // random number between 0-9
switch (attribute) {
case 0:
a.Xna += value * 10000;
OnRewarded ("strength", value);
break;
case 1:
// Increment the correct digits in Xna
// Invoke the event method
break;
case 2:
// Increment the correct digits in Xna
// Invoke the event method
break;
default:
break;
}
// return the modified Alien object
}
private static Alien Punish (Alien a) {
// Implement similar to Reward ()
}
private static Alien Check (Alien a, int modifier) {
// Implement (3) here
}
|
private static Alien Reward (Alien a) {
uint attribute = D6 () / 2;
uint value = D10 ();
switch (attribute) {
case 0:
a.Xna += value * 10000;
OnRewarded ("strength", value);
break;
case 1:
a.Xna += value * 100;
OnRewarded ("speed", value);
break;
case 2:
a.Xna += value;
OnRewarded ("weight", value);
break;
default:
break;
}
return a;
}
private static Alien Punish (Alien a) {
uint attribute = D6 () / 2;
uint value = D10 ();
switch (attribute) {
case 0:
a.Xna -= value * 10000;
OnPunished ("strength", value);
break;
case 1:
a.Xna -= value * 100;
OnPunished ("speed", value);
break;
case 2:
a.Xna -= value;
OnPunished ("weight", value);
break;
default:
break;
}
return a;
}
private static Alien Check (Alien a, int modifier) {
if (modifier + D100 () > 99)
return Reward (a);
else
return Punish (a);
}
|
|
|
The goal in this chapter is to implement a reward/punish mechanism for Aliens. When an Alien is rewarded/punished, an attribute of the Alien is increased/decreased by a random number.
We will also implement a roll-to-check system, where a dice is rolled between 0-99, and the number combined with a modifier will determine the success of an action.
-
Complete the Reward () method
-
Implement Punish () in the same way as Reward ()
-
In Check (), use an if statement to check if the modifier combined with a D100 roll crosses the threshold of (greater than) 99. Return a Reward () or Punish () call depending on the result.