gamer
v0.0.1
Published
Turn-based game server
Downloads
7
Maintainers
Readme
Gamer.JS
GamerJS - tiny NodeJS game server based on Socket.IO.
Features
- Game with 1 to N players or AI.
- Authentication.
- WebSockets or Long-Polling for transferring data.
- Public and private game-rooms.
- Turn-base behavior, when players do turns one-by-one, like Tic-Tak-Toe, Age of Empires, Civilization ,etc.
- Realtime behavior, when each player can do independent turns. Like Dota2, LoL, etc.
Workflow
- Game server is initiated.
- Client connects to the server. If the client want to create new game - step 3, if find already created or join - step 4.
- Create new game:
- Public
1. Client send
'client:create-public-room'
to the server. 2. Client receive'room:created'
with id in payload. - Private
1. Client send
'client:create-private-room'
to the server. 2. Client receive'room:created'
with id in payload. - Find already created game or join:
- Public
1. Client send
'client:find-public-room'
to the server. 2. Client receive'room:found'
with id in payload or'room:not-found'
. - Private
1. Client send
'client:join-private-room'
to the server. 2. Client receive'room:joined'
with id in payload or'room:not-found'
. - When players number in game are equal to needed - all the client receive
'game:ready'
. - Now every client need send
'client:ready'
or'client:not-ready'
to the server. - If some clients are not ready - move to step 2.
- When all the clients are ready, server execute
inititalAction
action and after send'game:initial-state'
to all the clients with the result as payload. - Send every second to the clients
'game:will-start-in'
with countdown as payload. It usecountdown
parameter as base and decrease it every second. - When countdown value is zero - the server sends
'game:started'
to all the clients. - After game is started, clients available to send
'client:turn'
to the server. Payload of this message will be passed to'turnAction'
method. - After
'turnAction'
is done,'syncAction'
is fired. In'syncAction'
determine what the data will be send with'game:update-state'
message as payload. - Sending to all the clients
'game:update-state'
with result of'syncAction'
method. - After it -
'gameOverAction'
will be fired. If the game is over - method fires callback with data, which will be passed to'game:over'
message later. - Client receive
'game:update-state'
and update current game state. - Steps 10-13 is repeating until
'gameOverAction'
keep not firing callback. - When the game is over clients receive
'game:over'
message with information to show the game results, which was build in'gameOverAction'
before. - After it, players still connected and game state on the server is identically to step 5. If rematch is take the place - client need to do step 6 and replay game again.
Installation
npm install gamer --save
Examples
- Tic-Tak-Toe, using React for Client.
- Barley-Breck, using React for Client.
API
here will be described API...