Created
December 6, 2011 01:43
-
-
Save ccapndave/1436310 to your computer and use it in GitHub Desktop.
Tictactoe SC2
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
App = SC.Application.create() | |
### Model ### | |
class App.Game extends SC.Object | |
@createNewGame: -> | |
game = App.Game.create( { cells: [] } ) | |
for x in [0...3] | |
for y in [0...3] | |
game.get("cells").pushObject App.Cell.create { x, y } | |
game | |
class App.Cell extends SC.Object | |
### Controller ### | |
### View ### | |
App.HeaderView = SC.View.extend | |
headerText: "Hello" | |
### | |
App.BoardView = SC.ContainerView.extend | |
classNames: "board" | |
init: -> | |
@_super() | |
for cell in App.currentGame.cells | |
cellView = App.CellView.create( { content: cell } ) | |
@get("childViews").push @createChildView(cellView) | |
### | |
App.BoardView = SC.CollectionView.extend | |
contentBinding: "App.currentGame.cells" | |
exampleView: App.CellView | |
App.CellView = SC.View.extend | |
classNames: "cell".w() | |
classNameBindings: [ "horizontalClass", "verticalClass" ] | |
horizontalClass: (-> | |
switch @content.get("x") | |
when 0 then "left" | |
when 1 then "middle" | |
when 2 then "right" | |
).property("content") | |
verticalClass: (-> | |
switch @content.get("y") | |
when 0 then "top" | |
when 1 then "middle" | |
when 2 then "bottom" | |
).property("content") | |
### Initialize ### | |
App.currentGame = App.Game.createNewGame() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment