| title | Dices and Getting Alien Attributes | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| actions |
|
||||||||
| material |
|
To lay the groundwork of game mechanics, we want to implement some methods that will come in handy later. The goal is to have D6 (), D10 (), D100 () methods that behave similarly to 6-soded, 10-sided and 100-sided dices of the same name.
- D6 returns a random
uintbetween 0 and 5. - D10 returns a random
uintbetween 0 and 9. - D100 returns a random
uintbetween 0 and 99. - DN(n) returns a
BigIntegerbetween 1 and n. This method will be used to randomly select an alien id.
Additionally, getStrength (), getSpeed, getWeight should return the corresponding two digits in the xna. Recall from Lesson1 that an xna has 8 digits. The 3 attributes are: Strength(digits 3-4), Speed(digits 5-6), and Weight(digits 7-8).
One thing to note is the return type of these methods. For example, since RandomNumber () returns a ulong, an explicit casting is required for methods with a return type of uint.
- Implement
D6 (),D10 (),D100 ()such that they return a number between 0 and n-1. Apply casting when appropriate. - Implement
DN (BigInteger n)such that they return a number between 1 and n. - Implement
getStrength (),getSpeed (),getWeight ()using%and/.