Permalink
Browse files

Add scoring to block matching.

  • Loading branch information...
1 parent 4de1bcd commit 4e798d67c73d6bdd51aa326a3d1e3e8fb675a3c3 @jimmycuadra committed Nov 18, 2012
@@ -57,6 +57,7 @@ class ph.Application
new ph.CellRow(collection)
markMatches: ->
+ score = 0
marked = []
for row, rowIndex in @grid.rows[0..@grid.rows.length - 3]
@@ -71,6 +72,9 @@ class ph.Application
nextCell = @grid.rows[rowIndex + i].at(columnIndex)
if tempMarked.length >= 3
marked.push.apply(marked, tempMarked)
+ score += 3 + (tempMarked.length - 3) * 2
+
+ @store.set("score", @store.get("score") + score)
_.each marked, (cell) ->
cell.trigger("clear")
@@ -7,13 +7,21 @@ class ph.Store extends Backbone.Model
playSoundEffects: true
initialize: ->
- @set(currentTime: 0)
- @set(gamesPlayed: @get("gamesPlayed") + 1)
+ @set
+ score: 0
+ currentTime: 0
+ gamesPlayed: @get("gamesPlayed") + 1
+
+ @on("change:score", @checkHighScore, this)
@on("change", @persist, this)
+
@timer = new Timer
@timer.every(1, @addTick)
@timer.start()
+ checkHighScore: (store, newScore) ->
+ @set("highScore", newScore) if newScore > @get("highScore")
+
persist: (store) ->
amplify.store("pushing-hands", @toJSON())
@@ -26,7 +34,12 @@ class ph.Store extends Backbone.Model
resetStats: ->
if confirm "Are you sure you want to permanently reset your stats?"
@timer.reset()
- @set(highScore: 0, gamesPlayed: 1, currentTime: 0, totalTime: 0)
+ @set
+ score: 0
+ highScore: 0
+ currentTime: 0
+ totalTime: 0
+ gamesPlayed: 1
@timer.start()
addTick: =>
@@ -8,7 +8,7 @@
%th Elapsed time
%tbody
%tr
- %td 0
+ %td= @score
%td 0
%td= @formatTime(@currentTime)
%h4 All time
@@ -21,7 +21,7 @@
%th Games played
%tbody
%tr
- %td 0
+ %td= @highScore
%td 0
%td= @formatTime(@totalTime)
%td= @gamesPlayed

0 comments on commit 4e798d6

Please sign in to comment.