Skip to content

Instantly share code, notes, and snippets.

@nthx
Created October 9, 2012 01:24
Show Gist options
  • Save nthx/3856019 to your computer and use it in GitHub Desktop.
Save nthx/3856019 to your computer and use it in GitHub Desktop.
Example of a usecase + model (pure domain)
class MemoryGameUseCase
constructor: ->
@games = []
@timeLimit = 60
playerRequestsStart: =>
if @knowsHowToPlay()
@start()
else
@teachHowToPlay()
playerPicksSlot: (slot) =>
try
@tryGuessSlot(slot)
catch error
@wrongSlot(slot) #...
tryGuessSlot: (slot) =>
if @currentBoard().notYetPlayed(slot)
@currentBoard().play(slot)
@correctSlot(slot)
if @isBoardComplete()
@completedWholeBoard(@currentBoard())
playerFinishedTutorial: => #...
knowsHowToPlay: => #...
readyToStart: => #empty. aop here..
teachHowToPlay: => #empty. aop here..
start: => #...
startTimer: => #...
secondsLeft: => #...
nextSecondElapsed: => #...
generateBoard: => #...
playerGotPoints: (points) => #...
#...
class Game
constructor: (@timeLimit, @levels) ->
@boardGenerator = new BoardGenerator(@levels)
generateBoard: =>
@boardGenerator.next()
#...
class BoardGenerator
constructor: (@levels) ->
@pastBoards = []
next: =>
level = @nextBoardLevel()
pattern = @nextBoardPattern(level)
board = new BoardWithPattern(pattern, level)
@pastBoards.push board
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment