Game.prototype.userCanPlay = function()

in application/game/js/alienattack.js [370:413]


Game.prototype.userCanPlay = function () {
    let canPlay = false;
    if (this.loggedin) {
        if (!this.session)
            //Playing without a session. Score will not be recorded, but player can have fun
            canPlay = true;
        else {
            switch (this.session.GameType) {
                case "MULTIPLE_TRIALS":
                    canPlay = true;
                    break;
                case "SINGLE_TRIAL":
                    if (this.userHasAlreadyPlayed()) canPlay = false;
                    else canPlay = true;
                    break;
                case "TIME_CONSTRAINED":
                    // session deadline will control if user can still play
                    canPlay = true;
                    break;
                default:
                    console.log("Unexpected value for this.session.GameType:", this.session.GameType);
                    canPlay = true;
            }
        }
        /*
        // THIS IS A TIP FOR THE FUTURE IMPLEMENTATION OF THE WEBSOCKET ENABLED VERSION OF THE GAME

        if (this.loggedin && !this.awsfacade.userHasAlreadyPlayed()) {
            var result = {};
            if (this.websocketEnabled) {
                result.WelcomeMessage = 'Wait for the game to begin'; 
                result.RespondToSpacebarPressed = false;
                return result;
            }
            else {
                result.WelcomeMessage  = "Press 'Space' to start the game"; 
                result.RespondToSpacebarPressed = true;
                return result;
            }
        } else return null;
        */
    }
    return canPlay;
}