-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
144 lines (131 loc) · 3.8 KB
/
Copy pathapp.js
File metadata and controls
144 lines (131 loc) · 3.8 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
let express = require('express');
let bodyParser = require('body-parser');
let Game = require('./game/game');
let game = new Game();
let app = express();
let urlencodetParser = bodyParser.urlencoded({
extendet: false
});
let log = '';
app.set('views', './views');
app.set('view engine', 'jade');
app.use(express.static(__dirname + "/public"));
app.post('/command', urlencodetParser, function(req, res) {
if(!req.body)
return res.sendStatus(400);
let cache = log;
switch(req.body.cmd.toLowerCase()) {
case '':
log = `${cache}`;
break;
case 'start':
console.log(req.body);
game.start();
log = `<p class="correct"> Игра началась </p>
<p class="correct"> Ваши координаты:
x${game.char.position.x},
y${game.char.position.y} </p><br>`;
break;
case 'help':
console.log(req.body);
log = `<p class="help">Список доступных команд:<br>
<br><b>start</b> - <i>начать игру</i><br>
<b>ahead/back/left/right</b> - <i>движение</i><br>
<b>map</b> - <i>посмотреть карту</i><br>
<b>i</b> - <i>посмотреть инвентарь</i><br>
<b>radar</b> - <i>узнать расположение предметов</i><br>
<b>direct</b> - <i>направление</i></p>${cache}`;
break;
case 'ahead':
console.log(req.body);
game.go('forward');
if(game.char.output === '') {
log = `<p class="correct"> Ваши координаты:
x${game.char.position.x},
y${game.char.position.y} </p>${cache}`;
} else {
log = `<p class="correct"> ${game.char.output} </p>${cache}`
}
break;
case 'back':
console.log(req.body);
game.go('backward');
if(game.char.output === '') {
log = `<p class="correct"> Ваши координаты:
x${game.char.position.x},
y${game.char.position.y} </p>${cache}`;
} else {
log = `<p class="correct"> ${game.char.output} </p>${cache}`
}
break;
case 'left':
console.log(req.body);
game.go('left');
if(game.char.output === '') {
log = `<p class="correct"> Ваши координаты:
x${game.char.position.x},
y${game.char.position.y} </p>${cache}`;
} else {
log = `<p class="correct"> ${game.char.output} </p>${cache}`
}
break;
case 'right':
console.log(req.body);
game.go('right');
if(game.char.output === '') {
log = `<p class="correct"> Ваши координаты:
x${game.char.position.x},
y${game.char.position.y} </p>${cache}`;
} else {
log = `<p class="correct"> ${game.char.output} </p>${cache}`
}
break;
case 'direct':
console.log(req.body);
log = `<p class="correct"> Ваше направление:
${game.char.position.direct}</p>${cache}`;
break;
case 'map':
console.log(req.body);
let minmap = game.map.renderMap();
log = `Ваши координаты: x${game.char.position.x},y${game.char.position.y}
${minmap}<br>${cache}`;
break;
case 'i':
console.log(req.body);
log = `<p>Информация:<br>
Здоровье - ${game.char.hitPoints}</p>${cache}`;
break;
case 'radar':
let lutList = game.map.radar();
console.log(req.body);
console.log(lutList);
log = `${game.map.radar()}<br>${cache}`;
break;
default:
log = `<p> Введите <b>help</b> для просмотра доступных команд</p> ${cache}`;
}
res.render('index', {
title: 'Game',
message: 'command',
output: log
});
});
app.get('/command', function(req, res){
res.render('index', {
title: 'Game',
message: 'command'
});
});
app.get('/', function(req, res){
res.render('index', {
title: 'Game',
message: 'command'
});
});
app.get('/history', function(req, res) {
console.log(req , res);
res.end();
});
app.listen(3000);
console.log('Server is running');