Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add block matching algorithm.

  • Loading branch information...
commit 4de1bcd2323442dd5d793de15c7bc63f33b2ea39 1 parent 2acde69
@jimmycuadra authored
View
20 source/javascripts/application.js.coffee
@@ -16,6 +16,7 @@ class ph.Application
@setUpGrid(rowCount, columnCount)
@setUpSounds()
@setUpHUD()
+ @on("push", @markMatches)
$("#loading").remove()
setUpGrid: (rowCount, columnCount) ->
@@ -55,6 +56,25 @@ class ph.Application
upperNeighbors[j] = new ph.Cell(upperNeighbor: upperNeighbor)
new ph.CellRow(collection)
+ markMatches: ->
+ marked = []
+
+ for row, rowIndex in @grid.rows[0..@grid.rows.length - 3]
+ for cell, columnIndex in row.models
+ tempMarked = [cell]
+ color = cell.get("color")
+ i = 1
+ nextCell = @grid.rows[rowIndex + i].at(columnIndex)
+ while nextCell.get("color") is color
+ tempMarked.push(nextCell)
+ i++
+ nextCell = @grid.rows[rowIndex + i].at(columnIndex)
+ if tempMarked.length >= 3
+ marked.push.apply(marked, tempMarked)
+
+ _.each marked, (cell) ->
+ cell.trigger("clear")
+
_.extend(ph.Application.prototype, Backbone.Events)
$ ->
View
5 source/javascripts/models/cell.js.coffee
@@ -8,3 +8,8 @@ class ph.Cell extends Backbone.Model
colors = _.difference(colors, [upperNeighbor.get("color")])
index = Math.floor(Math.random() * colors.length)
@set("color", colors[index])
+
+ @on("clear", @clear)
+
+ clear: =>
+ @set("color", null)
View
1  source/javascripts/views/cell_row_view.js.coffee
@@ -26,3 +26,4 @@ class ph.CellRowView extends Backbone.View
nextColor = cell.get("color")
cell.set("color", newColor)
ph.app.sfx.trigger("play", "push") if ph.app.store.get("playSoundEffects")
+ ph.app.trigger("push")
Please sign in to comment.
Something went wrong with that request. Please try again.