public
Created

  • Download Gist
coin.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14
var Coin = Backbone.Model.extend({
defaults: {
value: 0,
image: ''
}
});
 
var Coins = Backbone.Collection.extend({
model: Coin,
 
defaults: {
player_id: 0
}
});
index.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
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;
}
 
});
player.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.