Merge branch 'explain-assert' into master
[nit.git] / src / doc / term / tests / test_term.sav / test_code.res
1 Code for `test_prog::Character`:
2
3 ~~~
4 # Characters can be played by both the human or the machine.
5 class Character
6
7         # The `Race` of the character.
8         var race: Race
9
10         # The current `Career` of the character.
11         # Returns `null` if character is unemployed.
12         var career: nullable Career = null is writable
13
14         fun quit do
15                 career = null
16         end
17
18         var name: String
19         var age: Int
20         var sex: Bool
21
22         # The actual strength of the character.
23         #
24         # Returns `race.base_strength + career.strength_bonus` or just `race.base_strength` is unemployed.
25         fun total_strengh: Int do
26                 if career != null then return race.base_strength + career.strength_bonus
27                 return race.base_strength
28         end
29
30         # The actual endurance of the character.
31         fun total_endurance: Int do
32                 if career != null then return race.base_endurance + career.endurance_bonus
33                 return race.base_endurance
34         end
35
36         # The acutal intelligence of the character.
37         fun total_intelligence: Int do
38                 if career != null then return race.base_intelligence + career.intelligence_bonus
39                 return race.base_intelligence
40         end
41
42         # Maximum health of the character.
43         #
44         # Based on `total endurance * 10`.
45         fun max_health: Int do return total_endurance * 10
46
47         # The current `health` of the character.
48         #
49         # Starts at `max_health`.
50         var health: Int = max_health
51 end
52 ~~~