Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_prog / rpg / character.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Characters are playable entity in the world.
16 module character
17
18 import races
19 import careers
20
21 # Characters can be played by both the human or the machine.
22 class Character
23
24 # The `Race` of the character.
25 var race: Race
26
27 # The current `Career` of the character.
28 # Returns `null` if character is unemployed.
29 var career: nullable Career = null is writable
30
31 fun quit do
32 career = null
33 end
34
35 var name: String
36 var age: Int
37 var sex: Bool
38
39 # The actual strength of the character.
40 #
41 # Returns `race.base_strength + career.strength_bonus` or just `race.base_strength` is unemployed.
42 fun total_strengh: Int do
43 if career != null then return race.base_strength + career.strength_bonus
44 return race.base_strength
45 end
46
47 # The actual endurance of the character.
48 fun total_endurance: Int do
49 if career != null then return race.base_endurance + career.endurance_bonus
50 return race.base_endurance
51 end
52
53 # The acutal intelligence of the character.
54 fun total_intelligence: Int do
55 if career != null then return race.base_intelligence + career.intelligence_bonus
56 return race.base_intelligence
57 end
58
59 # Maximum health of the character.
60 #
61 # Based on `total endurance * 10`.
62 fun max_health: Int do return total_endurance * 10
63
64 # The current `health` of the character.
65 #
66 # Starts at `max_health`.
67 var health: Int = max_health
68 end
69