forked from npike/Pong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpong.js
44 lines (34 loc) · 1008 Bytes
/
pong.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var express = require('express')
, app = express()
, http = require('http')
, server = http.createServer(app)
, io = require('socket.io').listen(server);
server.listen(80);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
app.get('/main.css', function (req, res) {
res.sendfile(__dirname + '/main.css');
});
app.get('/input.html', function (req, res) {
res.sendfile(__dirname + '/input.html');
});
app.get('/output.html', function (req, res) {
res.sendfile(__dirname + '/output.html');
});
app.get('/game.js', function (req, res) {
res.sendfile(__dirname + '/game.js');
});
var players = 0;
io.sockets.on('connection', function (socket) {
players = (players==1)? 2 :1;
socket.emit('playerConnected', { player: 'player'+players });
socket.on('move', function (data) {
console.log(data);
io.sockets.volatile.emit('updatePlayer', data);
});
});
io.sockets.on('disconnect', function (socket) {
console.log('disconnected');
players--;
});