Skip to content

Commit 0e622e6

Browse files
committed
Fix merge conflict and add bundle.js
2 parents ecb9580 + 6aefe98 commit 0e622e6

10 files changed

+458
-353
lines changed

app/controllers/MathSwipeController.coffee

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ class MathSwipeController
6060
@goalContainer, @isMobile().any()?, Cell,
6161
Colors, ClickHandler, SolutionService,
6262
BoardSolvedService, RunningSum
63-
ResetButton.bindClick @board
63+
64+
ResetButton.bindClick @board, RunningSum
65+
RunningSum.empty()
6466
@createNewGame() unless ShareGameService.reloadPageWithHash(@board,
6567
solutionPlacements, SolutionService)
6668

app/services/ClickHandler.coffee

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ class ClickHandler
1717
@checkForSolution()
1818
@unselectAll()
1919
if @BoardSolvedService.isCleared @board
20-
TrackingService.boardEvent 'solved'
21-
@board.successAnimation()
20+
TrackingService.boardEvent 'solved'
21+
@board.successAnimation()
22+
else if @goalContainer.isEmpty()
23+
@RunningSum.display @RunningSum.tilesEmptyString
2224
@mouseDown = false
2325

2426
isMouseDown: ->
@@ -72,15 +74,15 @@ class ClickHandler
7274
false
7375

7476
unselectAll: ->
75-
@RunningSum.display ''
77+
unless @RunningSum.runningSumElem.html() is @RunningSum.solutionOperatorString
78+
@RunningSum.display @RunningSum.emptyString
7679
return if @clicked.length < 1
7780
for i in [@clicked.length - 1..0]
7881
@clicked[i].unselect()
7982
@clicked = []
8083

8184
checkForSolution: () ->
8285
if @solutionService.isSolution()
83-
@RunningSum.display ''
8486
@goalContainer.deleteGoal @solutionService.valueIndex
8587
@board.deleteCells @clickedToTuples()
8688
return true

app/services/ResetButton.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ $ = require 'jquery'
22

33
class ResetButton
44

5-
@bindClick: (board) ->
5+
@bindClick: (board, RunningSum) ->
66
$('#reset-button').click (e) =>
77
board.resetBoard()
8+
RunningSum.empty()
89

910
@unbindClick: ->
1011
$('#reset-button').unbind('click')

app/services/RunningSum.coffee

+23-9
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@ $ = require 'jquery'
22

33
class RunningSum
44

5+
@runningSumElem = $( '#running-sum' )
6+
7+
@tilesEmptyString = 'Try to get all the tiles off the board!'
8+
@solutionOperatorString = 'Solution must include an operator'
9+
@invalidString = 'Invalid Expression'
10+
@emptyString = ''
11+
512
@display: (solution, value) ->
6-
if solution is ''
7-
expression = ''
8-
else if isNaN value
9-
expression = 'Invalid Expression'
10-
else if @isCompleteExpression solution
11-
expression = (@addParens solution) + '=' + value
12-
else
13-
expression = solution
14-
$('#running-sum').html(@format expression)
13+
unless @runningSumElem.html() is @tilesEmptyString
14+
if @isSpecialString solution
15+
expression = solution
16+
else if isNaN value
17+
expression = @invalidString
18+
else if @isCompleteExpression solution
19+
expression = (@addParens solution) + '=' + value
20+
else
21+
expression = solution
22+
@runningSumElem.html(@format expression)
23+
24+
@isSpecialString: (solution) ->
25+
strings = [@emptyString, @tilesEmptyString, @solutionOperatorString]
26+
strings.indexOf(solution) isnt -1
1527

1628
@isCompleteExpression: (solution) ->
1729
return solution.search(/-?\d+[-+\*]\d+/g) is 0
@@ -33,4 +45,6 @@ class RunningSum
3345
@format: (input) ->
3446
input.replace(/\*/g, ' &times; ').replace(/\+/g, ' + ').replace(/(\d+|\))-/g, '$1 - ').replace(/\=/g, ' = ')
3547

48+
@empty: -> @runningSumElem.html @emptyString
49+
3650
module.exports = RunningSum

app/services/SolutionService.coffee

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@ InputSolver = require './InputSolver'
22

33
class SolutionService
44

5-
constructor: (@board, goals) ->
5+
constructor: (@board, goals, @RunningSum) ->
66
@goals = []
7-
for g in goals
8-
@goals.push g
7+
@goals.push g for g in goals
98

109
initialize: (clickedCells) ->
1110
@setSolutionString clickedCells
1211
@value = InputSolver.compute @solution
1312

1413
isSolution: ->
15-
return false unless @solution?.length >= 3
14+
return false unless @solution?
1615
return false if @solution[@solution.length - 1] is '+' or
1716
@solution[@solution.length - 1] is '-' or
1817
@solution[@solution.length - 1] is '*'
1918
return false unless @value in @goals
19+
if not @isCompleteExpression()
20+
@RunningSum.display @RunningSum.solutionOperatorString
21+
return false
2022
@valueIndex = @goals.indexOf @value
2123
@goals[@valueIndex] = ' '
22-
return true
24+
true
25+
26+
isCompleteExpression: -> @solution.search(/-?\d+[-+\*]\d+/g) is 0
2327

2428
setSolutionString: (cells) ->
2529
@solution = ''

app/views/Board.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Board
99
@initializer()
1010

1111
initializer: =>
12-
solutionService = new @SolutionService this, @goals
12+
solutionService = new @SolutionService this, @goals, @RunningSum
1313
@clickHandler = new @ClickHandler this, solutionService, @goalContainer, @isMobile, @BoardSolvedService, @RunningSum
1414

1515
@createBoard()

app/views/Board.js

-211
This file was deleted.

app/views/Colors.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Colors =
66
board: '#294248'
77
select: '#c7a579'
88
symbol: 'black'
9-
deletedGoalGrey: '#2F4F4F'
9+
deletedGoalGrey: 'rgb(47, 79, 79)'
1010

1111
module.exports = Colors

app/views/GoalContainer.coffee

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ class GoalContainer
1616
clearGoals: ->
1717
@container.empty()
1818

19+
isEmpty: ->
20+
for goal in $(@container.children())
21+
return false if $(goal).css('color') isnt @Colors.deletedGoalGrey
22+
true
23+
1924
module.exports = GoalContainer

0 commit comments

Comments
 (0)