-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.js
55 lines (50 loc) · 1.27 KB
/
player.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
const state = require('./state')
const generate = require('./generate')
module.exports = {
getNeighbors: userId => {
var player = state.get(userId, 'player')
return generate.getNeighbors(player.map, player.pos.x, player.pos.y)
},
move(userId, dir){
var player = state.get(userId, 'player')
var n = generate.getNeighbors(player.map, player.pos.x, player.pos.y)
if(n[dir]){
player.pos.x = n[dir].x
player.pos.y = n[dir].y
player.map[player.pos.y][player.pos.x].visited = true
state.saveState()
}
},
getMapAscii(userId){
var player = state.get(userId, 'player')
var map = player.map
var s = ''
for(var y = 0; y < generate.MAPSIZE; ++y){
for(var x = 0; x < generate.MAPSIZE; ++x) {
var c = map[y][x]
if(c){
c = map[y][x].val
}
if(map[y][x].visited === true){
c = '_'
}
if(player.pos.x == x && player.pos.y == y){
c = '*'
}
s+= ''+ c + ' '
}
s += '\n'
}
return s
},
add(userId, field, amount){
var player = state.get(userId, 'player')
if(typeof player[field] === 'number'){
player[field] += amount
}
},
getFightChance(userId){
},
getChance(userId){
}
}