

/*****************************************************************************
 *
 *  Define the Game Object and Functions
 *
 *****************************************************************************/
function Game(theNumberOfPlayers, theNumberOfRounds)
{
    this.riskLevels = [ 0.6, 0.5, 0.4, 0.3 ];
    this.numberOfRounds = theNumberOfRounds;
    this.players = new Array();

    this.humanPlayer = new HumanPlayer("You", Math.random());

    for (var i=1; i<theNumberOfPlayers; i++)
    {
        if (skillLevel == "original")
        {
            this.players.push(new ComputerPlayer('Player ' + i, Math.random()));
        }
        else if (skillLevel == "beta")
        {
            this.players.push
            (
                new BetaComputerPlayer
                (
                    'Player ' + i,
                    this.riskLevels[Math.floor((Math.random() * 15797)) % 4]
                )
            );
        }
    }


    // insert human player in the right position
    switch (theNumberOfPlayers)
    {
        case 3:
            this.players.splice(1,0,this.humanPlayer);
            break;
        case 4:
            this.players.splice(2,0,this.humanPlayer);
            break;
        case 5:
            this.players.splice(2,0,this.humanPlayer);
            break;
    }

    this.players[0].setAnchor(50, 65, 1, 1);
    switch (this.players.length)
    {
        case 3:
            this.players[1].setAnchor(365, 325, 3, 2);
            this.players[2].setAnchor(50, 560, 2, 3);
            break;
        case 4:
            this.players[1].setAnchor(365, 65, 4, 2);
            this.players[2].setAnchor(365, 325, 3, 3);
            this.players[3].setAnchor(50, 560, 2, 4);
            break;
        case 5:
            this.players[1].setAnchor(365, 65, 4, 2);
            this.players[2].setAnchor(365, 325, 3, 3);
            this.players[3].setAnchor(365, 560, 5, 4);
            this.players[4].setAnchor(50, 560, 2, 5);
            break;
    }

}

Game.prototype.getHumanPlayer = function()
{
    return this.humanPlayer;
}

Game.prototype.getPlayers = function()
{
    return this.players;
}

Game.prototype.isGameOver = function()
{
    return (this.numberOfRounds <= 0);
}

Game.prototype.getRoundsLeftCount = function()
{
    return this.numberOfRounds;
}

Game.prototype.playNextRound = function()
{
    hideDivById('roundend');
    hideDivById('deckscore');
    if (!this.isGameOver())
    {
        this.numberOfRounds--;

        // create a new round of the game and launch it
        callback = new AsyncCallback("round.start();", this.players.length);
        round = new Round(this.players);
    }
}

