Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Refactor Move to adhere to OCP and LSP
OCP is Open/Closed Principle LSP is Liskov substitution principle
- Loading branch information
1 parent
b6075cf
commit 512cb98d1a26d24e2d7be294c99c882f39f3c20e
Showing
3 changed files
with
24 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |