-
Notifications
You must be signed in to change notification settings - Fork 0
Game
- Client side stuff (lobby stuff, css, html etc) is in Public folder
-
engine.js runs the game for user.
-
Basically it listens for socket events clients send to server, and run the corresponding game Command.
-
All available game commands are specified in Commands.js, this is the interface for game logic.
For example, user want to build a settlement.
In client side:
sock.emit('BUILD_SETTLEMENT', relevant_data);
sock.on('BUILD_SETTLEMENT_SUCCESS', function(received_data){
// ... do some stuffs with data
// ... do some jquery to change UI
});
Here, 'BUILD_SETTLEMENT' is an socket.io event.
In server side:
In engine.js, we do
got('BUILD_SETTLEMENT', function(relevant_data){
Commands.buildSettlement(var1, var2...);
// ...
send('BUILD_SETTLEMENT_SUCCESS', some_data);
}
This listens for 'BUILD_SETTLEMENT' event, builds the settlement, and sends client back an acknowledgement. got
and send
are wrappers around socket.on
and socket.emit
, so we can perform logging and additional preprocessing.
For event xxx, there will be a Commands.xxx.
Socket events and their corresponding data format are specified in server/engine/document folder.
To be consistent:
- if you add a new socket event, please add it and its data format to document folder.
- all events name are UPPERCASE linked with underscores.