June 2015
Beginner
354 pages
8h 23m
English
Perform the following steps to create our foundation logic for the game:
game.js. We will store the room and game logic in this file.User class that stores the socket connection object and creates a random ID.function User(socket) {
this.socket = socket;
// assign a random number to User.
// Long enough to make duplication chance less.
this.id = "1" + Math.floor( Math.random() * 1000000000);
}Room class. We store a collection of user instances in this class.function Room() {
this.users = [];
}Room class that manages the adding and removing of users.Room.prototype.addUser = function(user){ ...Read now
Unlock full access