Skip to content

Instantly share code, notes, and snippets.

@jszmajda
Created September 18, 2011 15:03
Show Gist options
  • Select an option

  • Save jszmajda/1225144 to your computer and use it in GitHub Desktop.

Select an option

Save jszmajda/1225144 to your computer and use it in GitHub Desktop.
Game of Life in Backbone Design

Model: Cell {x, y, alive} View: CellView {model: Cell} Collection: Cells


CellView renders a div CellView listens to Cell.change to change b.g. color

On app init:

  1. Create cells 50x50
  2. Create CellView for each cell
  3. Add cells to Collection
  4. Iterate over collection to compute alive/dead.
    • 2-step "prepare" -> "change"
    • two methods:
      • compute next-state:
        • set next_turn_alive should be alive or not
      • make transition
        • do the actual bg-color/state cleanup/etc
    • pass over them twiec: first compute next state, second call make transition
    • should event change:alive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment