nodegame-openshift
Version:
Prepares a nodeGame instance to run on the openshift cloud.
111 lines (92 loc) • 3.46 kB
JavaScript
/**
* # Logic code for Ultimatum Game
* Copyright(c) 2016 Stefano Balietti
* MIT Licensed
*
* Handles bidding, and responds between two players.
*
* http://www.nodegame.org
*/
var ngc = require('nodegame-client');
var stepRules = ngc.stepRules;
var J = ngc.JSUS;
// Variable registered outside of the export function
// are shared among all instances of game logics.
var counter = 0;
// Flag to not cache required files.
var nocache = true;
// Here we export the logic function. Receives three parameters:
// - node: the NodeGameClient object.
// - channel: the ServerChannel object in which this logic will be running.
// - gameRoom: the GameRoom object in which this logic will be running.
module.exports = function(treatmentName, settings, stager, setup, gameRoom) {
var channel = gameRoom.channel;
var node = gameRoom.node;
var timers = settings.TIMER;
// Increment counter.
counter = counter ? ++counter : settings.SESSION_ID;
// Import other functions used in the game.
// Some objects are shared.
var cbs = channel.require(__dirname + '/includes/logic.callbacks.js', {
node: node,
gameRoom: gameRoom,
settings: settings,
counter: counter
// Reference to channel added by default.
}, nocache);
// Event handler registered in the init function are always valid.
stager.setOnInit(cbs.init);
// Event handler registered in the init function are always valid.
stager.setOnGameOver(cbs.gameover);
// `minPlayers` triggers the execution of a callback in the case
// the number of players (including this client) falls the below
// the chosen threshold. Related: `maxPlayers`, and `exactPlayers`.
// However, the server must be configured to send this information
// to the clients, otherwise the count will be always 0 and
// trigger the callback immediately. Notice that minPlayers is
// configured on logic.js as well.
// minPlayers: MIN_PLAYERS,
stager.setDefaultProperty('minPlayers', [
settings.MIN_PLAYERS,
cbs.notEnoughPlayers
]);
stager.setDefaultProperty('pushClients', true);
stager.extendStep('selectLanguage', {
cb: function() {
// Storing the language setting.
node.on.data('mylang', function(msg) {
if (msg.data && msg.data.name !== 'English') {
channel.registry.updateClient(msg.from, { lang: msg.data });
}
});
}
});
stager.extendStep('matching', {
cb: function() {
this.node.log('Ultimatum');
cbs.doMatch();
}
});
stager.extendStage('ultimatum', {
reconnect: cbs.reconnectUltimatum
});
stager.extendStep('questionnaire', {
minPlayers: undefined
});
stager.extendStep('endgame', {
cb: cbs.endgame,
minPlayers: undefined,
steprule: stepRules.SOLO
});
// Here we group together the definition of the game logic.
return {
nodename: 'lgc' + counter,
// Extracts, and compacts the game plot that we defined above.
plot: stager.getState(),
// If debug is false (default false), exception will be caught and
// and printed to screen, and the game will continue.
debug: settings.DEBUG,
// Controls the amount of information printed to screen.
verbosity: -100
};
};