-
-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is colyseus suitable for turn base game? #7
Comments
Hi @takaaptech, Yes, it's suitable! I'm starting to write the documentation for the server, you can take a look here: http://gamestd.io/colyseus/docs/room-state.html (feedbacks are welcome!) Considering you want to make a "tic tac toe" like game, you'd need to allow only 2 clients per room, and the room state might look like this: var Room = require('colyseus').Room
class TicTacToeRoom extends Room {
constructor (options) {
super(options, 1000)
this.players = {}
this.setState({
currentPlayer: null,
board: [[0,0,0], [0,0,0], [0,0,0]]
})
}
requestJoin() {
return this.clients.length < 2
}
onJoin(client) {
this.players[client.id] = (this.clients.length == 1) ? "X" : "O"
}
onMessage (client, data) {
// change this.state.board[x][y] to client's attribute (X or O?)
this.state.board[data.x][data.y] = this.players[client.id]
}
}
module.exports = TicTacToeRoom I didn't tested this code, just wrote it quickly here. You'd basically have to deal with the board state in the server, and request commands through the client on the position you want to update. When the state has successfully changed, you can apply the change in the client-side through the To deal with timing events, you could use built-in Hope this helps, let me know if you have any questions. |
Thank so much! |
Hi!
I am develop a turn base game (likes tic tac toe online). In game, users start match and play turn by turn, user move is limited by time (e.x 30 second each move) . And after some conditional, match over and then user start match again . So how can i implement this feature in colyseus server?
Thank so much!
The text was updated successfully, but these errors were encountered: