forked from bbales/battle-snake
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
executable file
·54 lines (43 loc) · 1.3 KB
/
server.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
var _dir = '/home/gonzo/Development/battlesnake/'
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/static'))
var snakes = require('./modules/snakes')
var util = require('./modules/util')
var game = require('./modules/game')
var keyboard = require('./modules/keyboard')
var http = require('http');
var server = http.createServer(app);
server.listen(8000, "0.0.0.0");
global.io = require('socket.io')(server);
app.get('/', function (request, response) {
console.log('Initial get')
});
io.on('connection', function (socket) {
var snake = snakes.functions.spawn();
socket.emit('gameState', game.state);
socket.emit('userIdSet', snake.id);
socket.on('keyPress', function(data){
keyboard.functions.readKeyPress(data, snake);
});
socket.on('disconnect', function(e){
snakes.functions.kill(snake.id)
});
});
var time=0;
function main(){
time++;
util.functions.generateFood();
snakes.functions.moveAll();
snakes.functions.checkFood();
snakes.functions.checkAllCollisions();
snakes.functions.checkLengths();
if(time%100==0){
snakes.functions.calories();
time=1;
}
// game.bullets.generate();
io.emit('gameState', game.state)
setTimeout(main,1000/game.config.frameRate);
};
main();