examples/moles: extract selection of what appears in holes
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 9 Aug 2015 14:59:43 +0000 (10:59 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 12 Aug 2015 18:42:12 +0000 (14:42 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/mnit_moles/src/moles.nit

index 8dab237..078d1b4 100644 (file)
@@ -59,21 +59,24 @@ class Hole
                                self.content = null
                        end
                else if (100.0*game.speed_modifier).to_i.rand == 0 then
-                       # shot traps only at 50 points and up
-                       var trap = false
-                       if game.points > 50 then
+                       self.content = to_pop
+               end
+       end
 
-                               # After 50 points we have more and more traps until point 1000
-                               var d = 1250-(game.points - 50)
-                               if d < 200 then d = 200
+       # Get next `HoleContent` to pop
+       fun to_pop: HoleContent
+       do
+               # show traps only at 10 points and up
+               if game.points > 10 then
 
-                               if d.rand < 100 then trap = true
-                       end
+                       # After 50 points we have more and more traps until point 1000
+                       var d = 1250-(game.points - 50)
+                       if d < 200 then d = 200
 
-                       if trap then
-                               self.content = game.trap
-                       else self.content = game.up
+                       if d.rand < 100 then return game.trap
                end
+
+               return game.up
        end
 
        # Does this hole intercepts `event`?