This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
app.js
108 lines (83 loc) · 2.4 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var game = require('./routes/game');
var http = require('http');
var path = require('path');
var lessMiddleware = require('less-middleware');
// var sio = require('socket.io');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(lessMiddleware(__dirname + '/public', { force: true }));
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
app.get('/new', game.new);
app.post('/:id', game.save);
app.get('/:id', game.detail);
var server = http.createServer(app);
server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
// var data = [
// [null, null, null, null, null, null],
// [null, null, null, null, null, null],
// [null, null, null, null, null, null],
// [null, null, null, null, null, null],
// [null, null, null, null, null, null],
// [null, null, null, null, null, null],
// [null, null, null, null, null, null]
// ];
// var player1Color = '#ff0000';
// var player2Color = '#00ff00';
// /**
// * Socket.IO server (single process only)
// */
// var io = sio.listen(server)
// , websockets = {},
// player1,
// player2;
// io.sockets.on('connection', function (socket) {
// console.log("CONNECT");
// if(player1 == null || player2 == null){
// if(player1 == null){
// player1 = socket;
// socket.emit('Color',player1Color);
// }else if(player2 == null){
// player2 = socket;
// socket.emit('Color',player2Color);
// }
// socket.on('playerMove', function(row, col, playerColor){
// data[row][col] = playerColor;
// if(socket == player1){
// if(player2)
// player2.emit('Opponent', row, col);
// }else{
// if(player1)
// player1.emit('Opponent', row, col);
// }
// });
// socket.on('disconnect', function () {
// socket.broadcast.emit('Closed');
// if(socket == player1)
// player1 = null;
// else
// player2 = null;
// });
// }
// });
//