module.exports = { 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) { return Math.sqrt((pos1.x - pos2.x) ** 2 + (pos1.y - pos2.y) ** 2); } return -1; // 如果不在一个房间内,就返回负数。 }, };