Skip to content

Commit

Permalink
added start game method for #7
Browse files Browse the repository at this point in the history
  • Loading branch information
drdamour committed Jan 6, 2013
1 parent 34f1e5f commit 51355f9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
10 changes: 10 additions & 0 deletions BaronDestinatr.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@ function PlayerVM(Name, Color)
//Represents a Game
function GameVM(PlayerCount)
{
var self = this;
if(PlayerCount == null) PlayerCount = 4; //default
this.PlayerCount = ko.observable(PlayerCount);

this.Players = ko.observableArray();

this.Start = function()
{
for(var i = 0, l = self.PlayerCount();i<l; i++)
{
self.Players.push( new PlayerVM("Player " + (i+1), "Color") );
}
};
}

33 changes: 25 additions & 8 deletions Test/GameVM.Tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,33 @@ test( "constructor", function() {
deepEqual(g.Players(), []);

g = new GameVM();
equal(g.PlayerCount(), 4); //default
deepEqual(g.Players(), []);
equal(g.PlayerCount(), 4); //default
deepEqual(g.Players(), []);

g = new GameVM(3);
equal(g.PlayerCount(), 3);
deepEqual(g.Players(), []);
g = new GameVM(3);
equal(g.PlayerCount(), 3);
deepEqual(g.Players(), []);
});

//TODO: test invalid constructor params

test( "constructor invalid parameters", function() {

});
test( "Start Game", function() {
var g = new GameVM(4);
equal(g.PlayerCount(), 4);
deepEqual(g.Players(), []);

g.Start();
var players = g.Players();
equal(players.length, 4);
equal(players[0].Name(), "Player 1");
equal(players[1].Name(), "Player 2");
equal(players[2].Name(), "Player 3");
equal(players[3].Name(), "Player 4");

//TODO: add checks for new colors
equal(players[0].Color(), "Color");
equal(players[1].Color(), "Color");
equal(players[2].Color(), "Color");
equal(players[3].Color(), "Color");

});

0 comments on commit 51355f9

Please sign in to comment.