Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_prog / rpg / combat.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 # COmbat interactions between characters.
16 module combat
17
18 import character
19
20 # Something that can be used to attack someone and inflict damage.
21 interface Weapon
22 # Damage per second inflicted by this weapon.
23 fun dps: Float is abstract
24 end
25
26 # Something that can be combatted, it can `attack` and `defend`.
27 #
28 # World items can also be `Combatable`.
29 # `defend` method is then used to determines how the object react to an attack
30 # Some magical items can even `attack`.
31 interface Combatable
32 fun hit_points: Int is abstract
33
34 # A `Combatable` can attack a `target` that is also a `Combatable`.
35 #
36 # Attack the `target` using `wepaon` and returns the number of inflicted hit points.
37 fun attack(target: Combatable, weapon: Weapon): Int is abstract
38
39 # Like `attack` but cannot be defended.
40 fun direct_attack(target: Combatable, weapon: Weapon): Int is abstract
41
42 # `Combatable` can defend against attacks.
43 #
44 # Defends against a number of received hit points and return the number of pared hit points.
45 #
46 # @param hit: damage received.
47 fun defend(hit: Int): Int is abstract
48
49 # Is the character still have hit_points?
50 fun is_dead: Bool do return hit_points > 0
51 end
52
53 # Characters are now `Comabatable`
54 redef class Character
55 super Combatable
56
57 # Use character `health` to determines hit_points.
58 redef fun hit_points do return health
59 end
60
61 # Dwarves can be used as weapons.
62 redef class Dwarf
63 super Weapon
64
65 # Dwarf `dps` are based on the dwarf `base_endurance` (represents weight here)
66 redef fun dps do return base_endurance.to_f / 10.0
67 end