add basic game classes

This commit is contained in:
Asraelite 2016-03-21 17:12:26 +00:00
parent ebcee954bf
commit bb9a493450
11 changed files with 137 additions and 6 deletions

View file

@ -1,15 +1,17 @@
'use strict';
const Player = require('../player.js');
class Connection {
constructor(net, socket) {
this.net = net;
this.server = net.server;
this.connections = net.connections;
this.io = net.io;
this.socket = socket;
this.player = false;
this.player = new Player(this);
this._room = false;
this.name = '';
this.chatCooldown = 0;
socket.on('chat', data => {
@ -17,10 +19,10 @@ class Connection {
});
socket.on('setName', data => {
this.player.name = data.name;
this.player.name = data.name.slice(0, 20) || 'Fish';
});
this.room = 'egg';
this.server.assignRoom(this.player);
}
chat(data) {
@ -47,6 +49,10 @@ class Connection {
this.socket.join(str);
this._room = str;
}
get name() {
return this.player.name;
}
}
module.exports = Connection;