dino: make code base more redefable
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 8 Apr 2014 19:53:11 +0000 (15:53 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 23 May 2014 17:48:33 +0000 (13:48 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/mnit_dino/src/dino.nit
examples/mnit_dino/src/game_logic.nit

index 8fc0d7e..684146d 100644 (file)
@@ -112,6 +112,6 @@ class DinoApp
        end
 end
 
-var app = new DinoApp
-app.main_loop
+fun app: DinoApp do return once new DinoApp
 
+app.main_loop
index 08f790a..1db0880 100644 (file)
@@ -267,6 +267,7 @@ class Caveman
 
        fun is_afraid( turn : Turn ) : Bool do return turn.nbr < afraid_until
        fun can_throw( turn : Turn ) : Bool do return cannot_throw_until < turn.nbr
+       fun die(turn: Turn) do is_alive = false
 
        redef fun do_turn( t )
        do
@@ -274,7 +275,7 @@ class Caveman
                        var dwd = squared_dist_with_dino( t.game )
 
                        if dwd < run_over_distance then
-                               if t.game.dino.is_alive then is_alive = false
+                               if t.game.dino.is_alive then die(t)
                                return
                        else if is_afraid( t ) then
                                # going to destination