{"size": 837, "ext": "js", "max_stars_repo_path": "tennis-js/Game.js", "max_stars_repo_name": "Johjo/coding-dojo", "max_stars_repo_stars_event_min_datetime": "2019-09-19T14:50:57.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T14:50:57.000Z", "max_issues_repo_path": "tennis-js/Game.js", "max_issues_repo_name": "Johjo/coding-dojo", "max_issues_repo_issues_event_min_datetime": "2020-10-02T11:32:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-02T11:32:47.000Z", "max_forks_repo_path": "tennis-js/Game.js", "max_forks_repo_name": "Johjo/coding-dojo", "max_forks_repo_forks_event_min_datetime": "2019-06-14T07:03:47.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-20T04:54:40.000Z"}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": 2, "avg_line_length": 20.925, "max_line_length": 105, "alphanum_fraction": 0.5555555556}
const Player = require('./Player');

const Scores = [0, 15, 30, 40, "ADV"];


class Game {
    constructor() {
        this._players = [new Player(), new Player()];
    }

    playerWinPoint(player) {
        this._players[player - 1].playerWinPoint()
    }

    playerWin(playerId) {
        var opponentId = playerId === 1 ? 2 : 1
        if (this._players[playerId - 1].getPoint() >= 4) {
            if (this._players[playerId - 1].getPoint() - this._players[opponentId - 1].getPoint() >= 2) {
                return true;
            }
        }
        return false;
    }

    getJoueur1() {
        return humanizePoint(this._players[0].getPoint());
    }

    getJoueur2() {
        return humanizePoint(this._players[1].getPoint());
    }

}

function humanizePoint(point) {
    return Scores[point];
}

module.exports = Game;
