Created
October 23, 2012 00:44
-
-
Save jaypeeZero/3935931 to your computer and use it in GitHub Desktop.
This file contains 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
var Coin = Backbone.Model.extend({ | |
defaults: { | |
value: 0, | |
image: '' | |
} | |
}); | |
var Coins = Backbone.Collection.extend({ | |
model: Coin, | |
defaults: { | |
player_id: 0 | |
} | |
}); |
This file contains 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
var IndexView = Backbone.View.extend({ | |
initialize: function() { | |
this.game = new Game(); | |
this.players = this.game.get("players"); | |
this.turns = this.game.get("turns"); | |
this.Taylor = new Player({ id: 1, name: "Taylor" }); | |
this.Sugar = new Player({ id: 2, name: "Sugar" }); | |
this.Darlene = new Player({ id: 3, name: "Darlene" }); | |
this.Cody = new Player({ id: 4, name: "Cody" }); | |
this.players.add([ | |
this.Taylor, | |
this.Sugar, | |
this.Darlene, | |
this.Cody | |
]); | |
console.log(this.players.toJSON()); | |
this.Taylor.get("coins").add([ | |
{ value: 1 }, | |
{ value: 1 }, | |
{ value: 1 }, | |
{ value: 5 }, | |
{ value: 5 }, | |
{ value: 10 } | |
]); | |
this.Sugar.get("coins").add([ | |
{ value: 1 }, | |
{ value: 1 }, | |
{ value: 2 }, | |
{ value: 2 }, | |
{ value: 5 }, | |
{ value: 5 }, | |
{ value: 10 } | |
]); | |
this.Darlene.get("coins").add([ | |
{ value: 1 }, | |
{ value: 1 }, | |
{ value: 1 }, | |
{ value: 3 }, | |
{ value: 3 }, | |
{ value: 3 }, | |
{ value: 10 }, | |
{ value: 10 }, | |
{ value: 20 } | |
]); | |
this.Cody.get("coins").add([ | |
{ value: 1 }, | |
{ value: 1 }, | |
{ value: 1 }, | |
{ value: 1 }, | |
{ value: 5 }, | |
{ value: 5 }, | |
{ value: 5 }, | |
{ value: 10 }, | |
{ value: 10 }, | |
{ value: 25 } | |
]); | |
}, | |
render: function() { | |
var players_div = $("#players"); | |
_.each(this.players.models, function(player) { | |
var p_view = new PlayerView({ player: player }); | |
players_div.append(p_view.render().el); | |
}); | |
var game_div = $("#game"); | |
game_div.append(new GameView({ game: this.game }).render().el); | |
return this; | |
} | |
}); |
This file contains 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
var Player = Backbone.Model.extend({ | |
defaults: { | |
id: 0, | |
name: '', | |
coins: new Coins() | |
}, | |
initialize: function() { | |
this.get("coins").player_id = this.get("id"); | |
} | |
}); | |
var Players = Backbone.Collection.extend({ | |
model: Player | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment