Created
October 30, 2012 22:40
-
-
Save tonyhb/3983573 to your computer and use it in GitHub Desktop.
Game State
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Contains the game state in a protected (closure) variable | |
state : -> | |
# Our protected variable, only changeable through the setState method | |
# defined below | |
_state = 'stopped' | |
# The state method will (from the 2nd call onwards) only return the | |
# state. | |
@.state = -> | |
_state | |
# Sets the Game state to allowed members only | |
@.setState = (newState) -> | |
if ['stopped', 'playing', 'paused'].indexOf(newState) < 0 | |
throw new Error("Unknown state '" + newState.toString() + "'") | |
else | |
_state = newState | |
@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment