From 191895567c1f3cb946362f8d0ecdc72e2981e79f Mon Sep 17 00:00:00 2001 From: tsui110 Date: Fri, 2 Jan 2026 22:44:17 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=89=AB=E9=9B=B7=E6=A0=BC=E5=AD=90?= =?UTF-8?q?=E5=92=8C=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages-game/game/minesweeper/play.scss | 6 ++++++ pages-game/game/minesweeper/play.vue | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pages-game/game/minesweeper/play.scss b/pages-game/game/minesweeper/play.scss index da96880..c4a5b7f 100644 --- a/pages-game/game/minesweeper/play.scss +++ b/pages-game/game/minesweeper/play.scss @@ -712,6 +712,8 @@ background: $bg-dark-card; border-radius: $radius-lg; border: 1px solid $border-dark; + // 确保格子始终保持正方形 + aspect-ratio: 1 / 1; } .grid-cell { @@ -722,6 +724,10 @@ align-items: center; transition: all $transition-fast; position: relative; + // 确保每个格子都是正方形 + aspect-ratio: 1 / 1; + width: 100%; + height: auto; &:active { transform: scale(0.95); diff --git a/pages-game/game/minesweeper/play.vue b/pages-game/game/minesweeper/play.vue index 1a1b73c..3754257 100644 --- a/pages-game/game/minesweeper/play.vue +++ b/pages-game/game/minesweeper/play.vue @@ -103,7 +103,7 @@ 'healed': healedPlayers.includes(p.userId) }" > - {{ p.avatar }} + {{ getPlayerAvatar(p) }} {{ p.username || '对手' }} @@ -193,7 +193,7 @@ 'healed': healedPlayers.includes(myPlayer.userId) }" > - {{ myPlayer.avatar }} + {{ getPlayerAvatar(myPlayer) }} @@ -660,6 +660,26 @@ export default { if (content === 'empty') return '✅'; return this.getItemIcon(content); }, + getPlayerAvatar(player) { + // 如果服务器已经发送了avatar字段,直接使用 + if (player.avatar) { + return player.avatar; + } + + // 否则,根据userId或username确定性分配一个动物头像 + const avatars = ['🐶', '🐘', '🐯', '🐵', '🦥', '🦛']; + + // 使用userId或username作为哈希种子,确保同一玩家总是获得相同的头像 + const seed = player.userId || player.username || player.id || ''; + let hash = 0; + for (let i = 0; i < seed.length; i++) { + hash = ((hash << 5) - hash) + seed.charCodeAt(i); + hash = hash & hash; // 转换为32位整数 + } + + const index = Math.abs(hash) % avatars.length; + return avatars[index]; + }, getNumColor(n) { return ['','blue','green','red','purple','orange'][n] || 'black'; }, getOpCodeName(code) { const map = {