[HTML] 纯文本查看 复制代码
<template>
<div class="color-game">
<!-- 模式切换按钮 -->
<div class="mode-selector">
<button @click="confirmSwitchMode('normal')" :class="{ active: gameMode === 'normal' }">无尽模式</button>
<button @click="confirmSwitchMode('timed')" :class="{ active: gameMode === 'timed' }">竞速模式</button>
</div>
<!-- 计时器 -->
<div v-if="gameMode === 'timed'" class="timer timer-display">
{{ remainingTime.toFixed(2) }}s
</div>
<!-- 分数和成就显示 -->
<div class="game-header">
<div class="score">分数: {{ score }}</div>
<div v-if="currentAchievement" class="achievement-notification">
<el-alert :title="`解锁成就:${currentAchievement}`" type="success" :closable="false" show-icon />
</div>
</div>
<!-- <h1 style="color: white;font-size: 35px;">当前游戏正在进行较大更新,排行榜可能存在bug,请勿上传分数</h1>
<h1 style="color: white;font-size: 35px;">竞速模式为测试版</h1> -->
<!-- 游戏网格 -->
<div class="game-container" :style="gridStyle">
<div v-for="(color, index) in colors" :key="index" class="color-block" :style="{ backgroundColor: color }"
@click="handleColorClick(index)"></div>
</div>
<!-- 控制按钮 -->
<div class="game-controls">
<el-button type="primary" @click="showAchievements = true">查看成就</el-button>
<el-button type="danger" @click="restartGame">重新开始</el-button>
</div>
<!-- 成就对话框 -->
<el-dialog title="游戏成就" :visible.sync="showAchievements" customClass="reward-width">
<div class="achievements-list">
<el-tag v-for="(achieved, title) in currentAchievements" :key="title" :type="achieved ? 'success' : 'info'"
class="achievement-tag">
{{ title }}
</el-tag>
</div>
</el-dialog>
<!-- 修改后的游戏结束对话框 -->
<el-dialog title="游戏结束" :visible.sync="showGameOver" customClass="gameover-width" @close="restartGame"
:close-on-click-modal="false">
<div class="game-over-content">
<p class="final-score">你到达了第<span style="color: rgb(232, 101, 39)"> {{ level }} </span>关 </p>
<p class="final-score">获得了<span style="color: rgb(50,225,50)"> {{ score }} </span>分!</p>
<span style="text-align: right; display: block;">
<el-button type="primary" @click="showUploadScore">上传分数</el-button>
<el-button @click="restartGame">重新开始</el-button>
</span>
</div>
<div class="achievements-earned">
<h3>已获得成就:</h3>
<el-tag :style="{ display: achieved ? 'inline-block' : 'none' }"
v-for="(achieved, title) in currentAchievements" :key="title" type="success" class="achievement-tag">
{{ title }}
</el-tag>
</div>
</el-dialog>
<!-- 上传分数对话框 -->
<el-dialog title="上传分数" :visible.sync="showUploadDialog" customClass="gameover-width" :close-on-click-modal="false">
<el-form :model="uploadForm" :rules="uploadRules" ref="uploadForm" @submit.native.prevent>
<el-form-item label="留下您的大名,为您获取排名" prop="username">
<el-input v-model="uploadForm.username" placeholder="请输入昵称"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="showUploadDialog = false">取消</el-button>
<el-button type="primary" @click="submitScore">确定</el-button>
</span>
</el-dialog>
<!-- 排名结果对话框 -->
<el-dialog title="排名结果" :visible.sync="showRankResult" customClass="gameover-width">
<div class="rank-result">
<p>恭喜!您的最好成绩排名第 <span class="highlight">{{ currentRank }}</span> 名</p>
<p v-if="isBreakRecord" class="break-record">新纪录!</p>
</div>
</el-dialog>
<!-- 显示最大轮数 -->
<div class="max-level-display">
<!-- 显示最大轮数和最高分 -->
<div class="max-level-display">
<p v-if="gameMode == 'normal'">最大轮数: {{ maxLevel }}</p>
<p v-if="gameMode == 'normal'">最高分: {{ maxScore }}</p>
<p v-if="gameMode == 'timed'">最大轮数(计时模式): {{ maxLevelTimed }}</p>
<p v-if="gameMode == 'timed'">最高分(计时模式): {{ maxScoreTimed }}</p>
</div>
</div>
<!-- 排行榜 -->
<div class="leaderboard">
<div class="leaderboard-header" style="position: relative;">
<el-button type="text" class="refresh-btn" @click="refreshLeaderboard"
style="position: absolute; left: 0; top: 22px;">
<i class="el-icon-refresh"></i> 刷新排行榜
</el-button>
<h2 class="leaderboard-title" style="margin: 0;">
排行榜({{ gameMode === 'normal' ? '无尽' : '竞速' }})
</h2>
</div>
<!-- 数据表格 -->
<el-table :data="leaderboardData" style="width: 100%"
:header-cell-style="{ background: '#4527A0', color: 'white' }" :row-class-name="setRowClassName"
:empty-text="leaderboardError ? '获取排行数据失败' : '暂时无人挑战,快来留下你的战绩吧'">
<el-table-column prop="rank" label="排名" width="80" align="center">
<template #default="scope">
<div class="rank-number" :class="getRankClass(scope.row.rank)">
{{ scope.row.rank }}
</div>
</template>
</el-table-column>
<el-table-column prop="username" label="用户名"></el-table-column>
<el-table-column prop="achievement" label="头衔"></el-table-column>
<el-table-column prop="max_score" label="分数" width="100"></el-table-column>
<el-table-column prop="record_broken_at" label="破纪录时间" width="180"></el-table-column>
</el-table>
<!-- 分页 -->
<div class="pagination-container" style="margin-top: 20px; text-align: center;">
<el-pagination :current-page="currentPage" :page-size="pageSize" :total="totalUsers" layout="prev, pager, next"
@current-change="handlePageChange" class="custom-pagination" />
</div>
</div>
</div>
</template>
<script>
import axiosRequest from '@/utils/request';
export default {
name: 'ColorGame',
data() {
return {
score: 0,
level: 1,
gridSize: 2,
colors: [],
targetIndex: 0,
clickedIndex: -1,
showAchievements: false,
showGameOver: false,
currentAchievement: '',
achievements: {
'色盲': false,
'色弱': false,
'肉眼凡胎': false,
'一眼丁真': false,
'目光犀利': false,
'初出茅庐': false,
'火眼初成': false,
'锋芒毕露': false,
'成绩斐然': false,
'得心应手': false,
'游刃有余': false,
'炉火纯青': false,
'登峰造极': false,
'出神入化': false,
'绝世无双': false,
'绝世无双-Pro': false,
'绝世无双-Ultra': false,
'绝世无双-Plus': false,
'绝世无双-Max': false,
'绝世无双-Pro-Max': false,
'绝世无双-Ultra-Pro-Max': false,
'绝世无双-Plus-Ultra-Pro-Max': false,
'淬体境': false,
'聚气境': false,
'蜕凡境': false,
'人元境': false,
'真阳境': false,
'灵武境': false,
'天罡境': false,
'玄冥境': false,
'化宗境': false,
'虚空境': false,
'洞虚境': false,
'阴阳境': false,
'四极境': false,
'轮回境': false,
'大武境': false,
'王者境': false,
'元尊境': false,
'至尊境': false,
'主宰境': false,
'皇者境': false,
'天王境': false,
'界王境': false,
'破天境': false,
'合天境': false,
'融天境': false,
'原神启动境': false
},
achievements_timed: {
'太慢了': false,
'慢': false,
'差点意思': false,
'还行': false,
'有点意思': false,
'哎哟不错哦': false,
'渐入佳境': false,
'眼感火热': false,
'电眼逼人': false,
'唯快不破': false,
'人肉3090': false,
'人肉4060': false,
'人肉4090': false,
'人肉A100': false
},
maxLevel: 1,
maxScore: 0,
maxLevelTimed: 1,
maxScoreTimed: 0,
showUploadDialog: false,
showRankResult: false,
leaderboardData: [],
leaderboardError: false, // 排行榜获取状态
currentPage: 1, // 当前页数
pageSize: 20, // 每页显示条数
uploadForm: {
username: localStorage.getItem('username') || ''
},
uploadRules: {
username: [
{ required: true, message: '请输入昵称', trigger: 'blur' },
{ min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }
]
},
currentRank: 0,
isBreakRecord: false,
totalUsers: 0,
gameMode: 'normal', // 当前模式,默认无尽模式
remainingTime: 60.00, // 限时模式下的剩余时间
timer: null, // 定时器句柄
timed_playing: false, // 是否正在限时模式下游戏
};
},