22 lines
697 B
JavaScript
22 lines
697 B
JavaScript
|
|
module.exports = {
|
||
|
|
uuid() {
|
||
|
|
//6位
|
||
|
|
let _uuid = "";
|
||
|
|
for (let i = 0; i < 6; i++) {
|
||
|
|
if (Math.random() > 0.5) {
|
||
|
|
//大于0.5就是数字,小于则是字母
|
||
|
|
_uuid = _uuid + (Math.round((Math.random() * 100)) % 10 );
|
||
|
|
} else {
|
||
|
|
_uuid = _uuid + String.fromCharCode(97 + (Math.round(Math.random() * 100)) % 26);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return _uuid;
|
||
|
|
},
|
||
|
|
distance(pos1,pos2){
|
||
|
|
if(pos1.roomName==pos2.roomName){
|
||
|
|
return Math.sqrt(Math.pow((pos1.x-pos2.x),2)+Math.pow((pos1.y-pos2.y),2));
|
||
|
|
}
|
||
|
|
return -1;//如果不在一个房间内,就返回负数。
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|