-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
64 lines (50 loc) · 1.49 KB
/
app.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Generated by CoffeeScript 1.4.0
(function() {
var app, connect, express, game, http, io, server;
express = require('express');
http = require('http');
connect = require('connect');
io = require('socket.io');
app = express();
game = require('./lib/game');
app.use(express.bodyParser());
app.set('port', 1338);
server = http.createServer(app);
server.listen(app.get('port'), function() {
return console.log('Express server listening on port ' + app.get('port'));
});
app.configure(function() {
app.use('/public', express["static"](__dirname + '/public'));
return app.use(express["static"](__dirname + '/public'));
});
io = require('socket.io').listen(server);
io.sockets.on('connection', function(socket) {
socket.emit('news', {
hello: 'world'
});
socket.on('error', function(data) {
return console.log(data);
});
socket.on('start', function(data) {
console.log('start');
return game.start();
});
socket.on('stop', function() {
return game.stop();
});
socket.on('kick', function(data) {
var velocity;
velocity = data.z;
game.kick(velocity);
return game.switchPlayer();
});
return game.inRange(function() {
var id, players, whosTurn;
players = io.sockets.clients();
whosTurn = Math.floor(Math.random() * players.length);
id = players[whosTurn].id;
console.log(id);
return io.sockets.socket(id).emit('turn');
});
});
}).call(this);