feat(app): 主页新增难度选择UI,游戏页读取localStorage难度参数

This commit is contained in:
Cloud Bot
2026-03-21 09:45:37 +00:00
parent 0f335e7722
commit 9704881fd8
2 changed files with 113 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
'use client'
import Link from 'next/link'
import { useState } from 'react'
import { useRouter } from 'next/navigation'
// 背景装饰黑话词条
const BUZZ_WORDS = [
@@ -11,7 +12,53 @@ const BUZZ_WORDS = [
'向上管理', '自驱力', '全链路', '数据驱动', '业务增长',
]
type DifficultyLevel = 'easy' | 'normal' | 'hard'
const DIFFICULTY_OPTIONS: {
key: DifficultyLevel
label: string
desc: string
color: string
borderColor: string
glowColor: string
}[] = [
{
key: 'easy',
label: '简单',
desc: '带薪摸鱼,准点下班',
color: '#22C55E',
borderColor: '#16a34a',
glowColor: 'rgba(34,197,94,0.35)',
},
{
key: 'normal',
label: '普通',
desc: '常规打工,偶有加班',
color: '#3B82F6',
borderColor: '#2563eb',
glowColor: 'rgba(59,130,246,0.35)',
},
{
key: 'hard',
label: '困难',
desc: '地狱模式007全开',
color: '#EF4444',
borderColor: '#dc2626',
glowColor: 'rgba(239,68,68,0.35)',
},
]
export default function GameCover() {
const [selectedDifficulty, setSelectedDifficulty] = useState<DifficultyLevel>('normal')
const router = useRouter()
const handleStart = () => {
if (typeof window !== 'undefined') {
localStorage.setItem('game-difficulty', selectedDifficulty)
}
router.push('/game')
}
return (
<main
className="crt-overlay relative w-full min-h-screen flex flex-col items-center justify-center overflow-hidden"
@@ -22,7 +69,7 @@ export default function GameCover() {
backgroundPosition: 'center',
}}
>
{/* 深色叠加层,确保文字可读 */}
{/* 深色叠加层 */}
<div className="absolute inset-0" style={{ backgroundColor: 'rgba(10,10,30,0.72)' }} />
{/* CRT 流动扫描线 */}
@@ -108,9 +155,54 @@ export default function GameCover() {
线 HC
</p>
{/* 难度选择 */}
<div className="w-full">
<p
className="font-pixel text-center mb-3"
style={{ fontSize: '9px', color: '#7C3AED', letterSpacing: '0.2em' }}
>
</p>
<div className="flex gap-3 justify-center">
{DIFFICULTY_OPTIONS.map(opt => {
const isSelected = selectedDifficulty === opt.key
return (
<button
key={opt.key}
onClick={() => setSelectedDifficulty(opt.key)}
style={{
flex: 1,
padding: '10px 8px',
backgroundColor: isSelected ? `rgba(${opt.key === 'easy' ? '34,197,94' : opt.key === 'normal' ? '59,130,246' : '239,68,68'},0.15)` : '#0F1B2D',
border: `2px solid ${isSelected ? opt.color : '#1e3a5f'}`,
borderRadius: '10px',
cursor: 'pointer',
transition: 'all 0.15s ease',
boxShadow: isSelected ? `0 0 16px ${opt.glowColor}` : 'none',
transform: isSelected ? 'translateY(-2px)' : 'none',
}}
>
<div
className="font-vt323"
style={{ fontSize: '22px', color: opt.color, marginBottom: '2px' }}
>
{opt.label}
</div>
<div
className="font-vt323"
style={{ fontSize: '13px', color: '#9CA3AF', lineHeight: 1.2 }}
>
{opt.desc}
</div>
</button>
)
})}
</div>
</div>
{/* 开始游戏按钮 */}
<Link
href="/game"
<button
onClick={handleStart}
className="font-pixel text-white rounded-lg transition-all duration-200 cursor-pointer"
style={{
backgroundColor: '#F43F5E',
@@ -118,22 +210,23 @@ export default function GameCover() {
fontSize: '12px',
letterSpacing: '0.1em',
boxShadow: '0 0 20px rgba(244, 63, 94, 0.4)',
border: 'none',
}}
onMouseEnter={e => {
const el = e.currentTarget as HTMLAnchorElement
const el = e.currentTarget as HTMLButtonElement
el.style.opacity = '0.9'
el.style.transform = 'translateY(-2px)'
el.style.boxShadow = '0 0 30px rgba(244, 63, 94, 0.6)'
}}
onMouseLeave={e => {
const el = e.currentTarget as HTMLAnchorElement
const el = e.currentTarget as HTMLButtonElement
el.style.opacity = '1'
el.style.transform = 'translateY(0)'
el.style.boxShadow = '0 0 20px rgba(244, 63, 94, 0.4)'
}}
>
</Link>
</button>
{/* 提示文字 */}
<p