     @g = @ctx.g @tileBackground
     @g.transform "translate(#{@x * @size}, #{@y * @size})"
 
-    @g.mouseover () =>
-      if game.state isnt game.states.GameOver
-        @tileBackground.attr fill: '#ccc'
-
-    @g.mouseout () =>
-      if game.state isnt game.states.GameOver
-        @tileBackground.attr fill: '#ddd'
-
-    @g.mouseup (evt) =>
-      return if game.state is game.states.GameOver
-      if game.state is game.states.Empty
-        game.initGame @x, @y
-
-      if evt.button is 2 # Right click
-        casePosition = game.positionFromCoord @x, @y
-        game.board.cases[casePosition].g.remove()
-        if game.board.cases[casePosition].constructor is Flag
-          game.board.flagsLbl.attr text: --game.flags
-          game.board.cases[casePosition] = new Case @ctx, @x, @y
-        else
-          game.board.flagsLbl.attr text: ++game.flags
-          game.board.cases[casePosition] = new Flag @ctx, @x, @y
+    @g.mouseover @mouseOverHandler
+    @g.mouseout @mouseOutHandler
+    @g.mouseup @mouseUpHandler
+
+
+  mouseOverHandler: (evt) =>
+    if game.state isnt game.states.GameOver
+      @tileBackground.attr fill: '#ccc'
+
+
+  mouseOutHandler: (evt) =>
+    if game.state isnt game.states.GameOver
+      @tileBackground.attr fill: '#ddd'
+
+
+  mouseUpHandler: (evt) =>
+    return if game.state is game.states.GameOver
+    if game.state is game.states.Empty
+      game.initGame @x, @y
+
+    if evt.button is 2 # Right click
+      casePosition = game.positionFromCoord @x, @y
+      game.board.cases[casePosition].g.remove()
+      if game.board.cases[casePosition].constructor is Flag
+        game.board.flagsLbl.attr text: --game.flags
+        game.board.cases[casePosition] = new Case @ctx, @x, @y
       else
-        @showCase()
+        game.board.flagsLbl.attr text: ++game.flags
+        game.board.cases[casePosition] = new Flag @ctx, @x, @y
+    else
+      @showCase()
+
 
   showCase: () ->
     casePosition = game.positionFromCoord @x, @y

  initGame: (x, y) ->
    @state = @states.Playing
    @generateBoard x, y

  rnd: (min, max) ->
    return Math.floor(Math.random() * (max - min + 1)) + min

    if nbMinesAround is 0
      for [x, y] in game.neighborCoord @x, @y
        game.board.cases[game.positionFromCoord(x, y)].showCase()


  countMines: () ->
    nbMines = 0
