Skip to content

Instantly share code, notes, and snippets.

@jaypeeZero
Created October 23, 2012 00:44
Show Gist options
  • Save jaypeeZero/3935931 to your computer and use it in GitHub Desktop.
Save jaypeeZero/3935931 to your computer and use it in GitHub Desktop.
var Coin = Backbone.Model.extend({
defaults: {
value: 0,
image: ''
}
});
var Coins = Backbone.Collection.extend({
model: Coin,
defaults: {
player_id: 0
}
});
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;
}
});
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