2020-10-18 22:00:22 +08:00
|
|
|
module.exports = {
|
2020-10-26 16:45:02 +08:00
|
|
|
uuid() {
|
|
|
|
|
// 6位
|
|
|
|
|
let uuid = "";
|
|
|
|
|
for (let i = 0; i < 6; i += 1) {
|
|
|
|
|
if (Math.random() > 0.5) {
|
|
|
|
|
// 大于0.5就是数字,小于则是字母
|
|
|
|
|
uuid += Math.round(Math.random() * 100) % 10;
|
|
|
|
|
} else {
|
|
|
|
|
uuid += String.fromCharCode(
|
|
|
|
|
97 + (Math.round(Math.random() * 100) % 26)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uuid;
|
|
|
|
|
},
|
|
|
|
|
distance(pos1, pos2) {
|
|
|
|
|
if (pos1.roomName === pos2.roomName) {
|
2020-10-26 22:03:25 +08:00
|
|
|
return Math.sqrt((pos1.x - pos2.x) ** 2 + (pos1.y - pos2.y) ** 2);
|
2020-10-26 16:45:02 +08:00
|
|
|
}
|
|
|
|
|
return -1; // 如果不在一个房间内,就返回负数。
|
|
|
|
|
},
|
2020-10-26 16:15:52 +08:00
|
|
|
};
|