Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/controllers/MathSwipeController.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ class MathSwipeController
TrackingService.desktopView()
@cursorToPointer()
ShareGameService.setMessage()
@initialize window.location.hash, 3
@initialize()

# # Uncomment the following line to perform general tests
# GeneralTests.tests @board

initialize: (hash, length = 3) ->
initialize: ->
length = 3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #77 we determine the length from the leveler here instead of as a parameter.

solutionPlacements = []
inputLengths = []
boardValues = []
Expand Down Expand Up @@ -91,7 +92,8 @@ class MathSwipeController
@gameScene.clear()
@goalContainer.clearGoals()
ResetButton.unbindClick()
@initialize (window.location.hash = '')
HashingService.emptyHash()
@initialize()

createGameScene: ->
gameDom = document.getElementById('game')
Expand Down Expand Up @@ -125,7 +127,9 @@ class MathSwipeController
generateBoard: (inputs, length, solutionPlacements) ->
DFS.setEquationsOnGrid length, inputs, AdjacentCellsCalculator, solutionPlacements

generateInputs: (inputLengths, goals = [], inputs = []) ->
generateInputs: (inputLengths) ->
goals = []
inputs = []
for inputSize in inputLengths
value = -1
while value < 1 or value > 300
Expand Down
15 changes: 8 additions & 7 deletions app/services/HashingService.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
class HashingService

alphabet = ['"', '{', '}', '[', ']', ',', ':',
'b', 'g', 'p', '1', '2', '3', '4',
'5', '6', '7', '8', '9', '0',
'+', '-', '*']

@reloadPageWithHash: (board, solutionPlacements, SolutionService) ->
unless @checkSolutionPlacements board, solutionPlacements, SolutionService
@emptyHash()
Expand All @@ -23,9 +28,9 @@ class HashingService

btoa(JSON.stringify {b: boardValues, g: goals, p: solutionPlacements})

@decodeMap: () ->
@decodeMap: ->
try
decoded_s = atob window.location.hash.substr(1, window.location.hash.length)
decoded_s = atob window.location.hash.substr(1, window.location.hash.length)
decoded = JSON.parse decoded_s
catch e
decoded = null
Expand All @@ -47,10 +52,6 @@ class HashingService
@regexPass decoded

@regexPass: (decoded) ->
alphabet = ['"', '{', '}', '[', ']', ',', ':',
'b', 'g', 'p', '1', '2', '3', '4',
'5', '6', '7', '8', '9', '0',
'+', '-', '*']
for char in decoded
return false if char not in alphabet
true
Expand Down Expand Up @@ -122,4 +123,4 @@ class HashingService
@tempBoard.boardValues[r1][c1] = @tempBoard.boardValues[r2][c2]
@tempBoard.boardValues[r2][c2] = temp

module.exports = HashingService
module.exports = HashingService
10 changes: 2 additions & 8 deletions app/services/ShareGameService.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
$ = require 'jquery'
TwitterGameService = require './TwitterGameService'

class ShareGameService

@setMessage: ->
possible = ['Play MathSwipe with me! Try to beat my score at',
'Play MathSwipe with me! Try to solve my board at',
'Play MathSwipe with me! Solve my puzzle at']
text = possible[Math.floor(Math.random() * 3)]
$( '#tweet' ).attr( 'data-text' , text )
console.log $('#fb-share')
$( '#fb-share' ).attr( 'data-href' , window.location.hash )
TwitterGameService.setTweet()

module.exports = ShareGameService
2 changes: 1 addition & 1 deletion app/services/SolutionService.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SolutionService
@RunningSum.display @RunningSum.solutionOperatorString
false

finished: -> @solution[@solution.length - 1] not in "+-*"
finished: -> @solution[@solution.length - 1] not in '+-*'

isCompleteExpression: -> @solution.search(/-?\d+[-+\*]\d+/g) is 0

Expand Down
12 changes: 12 additions & 0 deletions app/services/TwitterGameService.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ = require 'jquery'

class TwitterGameService

@setTweet: ->
possible = ['Play MathSwipe with me! Try to beat my score at',
'Play MathSwipe with me! Try to solve my board at',
'Play MathSwipe with me! Solve my puzzle at']
text = possible[Math.floor(Math.random() * 3)]
$( '#tweet' ).attr( 'data-text' , text )

module.exports = TwitterGameService
105 changes: 63 additions & 42 deletions bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading