Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.