Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bw hash edits v2 #82

Open
wants to merge 12 commits into
base: ec-hash-edits
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

[MathSwipe](http://sf-interns.github.io/mathswipe/) is a `CoffeeScript` game developed in the context of the [Originate](http://www.originate.com/) 'Intern Hack 2015' Event, presented August 2015. It is a web-game in which the user is given a grid of numbers (0-9) and operators (+, -, ×). The user's goal is to swipe a path through the cells to create an expression that evaluates to one of the goal-values listed below the board. A level is completed when the user finds expressions evaluating to each goal-value and has cleared the board of all cells.

Math Swipe is a simple brain game that is rooted in math. From children to their parents, Math Swipe is simple yet challenging enough to stump even the strongest math wizzes.

## Development Information

Note that the other services, when run locally, expect the frontend to be served on port 8080.

The codebase is primarily written in CoffeeScript using the Node package manager to install most of the dependencies. The entire project (including its dependencies) is bundled by `Webpack` into a single bundle.js file which can be served locally or staticlly with GitHub pages.

Animation and functionality of the game is implemented using `jQuery`, `Two.js` and Scalable Vector Graphics (SVGs).
Animation and functionality of the game is implemented using `jQuery`, `Two.js` and Scalable Vector Graphics (SVGs).

The styling is written in `SASS` and compiled down to CSS before use. If you plan to clone this repository and try building the game locally, we recommend using the Sublime plugin `SASS Build` to compile down to CSS.

Expand Down
13 changes: 9 additions & 4 deletions app/controllers/MathSwipeController.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ GeneralTests = require '../../tests/controllers/GeneralTests'
class MathSwipeController

constructor: ->
length = 3
@gameScene = @createGameScene()
@symbols = @getSymbols()
@bindNewGameButton()
Expand All @@ -34,12 +35,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 +93,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 +128,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
107 changes: 65 additions & 42 deletions bundle.js

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

Loading