Permalink
Browse files

Refactor Move to adhere to OCP and LSP

OCP is Open/Closed Principle
LSP is Liskov substitution principle
  • Loading branch information...
marcinbunsch committed Oct 21, 2014
1 parent b6075cf commit 512cb98d1a26d24e2d7be294c99c882f39f3c20e
Showing with 24 additions and 15 deletions.
  1. +1 −1 app/dot.coffee
  2. +1 −14 app/move.coffee
  3. +22 −0 app/move_with_squares.coffee
View
@@ -1,6 +1,6 @@
Colors = require('colors')
Entity = require('entity')
Move = require('move')
Move = require('move_with_squares')
class Dot extends Entity
View
@@ -12,25 +12,11 @@ class Move
complete: =>
Crafty.removeEvent this, Crafty.stage.elem, "mouseup", this.complete
if this.squarePresent()
this.addAllSameColoredDots()
this.destroyDots()
this.destroyAllLines()
this.updateGameState()
this.dispose()
squarePresent: =>
groupedDots = this.getGroupedDots()
for id, dots of groupedDots
return true if dots.length > 1
return false
addAllSameColoredDots: =>
uniqueDots = this.getUniqueDots()
@game.dots.forEach (dot) =>
if dot.color == @color and !uniqueDots[dot.id]
@dots.push(dot)
updateGameState: =>
if @dots.length > 1
dotCount = this.getUniqueDotCount()
@@ -174,3 +160,4 @@ class Move
@dots.push(dot)
module.exports = Move
@@ -0,0 +1,22 @@
Move = require('move')
class MoveWithSquares extends Move
complete: =>
if this.squarePresent()
this.addAllSameColoredDots()
super()
squarePresent: =>
groupedDots = this.getGroupedDots()
for id, dots of groupedDots
return true if dots.length > 1
return false
addAllSameColoredDots: =>
uniqueDots = this.getUniqueDots()
@game.dots.forEach (dot) =>
if dot.color == @color and !uniqueDots[dot.id]
@dots.push(dot)
module.exports = MoveWithSquares

0 comments on commit 512cb98

Please sign in to comment.