a
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
# 🎮 俄罗斯方块游戏
|
||||
|
||||
经典俄罗斯方块游戏实现,遵循FC/Game Boy标准规则。
|
||||
|
||||
## 🎯 游戏特性
|
||||
|
||||
### 核心规则
|
||||
- **场地尺寸**: 10列 × 20行标准网格
|
||||
- **方块类型**: 7种标准四连方块 (I, O, T, L, J, S, Z)
|
||||
- **控制方式**: 虚拟按钮 + 键盘控制
|
||||
- **分辨率**: 540×720竖屏 (优化显示效果)
|
||||
|
||||
### 游戏机制
|
||||
1. **方块生成**: 纯随机生成7种方块
|
||||
2. **移动控制**: 左右移动、旋转、软降
|
||||
3. **消行规则**: 单行100分、双行300分、三行500分、四行800分
|
||||
4. **等级系统**: 每消除10行升1级,速度逐渐加快
|
||||
5. **游戏结束**: 新方块无法放置时结束
|
||||
|
||||
## 🎮 控制方式
|
||||
|
||||
### 虚拟按钮 (移动设备)
|
||||
- **← 左移**: 向左移动方块
|
||||
- **→ 右移**: 向右移动方块
|
||||
- **↓ 软降**: 加速下落 (每格+1分)
|
||||
- **↻ 旋转**: 顺时针旋转方块
|
||||
|
||||
### 键盘控制 (桌面设备)
|
||||
- **← / →**: 左右移动
|
||||
- **↓**: 软降加速
|
||||
- **↑ / 空格**: 旋转方块
|
||||
- **P**: 暂停/继续游戏
|
||||
|
||||
### 触摸控制 (移动设备)
|
||||
- **左右滑动**: 水平移动
|
||||
- **向下滑动**: 软降加速
|
||||
- **向上滑动**: 旋转方块
|
||||
|
||||
## 📊 游戏界面
|
||||
|
||||
### 布局设计 (移动优化)
|
||||
```
|
||||
┌─────────────────────┐
|
||||
│ 游戏画布 │
|
||||
│ (540×720像素) │
|
||||
├─────────────────────┤
|
||||
│ 虚拟控制按钮 │
|
||||
│ [开始] [↻旋转] [重来] │
|
||||
│ [←][↓][→] │
|
||||
├─────────────────────┤
|
||||
│ 游戏信息面板 │
|
||||
│ 分数 | 等级 | 消行 | 速度 │
|
||||
└─────────────────────┘
|
||||
```
|
||||
|
||||
### 控制按钮特点
|
||||
- **第一行**: 开始(左) | 旋转(中) | 重来(右)
|
||||
- **第二行**: 方向按钮紧凑排列 ← ↓ → (间距5px)
|
||||
- **按钮大小**: 65×65像素,适合手指操作
|
||||
- **布局优化**: 方向按钮紧密排列,操作更便捷
|
||||
|
||||
### 控制按钮布局
|
||||
- **第一行**: 开始按钮 (左) | 旋转按钮 (中) | 重来按钮 (右)
|
||||
- **第二行**: 方向控制按钮 (← ↓ →)
|
||||
- **开始按钮**: 动态状态 (开始/暂停/继续/重新开始)
|
||||
- **重来按钮**: 立即重置游戏,重新开始
|
||||
|
||||
### 信息面板 (虚拟键盘下方)
|
||||
- **分数**: 当前游戏得分 (大字体显示)
|
||||
- **等级**: 当前游戏等级 (0-20)
|
||||
- **消行**: 已消除的行数
|
||||
- **速度**: 当前下落速度倍数
|
||||
|
||||
### 信息面板 (虚拟键盘下方)
|
||||
- **分数**: 当前游戏得分 (大字体显示)
|
||||
- **等级**: 当前游戏等级 (0-20)
|
||||
- **消行**: 已消除的行数
|
||||
- **速度**: 当前下落速度倍数
|
||||
|
||||
**设计特点**:
|
||||
- 信息面板位于虚拟键盘下方,方便查看
|
||||
- 水平排列,节省垂直空间
|
||||
- 大字体显示,易于阅读
|
||||
- 视觉增强:阴影、边框、间距优化
|
||||
|
||||
### 游戏状态
|
||||
- **游戏进行中**: 正常游戏状态
|
||||
- **游戏暂停**: 点击画布或按P键暂停
|
||||
- **游戏结束**: 显示最终得分和统计
|
||||
|
||||
## 🔧 技术实现
|
||||
|
||||
### 技术栈
|
||||
- **游戏引擎**: PlayCanvas (WebGL 2.0/WebGPU)
|
||||
- **SDK集成**: Poki SDK (游戏状态管理)
|
||||
- **分辨率**: 540×720竖屏优化
|
||||
- **响应式**: 自适应不同屏幕尺寸
|
||||
|
||||
### 代码结构
|
||||
```
|
||||
TetrisGame类
|
||||
├── 游戏初始化 (initGame)
|
||||
├── 方块管理 (spawnNewPiece, rotatePiece, movePiece)
|
||||
├── 碰撞检测 (checkCollision)
|
||||
├── 消行逻辑 (clearLines, updateScore)
|
||||
├── 游戏循环 (startGameLoop)
|
||||
├── 渲染系统 (render, drawBlock, drawRect, drawLine)
|
||||
└── 控制管理 (setupControls, setupUI)
|
||||
```
|
||||
|
||||
### 关键算法
|
||||
1. **碰撞检测**: 实时检测边界和方块重叠
|
||||
2. **旋转算法**: 4×4矩阵转置实现90度旋转
|
||||
3. **消行检测**: 遍历每行检查是否填满
|
||||
4. **分数计算**: 基础分 × 等级倍数
|
||||
5. **速度控制**: 等级越高下落间隔越短
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
### 访问方式
|
||||
1. 通过游戏门户: http://129.211.173.87:8895/
|
||||
2. 直接访问: http://129.211.173.87:8895/games/tetris/
|
||||
|
||||
### 开发测试
|
||||
```bash
|
||||
# 进入游戏目录
|
||||
cd /home/ubuntu/nanocode/happy-games/games/tetris/
|
||||
|
||||
# 查看游戏文件
|
||||
ls -la
|
||||
|
||||
# 编辑游戏配置
|
||||
vim index.html
|
||||
```
|
||||
|
||||
## 📈 游戏策略
|
||||
|
||||
### 新手技巧
|
||||
1. **保持平整**: 尽量填平底部,避免出现深坑
|
||||
2. **预留空间**: 为I型方块留出4格空间完成Tetris
|
||||
3. **优先消行**: 尽快消除行数提升等级
|
||||
4. **控制速度**: 高等级时提前规划方块位置
|
||||
|
||||
### 高级技巧
|
||||
1. **T-Spin准备**: 虽然经典版无T-Spin,但可预留T型位置
|
||||
2. **连消规划**: 一次性消除多行获得更高分数
|
||||
3. **速度适应**: 随着等级提升调整操作节奏
|
||||
|
||||
## 🔄 更新日志
|
||||
|
||||
### v1.2.0 (2026-04-03)
|
||||
- ✅ 移动开始/重来按钮到底部控制行
|
||||
- ✅ 布局优化:开始(左) | 旋转(中) | 重来(右)
|
||||
- ✅ 方向按钮紧凑排列 (←↓→ 间距5px)
|
||||
- ✅ 保持动态开始按钮状态 (开始/暂停/继续/重新开始)
|
||||
- ✅ 保持快速游戏重置功能
|
||||
|
||||
### v1.1.0 (2026-04-03)
|
||||
- ✅ 优化移动端布局:信息面板移到虚拟键盘下方
|
||||
- ✅ 改进信息面板设计:水平排列 + 大字体显示
|
||||
- ✅ 增强视觉体验:阴影、边框、间距优化
|
||||
|
||||
### v1.0.0 (2026-04-03)
|
||||
- ✅ 实现经典俄罗斯方块核心规则
|
||||
- ✅ 添加虚拟控制按钮系统
|
||||
- ✅ 集成PlayCanvas游戏引擎
|
||||
- ✅ 添加Poki SDK支持
|
||||
- ✅ 实现分数和等级系统
|
||||
- ✅ 优化540×720竖屏显示
|
||||
- ✅ 添加游戏暂停/继续功能
|
||||
- ✅ 集成到小游戏中心门户
|
||||
|
||||
## 📝 规则参考
|
||||
|
||||
详细规则请参考: [经典俄罗斯方块(标准复古版)规则.md](./经典俄罗斯方块(标准复古版)规则.md)
|
||||
|
||||
## 🎨 设计说明
|
||||
|
||||
### 视觉设计
|
||||
- **色彩方案**: 每种方块有独特颜色,易于区分
|
||||
- **网格显示**: 清晰显示10×20游戏场地
|
||||
- **预览系统**: 显示方块最终下落位置
|
||||
- **高光阴影**: 方块立体效果增强视觉体验
|
||||
|
||||
### 用户体验
|
||||
- **响应控制**: 虚拟按钮即时反馈
|
||||
- **状态提示**: 清晰显示游戏状态
|
||||
- **信息展示**: 实时更新分数和等级
|
||||
- **错误处理**: 无效操作无响应,避免误操作
|
||||
|
||||
## 🔗 相关链接
|
||||
|
||||
- [小游戏中心主页](http://129.211.173.87:8895/)
|
||||
- [PlayCanvas文档](https://developer.playcanvas.com/)
|
||||
- [Poki SDK文档](https://poki.com/developers)
|
||||
- [俄罗斯方块维基百科](https://zh.wikipedia.org/wiki/俄罗斯方块)
|
||||
@@ -0,0 +1,663 @@
|
||||
const { chromium } = require('playwright');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 所有俄罗斯方块版本
|
||||
const ALL_VERSIONS = [
|
||||
// Canvas 2D 版本
|
||||
{ file: 'tetris_final_canvas2d.html', name: '最终Canvas 2D版', type: 'canvas2d', priority: 1 },
|
||||
{ file: 'tetris_simple_fall_test.html', name: '简单下落测试版', type: 'canvas2d', priority: 2 },
|
||||
{ file: 'tetris_simple_fixed.html', name: '简单修复版', type: 'canvas2d', priority: 3 },
|
||||
{ file: 'tetris_working.html', name: '工作版', type: 'canvas2d', priority: 4 },
|
||||
{ file: 'tetris_mobile.html', name: '手机优化版', type: 'canvas2d', priority: 5 },
|
||||
{ file: 'tetris_ultimate.html', name: '终极版', type: 'canvas2d', priority: 6 },
|
||||
{ file: 'tetris_simple_canvas.html', name: 'Canvas 2D简化版', type: 'canvas2d', priority: 7 },
|
||||
|
||||
// PlayCanvas 版本
|
||||
{ file: 'tetris_playcanvas_working.html', name: 'PlayCanvas工作版', type: 'playcanvas', priority: 1 },
|
||||
{ file: 'tetris_playcanvas_super_debug.html', name: 'PlayCanvas超级调试版', type: 'playcanvas', priority: 2 },
|
||||
{ file: 'tetris_playcanvas_render_fixed.html', name: 'PlayCanvas渲染修复版', type: 'playcanvas', priority: 3 },
|
||||
{ file: 'tetris_playcanvas_simple.html', name: 'PlayCanvas简化版', type: 'playcanvas', priority: 4 },
|
||||
{ file: 'tetris_playcanvas_fixed.html', name: 'PlayCanvas修复版', type: 'playcanvas', priority: 5 },
|
||||
{ file: 'tetris_pure_playcanvas.html', name: '纯PlayCanvas版', type: 'playcanvas', priority: 6 },
|
||||
|
||||
// 其他版本
|
||||
{ file: 'tetris_final.html', name: '最终版', type: 'mixed', priority: 1 },
|
||||
{ file: 'tetris_exact_snake_copy.html', name: '贪吃蛇精确复制版', type: 'mixed', priority: 2 },
|
||||
{ file: 'tetris_snake_style.html', name: '贪吃蛇风格版', type: 'mixed', priority: 3 },
|
||||
{ file: 'tetris_no_poki.html', name: '无Poki SDK版', type: 'mixed', priority: 4 },
|
||||
|
||||
// 默认版本
|
||||
{ file: 'index.html', name: '默认版', type: 'default', priority: 1 },
|
||||
];
|
||||
|
||||
const BASE_URL = 'http://129.211.173.87:8895/games/tetris/';
|
||||
const OUTPUT_DIR = '/tmp/tetris_auto_test';
|
||||
|
||||
// 创建输出目录
|
||||
if (!fs.existsSync(OUTPUT_DIR)) {
|
||||
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
async function testVersion(browser, version, index, total) {
|
||||
console.log(`\n[${index}/${total}] 🎮 测试: ${version.name}`);
|
||||
console.log('='.repeat(70));
|
||||
|
||||
const page = await browser.newPage();
|
||||
const logs = [];
|
||||
const errors = [];
|
||||
const warnings = [];
|
||||
|
||||
try {
|
||||
// 设置页面事件监听
|
||||
page.on('console', msg => {
|
||||
const text = msg.text();
|
||||
const type = msg.type();
|
||||
|
||||
logs.push({
|
||||
time: new Date().toISOString(),
|
||||
type: type,
|
||||
text: text
|
||||
});
|
||||
|
||||
if (type === 'error') {
|
||||
errors.push(text);
|
||||
} else if (type === 'warning') {
|
||||
warnings.push(text);
|
||||
}
|
||||
});
|
||||
|
||||
page.on('pageerror', error => {
|
||||
errors.push(`页面错误: ${error.message}`);
|
||||
});
|
||||
|
||||
// 导航到页面
|
||||
const url = BASE_URL + version.file;
|
||||
console.log(`📡 URL: ${url}`);
|
||||
|
||||
const startTime = Date.now();
|
||||
await page.goto(url, {
|
||||
waitUntil: 'networkidle',
|
||||
timeout: 15000
|
||||
});
|
||||
const loadTime = Date.now() - startTime;
|
||||
console.log(`✅ 页面加载成功 (${loadTime}ms)`);
|
||||
|
||||
// 等待页面完全初始化
|
||||
await page.waitForTimeout(3000);
|
||||
|
||||
// 检查Canvas元素
|
||||
const canvasCount = await page.locator('canvas').count();
|
||||
console.log(`🎨 Canvas数量: ${canvasCount}`);
|
||||
|
||||
let canvasInfo = '未找到';
|
||||
if (canvasCount > 0) {
|
||||
const canvas = page.locator('canvas').first();
|
||||
const box = await canvas.boundingBox();
|
||||
if (box) {
|
||||
canvasInfo = `${Math.round(box.width)}x${Math.round(box.height)}`;
|
||||
console.log(`📐 Canvas尺寸: ${canvasInfo}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 查找开始按钮
|
||||
const buttonSelectors = [
|
||||
'#start-btn',
|
||||
'#start-button',
|
||||
'button:has-text("开始")',
|
||||
'button:has-text("Start")',
|
||||
'button:has-text("▶️")',
|
||||
'button:has-text("Play")',
|
||||
'button'
|
||||
];
|
||||
|
||||
let startButton = null;
|
||||
let buttonSelector = '';
|
||||
|
||||
for (const selector of buttonSelectors) {
|
||||
const count = await page.locator(selector).count();
|
||||
if (count > 0) {
|
||||
startButton = page.locator(selector).first();
|
||||
buttonSelector = selector;
|
||||
console.log(`🔘 找到按钮: ${selector} (${count}个)`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 点击开始按钮或按空格键
|
||||
let buttonClicked = false;
|
||||
if (startButton) {
|
||||
try {
|
||||
await startButton.click({ timeout: 3000 });
|
||||
buttonClicked = true;
|
||||
console.log('✅ 点击开始按钮');
|
||||
} catch (clickError) {
|
||||
console.log(`⚠️ 按钮点击失败: ${clickError.message}`);
|
||||
}
|
||||
} else {
|
||||
console.log('⚠️ 未找到开始按钮,尝试按空格键');
|
||||
await page.keyboard.press(' ');
|
||||
}
|
||||
|
||||
// 等待游戏开始
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
// 再次尝试点击(有些版本需要双击)
|
||||
if (!buttonClicked && startButton) {
|
||||
try {
|
||||
await startButton.click({ timeout: 2000 });
|
||||
console.log('✅ 第二次点击开始按钮');
|
||||
buttonClicked = true;
|
||||
} catch (e) {
|
||||
// 忽略第二次点击失败
|
||||
}
|
||||
}
|
||||
|
||||
// 等待游戏运行
|
||||
await page.waitForTimeout(5000); // 等待5秒让游戏运行
|
||||
|
||||
// 分析日志
|
||||
const spawnKeywords = ['生成', 'spawn', 'new piece', '方块', 'piece'];
|
||||
const moveKeywords = ['移动', 'move', '下落', 'drop', '位置', '位置', 'x=', 'y='];
|
||||
const errorKeywords = ['error', '❌', '失败', '未找到', 'undefined', 'NaN', 'TypeError'];
|
||||
|
||||
const spawnLogs = logs.filter(log =>
|
||||
spawnKeywords.some(keyword => log.text.toLowerCase().includes(keyword.toLowerCase()))
|
||||
);
|
||||
|
||||
const moveLogs = logs.filter(log =>
|
||||
moveKeywords.some(keyword => log.text.toLowerCase().includes(keyword.toLowerCase()))
|
||||
);
|
||||
|
||||
const errorLogs = logs.filter(log =>
|
||||
errorKeywords.some(keyword => log.text.toLowerCase().includes(keyword.toLowerCase()))
|
||||
);
|
||||
|
||||
console.log(`📊 日志统计:`);
|
||||
console.log(` 总日志: ${logs.length}条`);
|
||||
console.log(` 生成日志: ${spawnLogs.length}条`);
|
||||
console.log(` 移动日志: ${moveLogs.length}条`);
|
||||
console.log(` 错误日志: ${errorLogs.length}条`);
|
||||
|
||||
// 显示关键日志
|
||||
if (spawnLogs.length > 0) {
|
||||
const lastSpawn = spawnLogs[spawnLogs.length - 1];
|
||||
console.log(`📝 最后生成: ${lastSpawn.text.substring(0, 100)}`);
|
||||
}
|
||||
|
||||
if (moveLogs.length > 0) {
|
||||
const recentMoves = moveLogs.slice(-3);
|
||||
console.log(`📝 最近移动:`);
|
||||
recentMoves.forEach((log, i) => {
|
||||
console.log(` ${i+1}. ${log.text.substring(0, 80)}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (errorLogs.length > 0) {
|
||||
console.log(`⚠️ 关键错误:`);
|
||||
errorLogs.slice(0, 3).forEach((log, i) => {
|
||||
console.log(` ${i+1}. ${log.text.substring(0, 100)}`);
|
||||
});
|
||||
}
|
||||
|
||||
// 截图
|
||||
const screenshotName = `${version.type}_${version.name.replace(/\s+/g, '_')}.png`;
|
||||
const screenshotPath = path.join(OUTPUT_DIR, screenshotName);
|
||||
|
||||
try {
|
||||
await page.screenshot({
|
||||
path: screenshotPath,
|
||||
fullPage: true,
|
||||
timeout: 5000
|
||||
});
|
||||
console.log(`📸 截图保存: ${screenshotPath}`);
|
||||
} catch (screenshotError) {
|
||||
console.log(`⚠️ 截图失败: ${screenshotError.message}`);
|
||||
}
|
||||
|
||||
// 判断测试结果
|
||||
let status = 'unknown';
|
||||
let score = 0;
|
||||
let details = [];
|
||||
|
||||
// 评分系统
|
||||
if (canvasCount > 0) score += 20;
|
||||
if (buttonClicked) score += 20;
|
||||
if (spawnLogs.length > 0) score += 30;
|
||||
if (moveLogs.length > 0) score += 30;
|
||||
if (errorLogs.length === 0) score += 10;
|
||||
|
||||
// 状态判断
|
||||
if (score >= 90) {
|
||||
status = 'excellent';
|
||||
details.push('🎉 完美工作');
|
||||
} else if (score >= 70) {
|
||||
status = 'good';
|
||||
details.push('✅ 工作良好');
|
||||
} else if (score >= 50) {
|
||||
status = 'partial';
|
||||
details.push('⚠️ 部分工作');
|
||||
} else if (score >= 30) {
|
||||
status = 'poor';
|
||||
details.push('❌ 工作不佳');
|
||||
} else {
|
||||
status = 'failed';
|
||||
details.push('💥 完全失败');
|
||||
}
|
||||
|
||||
if (spawnLogs.length === 0) details.push('方块未生成');
|
||||
if (moveLogs.length === 0) details.push('方块未移动');
|
||||
if (errorLogs.length > 0) details.push(`${errorLogs.length}个错误`);
|
||||
|
||||
console.log(`📈 测试评分: ${score}/100 (${status})`);
|
||||
console.log(`📋 详情: ${details.join(', ')}`);
|
||||
|
||||
// 收集测试结果
|
||||
return {
|
||||
...version,
|
||||
status,
|
||||
score,
|
||||
details: details.join('; '),
|
||||
canvasCount,
|
||||
canvasSize: canvasInfo,
|
||||
buttonClicked,
|
||||
spawnLogs: spawnLogs.length,
|
||||
moveLogs: moveLogs.length,
|
||||
errorLogs: errorLogs.length,
|
||||
totalLogs: logs.length,
|
||||
loadTime,
|
||||
screenshot: screenshotPath,
|
||||
url,
|
||||
logs: logs.slice(-20).map(log => `${log.type}: ${log.text}`), // 最后20条日志
|
||||
errors: errors.slice(0, 5) // 前5个错误
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.log(`💥 测试异常: ${error.message}`);
|
||||
return {
|
||||
...version,
|
||||
status: 'error',
|
||||
score: 0,
|
||||
details: `测试异常: ${error.message}`,
|
||||
canvasCount: 0,
|
||||
canvasSize: '未知',
|
||||
buttonClicked: false,
|
||||
spawnLogs: 0,
|
||||
moveLogs: 0,
|
||||
errorLogs: 1,
|
||||
totalLogs: 0,
|
||||
loadTime: 0,
|
||||
screenshot: '',
|
||||
url: BASE_URL + version.file,
|
||||
logs: [],
|
||||
errors: [error.message]
|
||||
};
|
||||
} finally {
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('🚀 开始全面自动化测试俄罗斯方块游戏');
|
||||
console.log(`测试时间: ${new Date().toLocaleString()}`);
|
||||
console.log(`测试版本数: ${ALL_VERSIONS.length}`);
|
||||
console.log(`输出目录: ${OUTPUT_DIR}`);
|
||||
console.log('='.repeat(80));
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-accelerated-2d-canvas',
|
||||
'--disable-gpu'
|
||||
]
|
||||
});
|
||||
|
||||
const results = [];
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
// 按优先级排序测试
|
||||
const sortedVersions = [...ALL_VERSIONS].sort((a, b) => a.priority - b.priority);
|
||||
|
||||
for (let i = 0; i < sortedVersions.length; i++) {
|
||||
const version = sortedVersions[i];
|
||||
const result = await testVersion(browser, version, i + 1, sortedVersions.length);
|
||||
results.push(result);
|
||||
|
||||
// 版本间间隔
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
|
||||
const totalTime = Date.now() - startTime;
|
||||
console.log(`\n✅ 所有测试完成! 总耗时: ${(totalTime / 1000).toFixed(1)}秒`);
|
||||
|
||||
// 生成详细报告
|
||||
generateReport(results, totalTime);
|
||||
|
||||
} catch (error) {
|
||||
console.error(`💥 主测试过程异常: ${error.message}`);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
}
|
||||
|
||||
function generateReport(results, totalTime) {
|
||||
console.log('\n' + '='.repeat(80));
|
||||
console.log('📋 俄罗斯方块游戏自动化测试报告');
|
||||
console.log('='.repeat(80));
|
||||
|
||||
// 按类型和状态分组
|
||||
const byType = {
|
||||
canvas2d: results.filter(r => r.type === 'canvas2d'),
|
||||
playcanvas: results.filter(r => r.type === 'playcanvas'),
|
||||
mixed: results.filter(r => r.type === 'mixed'),
|
||||
default: results.filter(r => r.type === 'default')
|
||||
};
|
||||
|
||||
const byStatus = {
|
||||
excellent: results.filter(r => r.status === 'excellent'),
|
||||
good: results.filter(r => r.status === 'good'),
|
||||
partial: results.filter(r => r.status === 'partial'),
|
||||
poor: results.filter(r => r.status === 'poor'),
|
||||
failed: results.filter(r => r.status === 'failed'),
|
||||
error: results.filter(r => r.status === 'error')
|
||||
};
|
||||
|
||||
// 统计信息
|
||||
console.log(`\n📊 总体统计:`);
|
||||
console.log(` 测试版本: ${results.length}个`);
|
||||
console.log(` 测试耗时: ${(totalTime / 1000).toFixed(1)}秒`);
|
||||
console.log(` 成功版本: ${byStatus.excellent.length + byStatus.good.length}`);
|
||||
console.log(` 部分成功: ${byStatus.partial.length}`);
|
||||
console.log(` 失败版本: ${byStatus.poor.length + byStatus.failed.length + byStatus.error.length}`);
|
||||
|
||||
console.log(`\n📊 按类型统计:`);
|
||||
Object.entries(byType).forEach(([type, versions]) => {
|
||||
if (versions.length > 0) {
|
||||
const excellent = versions.filter(v => v.status === 'excellent').length;
|
||||
const good = versions.filter(v => v.status === 'good').length;
|
||||
console.log(` ${type}: ${versions.length}个 (优秀:${excellent}, 良好:${good})`);
|
||||
}
|
||||
});
|
||||
|
||||
// 最佳版本推荐
|
||||
const excellentVersions = [...byStatus.excellent].sort((a, b) => b.score - a.score);
|
||||
const goodVersions = [...byStatus.good].sort((a, b) => b.score - a.score);
|
||||
|
||||
console.log('\n' + '='.repeat(80));
|
||||
console.log('🏆 最佳版本推荐');
|
||||
console.log('='.repeat(80));
|
||||
|
||||
if (excellentVersions.length > 0) {
|
||||
console.log('\n🎉 优秀版本 (评分≥90):');
|
||||
excellentVersions.slice(0, 3).forEach((version, i) => {
|
||||
console.log(` ${i+1}. ${version.name}`);
|
||||
console.log(` 文件: ${version.file}`);
|
||||
console.log(` 评分: ${version.score}/100`);
|
||||
console.log(` Canvas: ${version.canvasSize}`);
|
||||
console.log(` 生成: ${version.spawnLogs}次, 移动: ${version.moveLogs}次`);
|
||||
console.log(` 错误: ${version.errorLogs}个`);
|
||||
console.log(` 访问: ${version.url}`);
|
||||
console.log('');
|
||||
});
|
||||
}
|
||||
|
||||
if (goodVersions.length > 0 && excellentVersions.length < 3) {
|
||||
console.log('\n✅ 良好版本 (评分≥70):');
|
||||
goodVersions.slice(0, 3).forEach((version, i) => {
|
||||
console.log(` ${i+1}. ${version.name}`);
|
||||
console.log(` 评分: ${version.score}/100`);
|
||||
console.log(` 详情: ${version.details}`);
|
||||
console.log(` 访问: ${version.url}`);
|
||||
console.log('');
|
||||
});
|
||||
}
|
||||
|
||||
// 问题版本
|
||||
const problemVersions = results.filter(r =>
|
||||
r.status === 'poor' || r.status === 'failed' || r.status === 'error'
|
||||
);
|
||||
|
||||
if (problemVersions.length > 0) {
|
||||
console.log('\n' + '='.repeat(80));
|
||||
console.log('⚠️ 问题版本需要修复');
|
||||
console.log('='.repeat(80));
|
||||
|
||||
problemVersions.slice(0, 5).forEach((version, i) => {
|
||||
console.log(` ${i+1}. ${version.name} (${version.file})`);
|
||||
console.log(` 状态: ${version.status}, 评分: ${version.score}/100`);
|
||||
console.log(` 问题: ${version.details}`);
|
||||
if (version.errors && version.errors.length > 0) {
|
||||
console.log(` 错误: ${version.errors[0]}`);
|
||||
}
|
||||
console.log('');
|
||||
});
|
||||
}
|
||||
|
||||
// 生成CSV报告
|
||||
generateCsvReport(results);
|
||||
|
||||
// 生成HTML报告
|
||||
generateHtmlReport(results, excellentVersions);
|
||||
|
||||
console.log(`\n📁 所有截图保存在: ${OUTPUT_DIR}`);
|
||||
console.log(`📄 CSV报告: ${path.join(OUTPUT_DIR, 'tetris_test_results.csv')}`);
|
||||
console.log(`📄 HTML报告: ${path.join(OUTPUT_DIR, 'tetris_test_report.html')}`);
|
||||
}
|
||||
|
||||
function generateCsvReport(results) {
|
||||
const csvPath = path.join(OUTPUT_DIR, 'tetris_test_results.csv');
|
||||
const headers = [
|
||||
'序号', '名称', '文件', '类型', '状态', '评分',
|
||||
'Canvas数量', 'Canvas尺寸', '按钮点击',
|
||||
'生成次数', '移动次数', '错误数', '总日志数',
|
||||
'加载时间(ms)', '详情', 'URL'
|
||||
];
|
||||
|
||||
const csvRows = [
|
||||
headers.join(','),
|
||||
...results.map((result, index) => [
|
||||
index + 1,
|
||||
`"${result.name}"`,
|
||||
`"${result.file}"`,
|
||||
`"${result.type}"`,
|
||||
`"${result.status}"`,
|
||||
result.score,
|
||||
result.canvasCount,
|
||||
`"${result.canvasSize}"`,
|
||||
result.buttonClicked ? '是' : '否',
|
||||
result.spawnLogs,
|
||||
result.moveLogs,
|
||||
result.errorLogs,
|
||||
result.totalLogs,
|
||||
result.loadTime,
|
||||
`"${result.details}"`,
|
||||
`"${result.url}"`
|
||||
].join(','))
|
||||
];
|
||||
|
||||
fs.writeFileSync(csvPath, csvRows.join('\n'));
|
||||
console.log(`✅ CSV报告已生成: ${csvPath}`);
|
||||
}
|
||||
|
||||
function generateHtmlReport(results, bestVersions) {
|
||||
const htmlPath = path.join(OUTPUT_DIR, 'tetris_test_report.html');
|
||||
|
||||
const statusColors = {
|
||||
excellent: '#4CAF50',
|
||||
good: '#8BC34A',
|
||||
partial: '#FFC107',
|
||||
poor: '#FF9800',
|
||||
failed: '#F44336',
|
||||
error: '#9C27B0'
|
||||
};
|
||||
|
||||
const statusTexts = {
|
||||
excellent: '优秀',
|
||||
good: '良好',
|
||||
partial: '部分工作',
|
||||
poor: '工作不佳',
|
||||
failed: '失败',
|
||||
error: '异常'
|
||||
};
|
||||
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>俄罗斯方块游戏自动化测试报告</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6; color: #333; background: #f5f7fa; padding: 20px; }
|
||||
.container { max-width: 1400px; margin: 0 auto; }
|
||||
|
||||
header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 30px; border-radius: 10px; margin-bottom: 30px; box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
|
||||
h1 { font-size: 2.5em; margin-bottom: 10px; }
|
||||
.subtitle { font-size: 1.2em; opacity: 0.9; }
|
||||
|
||||
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-bottom: 30px; }
|
||||
.card { background: white; padding: 25px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.08); }
|
||||
.card h3 { color: #555; margin-bottom: 15px; font-size: 1.1em; }
|
||||
.card .number { font-size: 2.5em; font-weight: bold; margin-bottom: 10px; }
|
||||
.card .label { color: #777; font-size: 0.9em; }
|
||||
|
||||
.best-versions { background: #e8f5e9; border-left: 5px solid #4CAF50; padding: 20px; margin-bottom: 30px; border-radius: 5px; }
|
||||
.best-versions h2 { color: #2e7d32; margin-bottom: 15px; }
|
||||
|
||||
.results-table { background: white; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,0.08); margin-bottom: 30px; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th { background: #f8f9fa; padding: 15px; text-align: left; font-weight: 600; color: #555; border-bottom: 2px solid #e9ecef; }
|
||||
td { padding: 12px 15px; border-bottom: 1px solid #e9ecef; }
|
||||
tr:hover { background: #f8f9fa; }
|
||||
|
||||
.status-badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 0.85em; font-weight: 600; color: white; }
|
||||
.score { font-weight: bold; }
|
||||
.score-high { color: #4CAF50; }
|
||||
.score-medium { color: #FF9800; }
|
||||
.score-low { color: #F44336; }
|
||||
|
||||
.version-details { margin-top: 30px; }
|
||||
.detail-card { background: white; padding: 20px; border-radius: 10px; margin-bottom: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.08); }
|
||||
.detail-card h3 { color: #333; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 2px solid #f0f0f0; }
|
||||
|
||||
footer { text-align: center; margin-top: 40px; padding: 20px; color: #777; font-size: 0.9em; border-top: 1px solid #e9ecef; }
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.summary-cards { grid-template-columns: 1fr; }
|
||||
table { display: block; overflow-x: auto; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>🎮 俄罗斯方块游戏自动化测试报告</h1>
|
||||
<div class="subtitle">测试时间: ${new Date().toLocaleString()} | 测试版本: ${results.length}个</div>
|
||||
</header>
|
||||
|
||||
<div class="summary-cards">
|
||||
<div class="card">
|
||||
<h3>📊 总体统计</h3>
|
||||
<div class="number">${results.length}</div>
|
||||
<div class="label">测试版本总数</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>✅ 成功版本</h3>
|
||||
<div class="number">${results.filter(r => r.status === 'excellent' || r.status === 'good').length}</div>
|
||||
<div class="label">优秀 + 良好</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>⚠️ 问题版本</h3>
|
||||
<div class="number">${results.filter(r => r.status === 'poor' || r.status === 'failed' || r.status === 'error').length}</div>
|
||||
<div class="label">需要修复</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>🎯 最佳评分</h3>
|
||||
<div class="number">${results.length > 0 ? Math.max(...results.map(r => r.score)) : 0}/100</div>
|
||||
<div class="label">最高分版本</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${bestVersions.length > 0 ? `
|
||||
<div class="best-versions">
|
||||
<h2>🏆 推荐使用版本</h2>
|
||||
${bestVersions.slice(0, 3).map(version => `
|
||||
<div class="detail-card">
|
||||
<h3>${version.name} (${version.file})</h3>
|
||||
<p><strong>评分:</strong> <span class="score score-high">${version.score}/100</span></p>
|
||||
<p><strong>Canvas尺寸:</strong> ${version.canvasSize}</p>
|
||||
<p><strong>游戏表现:</strong> 方块生成${version.spawnLogs}次,移动${version.moveLogs}次</p>
|
||||
<p><strong>错误数量:</strong> ${version.errorLogs}个</p>
|
||||
<p><strong>访问地址:</strong> <a href="${version.url}" target="_blank">${version.url}</a></p>
|
||||
${version.screenshot ? `<p><strong>测试截图:</strong> <br><img src="file://${version.screenshot}" alt="${version.name}" style="max-width: 300px; margin-top: 10px; border: 1px solid #ddd;"></p>` : ''}
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<div class="results-table">
|
||||
<h2 style="padding: 20px 20px 0;">📋 详细测试结果</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>版本名称</th>
|
||||
<th>文件</th>
|
||||
<th>类型</th>
|
||||
<th>状态</th>
|
||||
<th>评分</th>
|
||||
<th>Canvas</th>
|
||||
<th>生成/移动</th>
|
||||
<th>错误</th>
|
||||
<th>详情</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${results.map((result, index) => `
|
||||
<tr>
|
||||
<td>${index + 1}</td>
|
||||
<td><strong>${result.name}</strong></td>
|
||||
<td><code>${result.file}</code></td>
|
||||
<td>${result.type}</td>
|
||||
<td>
|
||||
<span class="status-badge" style="background: ${statusColors[result.status] || '#999'}">
|
||||
${statusTexts[result.status] || result.status}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="score ${result.score >= 90 ? 'score-high' : result.score >= 70 ? 'score-medium' : 'score-low'}">
|
||||
${result.score}/100
|
||||
</span>
|
||||
</td>
|
||||
<td>${result.canvasSize}</td>
|
||||
<td>${result.spawnLogs}/${result.moveLogs}</td>
|
||||
<td>${result.errorLogs}</td>
|
||||
<td>${result.details}</td>
|
||||
</tr>
|
||||
`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<p>测试工具: Playwright 1.58.0 | 浏览器: Chromium (Headless) | 生成时间: ${new Date().toLocaleString()}</p>
|
||||
<p>所有截图和详细数据保存在: ${OUTPUT_DIR}</p>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
fs.writeFileSync(htmlPath, html);
|
||||
console.log(`✅ HTML报告已生成: ${htmlPath}`);
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
main().catch(error => {
|
||||
console.error('💥 测试程序异常:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,417 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
俄罗斯方块游戏深度测试脚本
|
||||
使用Playwright无头浏览器进行专业测试
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
# 测试配置
|
||||
BASE_URL = "http://129.211.173.87:8895/games/tetris/"
|
||||
OUTPUT_DIR = Path("/tmp/tetris_deep_test")
|
||||
OUTPUT_DIR.mkdir(exist_ok=True)
|
||||
|
||||
# 重点测试版本
|
||||
KEY_VERSIONS = [
|
||||
# 优秀版本
|
||||
{"file": "tetris_playcanvas_working.html", "name": "PlayCanvas工作版", "type": "playcanvas"},
|
||||
{"file": "tetris_final_canvas2d.html", "name": "最终Canvas 2D版", "type": "canvas2d"},
|
||||
{"file": "tetris_simple_fall_test.html", "name": "简单下落测试版", "type": "canvas2d"},
|
||||
|
||||
# 默认版本
|
||||
{"file": "index.html", "name": "默认版", "type": "default"},
|
||||
|
||||
# 问题版本(需要修复)
|
||||
{"file": "tetris_simple_fixed.html", "name": "简单修复版", "type": "canvas2d"},
|
||||
{"file": "tetris_working.html", "name": "工作版", "type": "canvas2d"},
|
||||
]
|
||||
|
||||
async def test_version(page, version, test_id):
|
||||
"""深度测试单个版本"""
|
||||
print(f"\n{'='*80}")
|
||||
print(f"🎮 深度测试: {version['name']} ({version['file']})")
|
||||
print(f"{'='*80}")
|
||||
|
||||
results = {
|
||||
"version": version,
|
||||
"test_id": test_id,
|
||||
"start_time": datetime.now().isoformat(),
|
||||
"metrics": {},
|
||||
"issues": [],
|
||||
"logs": [],
|
||||
"screenshots": []
|
||||
}
|
||||
|
||||
try:
|
||||
# 导航到页面
|
||||
url = BASE_URL + version["file"]
|
||||
print(f"📡 访问: {url}")
|
||||
|
||||
start_time = time.time()
|
||||
await page.goto(url, wait_until="networkidle", timeout=15000)
|
||||
load_time = time.time() - start_time
|
||||
results["metrics"]["load_time"] = load_time
|
||||
print(f"✅ 页面加载: {load_time:.2f}秒")
|
||||
|
||||
# 等待页面完全初始化
|
||||
await page.wait_for_timeout(2000)
|
||||
|
||||
# 收集页面基本信息
|
||||
title = await page.title()
|
||||
results["metrics"]["title"] = title
|
||||
print(f"📄 页面标题: {title}")
|
||||
|
||||
# 检查Canvas元素
|
||||
canvas_elements = await page.locator("canvas").all()
|
||||
canvas_count = len(canvas_elements)
|
||||
results["metrics"]["canvas_count"] = canvas_count
|
||||
print(f"🎨 Canvas数量: {canvas_count}")
|
||||
|
||||
if canvas_count > 0:
|
||||
canvas = canvas_elements[0]
|
||||
box = await canvas.bounding_box()
|
||||
if box:
|
||||
canvas_size = f"{int(box['width'])}x{int(box['height'])}"
|
||||
results["metrics"]["canvas_size"] = canvas_size
|
||||
print(f"📐 Canvas尺寸: {canvas_size}")
|
||||
|
||||
# 查找所有按钮
|
||||
buttons = []
|
||||
button_selectors = [
|
||||
"#start-btn", "#start-button", "#restart-btn", "#pause-btn",
|
||||
"#left-btn", "#right-btn", "#down-btn", "#rotate-btn",
|
||||
"button:has-text('开始')", "button:has-text('Start')",
|
||||
"button:has-text('暂停')", "button:has-text('Pause')",
|
||||
"button:has-text('重来')", "button:has-text('Restart')",
|
||||
"button:has-text('旋转')", "button:has-text('Rotate')",
|
||||
"button:has-text('←')", "button:has-text('→')", "button:has-text('↓')",
|
||||
]
|
||||
|
||||
for selector in button_selectors:
|
||||
elements = await page.locator(selector).all()
|
||||
count = len(elements)
|
||||
if count > 0:
|
||||
buttons.append({"selector": selector, "count": count})
|
||||
|
||||
results["metrics"]["buttons_found"] = len(buttons)
|
||||
print(f"🔘 找到按钮: {len(buttons)}个")
|
||||
for btn in buttons:
|
||||
print(f" - {btn['selector']}: {btn['count']}个")
|
||||
|
||||
# 监听控制台日志
|
||||
console_logs = []
|
||||
page.on("console", lambda msg: console_logs.append({
|
||||
"time": datetime.now().isoformat(),
|
||||
"type": msg.type,
|
||||
"text": msg.text
|
||||
}))
|
||||
|
||||
# 监听页面错误
|
||||
page_errors = []
|
||||
page.on("pageerror", lambda error: page_errors.append({
|
||||
"time": datetime.now().isoformat(),
|
||||
"error": str(error)
|
||||
}))
|
||||
|
||||
# 测试1: 点击开始按钮
|
||||
print("\n🧪 测试1: 点击开始按钮")
|
||||
start_button = None
|
||||
for btn in buttons:
|
||||
if "start" in btn["selector"].lower() or "开始" in btn["selector"]:
|
||||
start_button = page.locator(btn["selector"]).first()
|
||||
break
|
||||
|
||||
if start_button:
|
||||
try:
|
||||
await start_button.click(timeout=3000)
|
||||
results["metrics"]["start_button_clicked"] = True
|
||||
print("✅ 成功点击开始按钮")
|
||||
except Exception as e:
|
||||
results["issues"].append(f"开始按钮点击失败: {str(e)}")
|
||||
print(f"⚠️ 开始按钮点击失败: {e}")
|
||||
else:
|
||||
print("⚠️ 未找到开始按钮,尝试按空格键")
|
||||
await page.keyboard.press(" ")
|
||||
|
||||
# 等待游戏开始
|
||||
await page.wait_for_timeout(1000)
|
||||
|
||||
# 测试2: 游戏运行状态检查
|
||||
print("\n🧪 测试2: 游戏运行状态检查")
|
||||
await page.wait_for_timeout(3000) # 等待3秒让游戏运行
|
||||
|
||||
# 分析日志
|
||||
spawn_logs = [log for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["生成", "spawn", "new piece", "方块", "piece"])]
|
||||
move_logs = [log for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["移动", "move", "下落", "drop", "位置", "x=", "y="])]
|
||||
error_logs = [log for log in console_logs if log["type"] == "error"]
|
||||
|
||||
results["metrics"]["spawn_logs"] = len(spawn_logs)
|
||||
results["metrics"]["move_logs"] = len(move_logs)
|
||||
results["metrics"]["error_logs"] = len(error_logs)
|
||||
results["metrics"]["total_logs"] = len(console_logs)
|
||||
|
||||
print(f"📊 日志分析:")
|
||||
print(f" 总日志: {len(console_logs)}条")
|
||||
print(f" 方块生成: {len(spawn_logs)}次")
|
||||
print(f" 方块移动: {len(move_logs)}次")
|
||||
print(f" 错误日志: {len(error_logs)}条")
|
||||
|
||||
if spawn_logs:
|
||||
print(f" 最后生成: {spawn_logs[-1]['text'][:80]}...")
|
||||
if move_logs:
|
||||
recent_moves = move_logs[-3:] if len(move_logs) >= 3 else move_logs
|
||||
print(f" 最近移动:")
|
||||
for i, move in enumerate(recent_moves):
|
||||
print(f" {i+1}. {move['text'][:60]}...")
|
||||
|
||||
# 测试3: 键盘控制测试
|
||||
print("\n🧪 测试3: 键盘控制测试")
|
||||
try:
|
||||
# 测试左移
|
||||
await page.keyboard.press("ArrowLeft")
|
||||
await page.wait_for_timeout(200)
|
||||
print("✅ 左箭头键测试")
|
||||
|
||||
# 测试右移
|
||||
await page.keyboard.press("ArrowRight")
|
||||
await page.wait_for_timeout(200)
|
||||
print("✅ 右箭头键测试")
|
||||
|
||||
# 测试下移
|
||||
await page.keyboard.press("ArrowDown")
|
||||
await page.wait_for_timeout(200)
|
||||
print("✅ 下箭头键测试")
|
||||
|
||||
# 测试旋转
|
||||
await page.keyboard.press(" ")
|
||||
await page.wait_for_timeout(200)
|
||||
print("✅ 空格键旋转测试")
|
||||
|
||||
results["metrics"]["keyboard_tested"] = True
|
||||
except Exception as e:
|
||||
results["issues"].append(f"键盘控制测试失败: {str(e)}")
|
||||
print(f"⚠️ 键盘控制测试失败: {e}")
|
||||
|
||||
# 测试4: 截图和性能检查
|
||||
print("\n🧪 测试4: 截图和性能检查")
|
||||
|
||||
# 游戏运行截图
|
||||
screenshot_path = OUTPUT_DIR / f"{version['type']}_{version['name'].replace(' ', '_')}_{test_id}.png"
|
||||
await page.screenshot(path=str(screenshot_path), full_page=True)
|
||||
results["screenshots"].append(str(screenshot_path))
|
||||
print(f"📸 截图保存: {screenshot_path}")
|
||||
|
||||
# 检查游戏状态
|
||||
game_running = len(move_logs) > 0
|
||||
results["metrics"]["game_running"] = game_running
|
||||
results["metrics"]["game_working"] = len(spawn_logs) > 0 and len(move_logs) > 0
|
||||
|
||||
# 评估游戏状态
|
||||
if len(spawn_logs) > 0 and len(move_logs) > 0:
|
||||
status = "🎉 完美工作"
|
||||
score = 100
|
||||
elif len(spawn_logs) > 0 and len(move_logs) == 0:
|
||||
status = "⚠️ 方块生成但不下落"
|
||||
score = 60
|
||||
results["issues"].append("方块生成但不下落")
|
||||
elif len(spawn_logs) == 0:
|
||||
status = "❌ 方块未生成"
|
||||
score = 30
|
||||
results["issues"].append("方块未生成")
|
||||
else:
|
||||
status = "❓ 未知状态"
|
||||
score = 50
|
||||
|
||||
results["metrics"]["status"] = status
|
||||
results["metrics"]["score"] = score
|
||||
|
||||
print(f"\n📈 测试结果: {status}")
|
||||
print(f"🏆 评分: {score}/100")
|
||||
|
||||
if error_logs:
|
||||
print(f"\n⚠️ 发现错误:")
|
||||
for i, error in enumerate(error_logs[:5]):
|
||||
print(f" {i+1}. {error['text'][:100]}...")
|
||||
|
||||
# 保存详细日志
|
||||
log_file = OUTPUT_DIR / f"{version['type']}_{version['name'].replace(' ', '_')}_{test_id}_logs.json"
|
||||
with open(log_file, "w", encoding="utf-8") as f:
|
||||
json.dump({
|
||||
"version": version,
|
||||
"console_logs": console_logs[-50:], # 最后50条日志
|
||||
"page_errors": page_errors,
|
||||
"results": results
|
||||
}, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"📄 详细日志保存: {log_file}")
|
||||
|
||||
except Exception as e:
|
||||
results["issues"].append(f"测试异常: {str(e)}")
|
||||
print(f"💥 测试异常: {e}")
|
||||
|
||||
results["end_time"] = datetime.now().isoformat()
|
||||
return results
|
||||
|
||||
async def main():
|
||||
"""主测试函数"""
|
||||
print("🚀 俄罗斯方块游戏深度测试开始")
|
||||
print(f"测试时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print(f"测试版本数: {len(KEY_VERSIONS)}")
|
||||
print(f"输出目录: {OUTPUT_DIR}")
|
||||
|
||||
all_results = []
|
||||
|
||||
async with async_playwright() as p:
|
||||
# 启动浏览器
|
||||
browser = await p.chromium.launch(
|
||||
headless=True,
|
||||
args=[
|
||||
"--no-sandbox",
|
||||
"--disable-setuid-sandbox",
|
||||
"--disable-dev-shm-usage",
|
||||
"--disable-accelerated-2d-canvas",
|
||||
"--disable-gpu"
|
||||
]
|
||||
)
|
||||
|
||||
try:
|
||||
for i, version in enumerate(KEY_VERSIONS):
|
||||
print(f"\n{'#'*80}")
|
||||
print(f"测试进度: {i+1}/{len(KEY_VERSIONS)}")
|
||||
|
||||
# 为每个版本创建新的上下文和页面
|
||||
context = await browser.new_context(
|
||||
viewport={"width": 1280, "height": 720},
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
||||
)
|
||||
page = await context.new_page()
|
||||
|
||||
try:
|
||||
results = await test_version(page, version, i+1)
|
||||
all_results.append(results)
|
||||
finally:
|
||||
await page.close()
|
||||
await context.close()
|
||||
|
||||
# 版本间间隔
|
||||
await asyncio.sleep(1)
|
||||
|
||||
finally:
|
||||
await browser.close()
|
||||
|
||||
# 生成测试报告
|
||||
generate_report(all_results)
|
||||
|
||||
print(f"\n✅ 所有测试完成!")
|
||||
print(f"📁 测试结果保存在: {OUTPUT_DIR}")
|
||||
|
||||
def generate_report(results):
|
||||
"""生成测试报告"""
|
||||
report_file = OUTPUT_DIR / "tetris_deep_test_report.md"
|
||||
|
||||
with open(report_file, "w", encoding="utf-8") as f:
|
||||
f.write("# 🎮 俄罗斯方块游戏深度测试报告\n\n")
|
||||
f.write(f"**测试时间**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
|
||||
f.write(f"**测试版本**: {len(results)}个\n\n")
|
||||
|
||||
f.write("## 📊 测试结果汇总\n\n")
|
||||
f.write("| 排名 | 版本名称 | 类型 | 评分 | 状态 | 方块生成 | 方块移动 | 错误数 |\n")
|
||||
f.write("|------|----------|------|------|------|----------|----------|--------|\n")
|
||||
|
||||
# 按评分排序
|
||||
sorted_results = sorted(results, key=lambda x: x["metrics"].get("score", 0), reverse=True)
|
||||
|
||||
for i, result in enumerate(sorted_results):
|
||||
version = result["version"]
|
||||
metrics = result["metrics"]
|
||||
|
||||
f.write(f"| {i+1} | {version['name']} | {version['type']} | ")
|
||||
f.write(f"{metrics.get('score', 0)}/100 | {metrics.get('status', '未知')} | ")
|
||||
f.write(f"{metrics.get('spawn_logs', 0)} | {metrics.get('move_logs', 0)} | ")
|
||||
f.write(f"{metrics.get('error_logs', 0)} |\n")
|
||||
|
||||
f.write("\n## 🏆 最佳版本推荐\n\n")
|
||||
|
||||
# 推荐最佳版本
|
||||
excellent_versions = [r for r in sorted_results if r["metrics"].get("score", 0) >= 80]
|
||||
good_versions = [r for r in sorted_results if 60 <= r["metrics"].get("score", 0) < 80]
|
||||
problem_versions = [r for r in sorted_results if r["metrics"].get("score", 0) < 60]
|
||||
|
||||
if excellent_versions:
|
||||
f.write("### 🎉 优秀版本 (评分≥80)\n\n")
|
||||
for result in excellent_versions[:3]:
|
||||
version = result["version"]
|
||||
metrics = result["metrics"]
|
||||
f.write(f"#### {version['name']}\n")
|
||||
f.write(f"- **文件**: `{version['file']}`\n")
|
||||
f.write(f"- **评分**: {metrics.get('score', 0)}/100\n")
|
||||
f.write(f"- **Canvas**: {metrics.get('canvas_size', '未知')}\n")
|
||||
f.write(f"- **游戏表现**: 方块生成{metrics.get('spawn_logs', 0)}次,移动{metrics.get('move_logs', 0)}次\n")
|
||||
f.write(f"- **访问地址**: {BASE_URL}{version['file']}\n")
|
||||
if result.get("issues"):
|
||||
f.write(f"- **问题**: {', '.join(result['issues'])}\n")
|
||||
f.write("\n")
|
||||
|
||||
if good_versions:
|
||||
f.write("### ✅ 良好版本 (评分60-79)\n\n")
|
||||
for result in good_versions[:3]:
|
||||
version = result["version"]
|
||||
metrics = result["metrics"]
|
||||
f.write(f"- **{version['name']}**: {metrics.get('score', 0)}/100 - {metrics.get('status', '未知')}\n")
|
||||
|
||||
if problem_versions:
|
||||
f.write("### ⚠️ 需要修复的版本 (评分<60)\n\n")
|
||||
for result in problem_versions:
|
||||
version = result["version"]
|
||||
metrics = result["metrics"]
|
||||
f.write(f"- **{version['name']}**: {metrics.get('score', 0)}/100 - {metrics.get('status', '未知')}\n")
|
||||
if result.get("issues"):
|
||||
f.write(f" - 问题: {', '.join(result['issues'])}\n")
|
||||
|
||||
f.write("\n## 🔍 技术分析\n\n")
|
||||
|
||||
# 技术分析
|
||||
playcanvas_versions = [r for r in results if r["version"]["type"] == "playcanvas"]
|
||||
canvas2d_versions = [r for r in results if r["version"]["type"] == "canvas2d"]
|
||||
|
||||
f.write("### 技术栈对比\n\n")
|
||||
f.write("| 技术栈 | 测试版本 | 平均评分 | 优点 | 缺点 |\n")
|
||||
f.write("|--------|----------|----------|------|------|\n")
|
||||
|
||||
if playcanvas_versions:
|
||||
avg_score = sum(r["metrics"].get("score", 0) for r in playcanvas_versions) / len(playcanvas_versions)
|
||||
f.write(f"| PlayCanvas | {len(playcanvas_versions)} | {avg_score:.1f} | 性能好,移动次数多 | 依赖外部库,兼容性问题 |\n")
|
||||
|
||||
if canvas2d_versions:
|
||||
avg_score = sum(r["metrics"].get("score", 0) for r in canvas2d_versions) / len(canvas2d_versions)
|
||||
f.write(f"| Canvas 2D | {len(canvas2d_versions)} | {avg_score:.1f} | 兼容性好,无依赖 | 性能一般 |\n")
|
||||
|
||||
f.write("\n### 常见问题\n\n")
|
||||
f.write("1. **方块生成但不下落**: 游戏循环没有正确启动或时间计算错误\n")
|
||||
f.write("2. **键盘控制失效**: 事件监听器没有正确绑定\n")
|
||||
f.write("3. **Canvas渲染问题**: Canvas上下文获取失败或绘图API错误\n")
|
||||
f.write("4. **移动端兼容性**: 触摸事件处理不完整\n")
|
||||
|
||||
f.write("\n## 🚀 建议\n\n")
|
||||
f.write("1. **立即使用**: PlayCanvas工作版 (性能最佳)\n")
|
||||
f.write("2. **稳定选择**: 最终Canvas 2D版 (兼容性最佳)\n")
|
||||
f.write("3. **需要修复**: 检查游戏循环逻辑,确保方块自动下落\n")
|
||||
f.write("4. **移动端优化**: 确保触摸事件正确处理\n")
|
||||
|
||||
f.write(f"\n## 📁 测试文件\n\n")
|
||||
f.write(f"- **报告文件**: {report_file}\n")
|
||||
f.write(f"- **截图目录**: {OUTPUT_DIR}/\n")
|
||||
f.write(f"- **日志文件**: {OUTPUT_DIR}/*_logs.json\n")
|
||||
|
||||
print(f"📄 测试报告生成: {report_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,730 @@
|
||||
iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA
|
||||
B3RJTUUH6AUREhQ0q8J8WgAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAABQ
|
||||
SURBVHja7c4xAQAgDMCw8q8e7E4iIhJ4JgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
@@ -0,0 +1,225 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
最终完整测试
|
||||
"""
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
|
||||
def final_complete_test():
|
||||
"""最终完整测试"""
|
||||
print("🎮 俄罗斯方块最终完整测试")
|
||||
print("=" * 70)
|
||||
print("🪟 测试Windows浏览器兼容性")
|
||||
print("🎯 目标: 确认所有问题都已修复")
|
||||
print("=" * 70)
|
||||
|
||||
url = "http://129.211.173.87:8895/games/tetris/index.html"
|
||||
print(f"🌐 测试URL: {url}")
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
|
||||
context = browser.new_context(
|
||||
viewport={"width": 1280, "height": 720},
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
||||
)
|
||||
|
||||
page = context.new_page()
|
||||
|
||||
try:
|
||||
# 1. 页面加载
|
||||
print("\n1️⃣ 页面加载测试")
|
||||
page.goto(url, wait_until="networkidle", timeout=10000)
|
||||
print(" ✅ 页面加载成功")
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
# 2. 收集日志
|
||||
logs = []
|
||||
page.on("console", lambda msg: logs.append({
|
||||
"type": msg.type,
|
||||
"text": msg.text
|
||||
}))
|
||||
|
||||
# 3. 游戏启动
|
||||
print("\n2️⃣ 游戏启动测试")
|
||||
start_btn = page.query_selector("#start-btn")
|
||||
if start_btn:
|
||||
start_btn.click(timeout=3000)
|
||||
print(" ✅ 开始按钮点击成功")
|
||||
else:
|
||||
print(" ❌ 未找到开始按钮")
|
||||
return
|
||||
|
||||
# 4. 等待游戏初始化
|
||||
time.sleep(3)
|
||||
|
||||
# 5. 测试键盘控制
|
||||
print("\n3️⃣ 键盘控制测试")
|
||||
print(" ⌨️ 测试左移...")
|
||||
page.keyboard.press("ArrowLeft")
|
||||
time.sleep(0.5)
|
||||
|
||||
print(" ⌨️ 测试右移...")
|
||||
page.keyboard.press("ArrowRight")
|
||||
time.sleep(0.5)
|
||||
|
||||
print(" ⌨️ 测试旋转...")
|
||||
page.keyboard.press(" ")
|
||||
time.sleep(0.5)
|
||||
|
||||
print(" ⌨️ 测试加速下落...")
|
||||
page.keyboard.press("ArrowDown")
|
||||
time.sleep(0.5)
|
||||
|
||||
# 6. 等待游戏运行
|
||||
print("\n4️⃣ 游戏运行测试")
|
||||
print(" ⏳ 等待游戏运行20秒...")
|
||||
time.sleep(20)
|
||||
|
||||
# 7. 分析日志
|
||||
print("\n5️⃣ 日志分析")
|
||||
|
||||
# 分类日志
|
||||
init_logs = [log for log in logs if "初始化" in log["text"] or "Canvas" in log["text"]]
|
||||
spawn_logs = [log for log in logs if "生成新方块" in log["text"]]
|
||||
move_logs = [log for log in logs if "移动方块" in log["text"] or "游戏循环" in log["text"]]
|
||||
error_logs = [log for log in logs if log["type"] == "error"]
|
||||
nan_logs = [log for log in logs if "NaN" in log["text"] or "undefined" in log["text"]]
|
||||
|
||||
print(f" 总日志数: {len(logs)}")
|
||||
print(f" 初始化日志: {len(init_logs)}")
|
||||
print(f" 方块生成日志: {len(spawn_logs)}")
|
||||
print(f" 方块移动日志: {len(move_logs)}")
|
||||
print(f" 错误日志: {len(error_logs)}")
|
||||
print(f" NaN/undefined日志: {len(nan_logs)}")
|
||||
|
||||
# 8. 显示关键日志
|
||||
print("\n6️⃣ 关键日志")
|
||||
|
||||
if spawn_logs:
|
||||
print(" 🧱 方块生成记录:")
|
||||
for i, log in enumerate(spawn_logs[-3:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if move_logs:
|
||||
print(" 🚀 方块移动记录:")
|
||||
valid_moves = [log for log in move_logs if "移动方块到:" in log["text"] and "NaN" not in log["text"]]
|
||||
for i, log in enumerate(valid_moves[-5:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if error_logs:
|
||||
print(" ❌ 错误记录:")
|
||||
for i, log in enumerate(error_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if nan_logs:
|
||||
print(" ⚠️ NaN/undefined问题:")
|
||||
for i, log in enumerate(nan_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
# 9. 问题修复验证
|
||||
print("\n7️⃣ 问题修复验证")
|
||||
|
||||
# 检查原始问题是否修复
|
||||
original_problems_fixed = True
|
||||
problems = []
|
||||
|
||||
# 检查NaN问题
|
||||
if len(nan_logs) > 0:
|
||||
original_problems_fixed = False
|
||||
problems.append("NaN/undefined问题未修复")
|
||||
else:
|
||||
print(" ✅ NaN/undefined问题已修复")
|
||||
|
||||
# 检查方块生成
|
||||
if len(spawn_logs) == 0:
|
||||
original_problems_fixed = False
|
||||
problems.append("方块未生成")
|
||||
else:
|
||||
# 检查位置是否正确
|
||||
correct_positions = 0
|
||||
for log in spawn_logs:
|
||||
if "位置: (" in log["text"] and "undefined" not in log["text"]:
|
||||
correct_positions += 1
|
||||
|
||||
if correct_positions == len(spawn_logs):
|
||||
print(f" ✅ 方块生成正常 ({len(spawn_logs)}次,位置全部正确)")
|
||||
else:
|
||||
original_problems_fixed = False
|
||||
problems.append(f"方块位置错误 ({correct_positions}/{len(spawn_logs)}正确)")
|
||||
|
||||
# 检查方块移动
|
||||
if len(move_logs) == 0:
|
||||
original_problems_fixed = False
|
||||
problems.append("方块未移动")
|
||||
else:
|
||||
valid_moves_count = len([log for log in move_logs if "NaN" not in log["text"]])
|
||||
if valid_moves_count > 0:
|
||||
print(f" ✅ 方块移动正常 ({valid_moves_count}次有效移动)")
|
||||
else:
|
||||
original_problems_fixed = False
|
||||
problems.append("方块移动无效")
|
||||
|
||||
# 检查游戏循环
|
||||
game_loop_logs = [log for log in logs if "游戏循环" in log["text"]]
|
||||
if len(game_loop_logs) > 0:
|
||||
print(f" ✅ 游戏循环工作正常 ({len(game_loop_logs)}次)")
|
||||
else:
|
||||
original_problems_fixed = False
|
||||
problems.append("游戏循环未工作")
|
||||
|
||||
# 10. 总体评估
|
||||
print("\n8️⃣ 总体评估")
|
||||
|
||||
if original_problems_fixed:
|
||||
print(" 🎉 🎉 🎉 所有问题已修复! 🎉 🎉 🎉")
|
||||
print(" ✅ NaN/undefined问题: 已修复")
|
||||
print(" ✅ 方块生成: 正常")
|
||||
print(" ✅ 方块移动: 正常")
|
||||
print(" ✅ 游戏循环: 正常")
|
||||
print(" ✅ 键盘控制: 正常")
|
||||
print("\n 🚀 游戏现在可以在Windows浏览器上完美运行!")
|
||||
else:
|
||||
print(" ⚠️ 仍有问题需要修复:")
|
||||
for problem in problems:
|
||||
print(f" ❌ {problem}")
|
||||
|
||||
# 11. 截图
|
||||
screenshot_path = "/tmp/final_complete_test.png"
|
||||
page.screenshot(path=screenshot_path, full_page=True)
|
||||
print(f"\n📸 截图保存: {screenshot_path}")
|
||||
|
||||
# 12. 给用户的建议
|
||||
print("\n9️⃣ 给用户的建议")
|
||||
print("=" * 70)
|
||||
|
||||
if original_problems_fixed:
|
||||
print("🎮 请用户测试以下功能:")
|
||||
print("1. 访问: http://129.211.173.87:8895/games/tetris/")
|
||||
print("2. 点击'开始游戏'按钮")
|
||||
print("3. 使用键盘控制:")
|
||||
print(" - ← → : 左右移动")
|
||||
print(" - ↓ : 加速下落")
|
||||
print(" - 空格键 : 旋转方块")
|
||||
print(" - P键 : 暂停/继续")
|
||||
print("4. 观察方块是否自动下落")
|
||||
print("5. 检查是否有任何错误")
|
||||
print("\n✅ 预期结果: 游戏应该完全正常工作,无NaN错误")
|
||||
else:
|
||||
print("🔧 需要进一步调试:")
|
||||
for problem in problems:
|
||||
print(f" - {problem}")
|
||||
|
||||
print("=" * 70)
|
||||
|
||||
finally:
|
||||
page.close()
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
print("\n✅ 最终完整测试完成!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
final_complete_test()
|
||||
@@ -0,0 +1,232 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
最终验证测试
|
||||
"""
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
def final_test():
|
||||
"""最终验证测试"""
|
||||
print("🎮 俄罗斯方块最终验证测试")
|
||||
print("=" * 70)
|
||||
print("🪟 测试Windows浏览器兼容性")
|
||||
print("🎯 目标: 确认游戏在Windows上100%工作")
|
||||
print("=" * 70)
|
||||
|
||||
url = "http://129.211.173.87:8895/games/tetris/index.html"
|
||||
print(f"🌐 测试URL: {url}")
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
|
||||
# 模拟Windows Chrome浏览器
|
||||
context = browser.new_context(
|
||||
viewport={"width": 1280, "height": 720},
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
)
|
||||
|
||||
page = context.new_page()
|
||||
|
||||
try:
|
||||
# 1. 页面加载测试
|
||||
print("\n1️⃣ 页面加载测试")
|
||||
print(" 📡 加载页面...")
|
||||
start_time = time.time()
|
||||
page.goto(url, wait_until="networkidle", timeout=15000)
|
||||
load_time = time.time() - start_time
|
||||
print(f" ✅ 页面加载成功 ({load_time:.2f}秒)")
|
||||
|
||||
# 等待初始化
|
||||
time.sleep(2)
|
||||
|
||||
# 2. Canvas检查
|
||||
print("\n2️⃣ Canvas检查")
|
||||
canvas_elements = page.query_selector_all("canvas")
|
||||
canvas_count = len(canvas_elements)
|
||||
print(f" 🎨 Canvas数量: {canvas_count}")
|
||||
|
||||
if canvas_count > 0:
|
||||
canvas = canvas_elements[0]
|
||||
box = canvas.bounding_box()
|
||||
if box:
|
||||
print(f" 📐 Canvas尺寸: {int(box['width'])}x{int(box['height'])}")
|
||||
|
||||
# 3. 按钮检查
|
||||
print("\n3️⃣ 按钮检查")
|
||||
buttons = ["#start-btn", "#pause-btn", "#restart-btn"]
|
||||
for btn in buttons:
|
||||
if page.query_selector(btn):
|
||||
print(f" ✅ {btn}: 存在")
|
||||
else:
|
||||
print(f" ❌ {btn}: 不存在")
|
||||
|
||||
# 收集日志
|
||||
logs = []
|
||||
page.on("console", lambda msg: logs.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S"),
|
||||
"type": msg.type,
|
||||
"text": msg.text
|
||||
}))
|
||||
|
||||
# 4. 游戏启动测试
|
||||
print("\n4️⃣ 游戏启动测试")
|
||||
print(" 🔘 点击开始按钮...")
|
||||
start_btn = page.query_selector("#start-btn")
|
||||
if start_btn:
|
||||
start_btn.click(timeout=3000)
|
||||
print(" ✅ 开始按钮点击成功")
|
||||
else:
|
||||
print(" ❌ 未找到开始按钮")
|
||||
return
|
||||
|
||||
# 等待游戏初始化
|
||||
time.sleep(3)
|
||||
|
||||
# 5. 游戏运行测试
|
||||
print("\n5️⃣ 游戏运行测试")
|
||||
print(" ⏳ 等待游戏运行30秒...")
|
||||
|
||||
# 测试键盘控制
|
||||
print(" ⌨️ 测试键盘控制...")
|
||||
time.sleep(1)
|
||||
page.keyboard.press("ArrowLeft") # 左移
|
||||
time.sleep(0.5)
|
||||
page.keyboard.press("ArrowRight") # 右移
|
||||
time.sleep(0.5)
|
||||
page.keyboard.press(" ") # 旋转
|
||||
time.sleep(0.5)
|
||||
page.keyboard.press("ArrowDown") # 加速下落
|
||||
|
||||
# 继续等待
|
||||
time.sleep(25)
|
||||
|
||||
# 6. 日志分析
|
||||
print("\n6️⃣ 日志分析")
|
||||
|
||||
# 分类日志
|
||||
init_logs = [log for log in logs if "初始化" in log["text"] or "Canvas" in log["text"]]
|
||||
spawn_logs = [log for log in logs if "生成新方块" in log["text"]]
|
||||
move_logs = [log for log in logs if "移动" in log["text"] or "游戏循环" in log["text"]]
|
||||
error_logs = [log for log in logs if log["type"] == "error"]
|
||||
nan_logs = [log for log in logs if "NaN" in log["text"] or "undefined" in log["text"]]
|
||||
|
||||
print(f" 总日志数: {len(logs)}")
|
||||
print(f" 初始化日志: {len(init_logs)}")
|
||||
print(f" 方块生成日志: {len(spawn_logs)}")
|
||||
print(f" 方块移动日志: {len(move_logs)}")
|
||||
print(f" 错误日志: {len(error_logs)}")
|
||||
print(f" NaN/undefined日志: {len(nan_logs)}")
|
||||
|
||||
# 7. 关键日志显示
|
||||
print("\n7️⃣ 关键日志")
|
||||
|
||||
if spawn_logs:
|
||||
print(" 🧱 方块生成记录:")
|
||||
for i, log in enumerate(spawn_logs[-3:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if move_logs:
|
||||
print(" 🚀 方块移动记录:")
|
||||
valid_moves = [log for log in move_logs if "移动成功" in log["text"] or "自动下落" in log["text"]]
|
||||
for i, log in enumerate(valid_moves[-5:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if error_logs:
|
||||
print(" ❌ 错误记录:")
|
||||
for i, log in enumerate(error_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if nan_logs:
|
||||
print(" ⚠️ NaN/undefined问题:")
|
||||
for i, log in enumerate(nan_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
# 8. 兼容性评估
|
||||
print("\n8️⃣ Windows兼容性评估")
|
||||
|
||||
test_results = {
|
||||
"页面加载": load_time < 3.0,
|
||||
"Canvas支持": canvas_count > 0,
|
||||
"按钮功能": all(page.query_selector(btn) for btn in buttons),
|
||||
"方块生成": len(spawn_logs) > 0,
|
||||
"方块移动": len(move_logs) > 0,
|
||||
"无JavaScript错误": len(error_logs) == 0,
|
||||
"无NaN问题": len(nan_logs) == 0,
|
||||
"游戏循环工作": any("游戏循环" in log["text"] for log in logs)
|
||||
}
|
||||
|
||||
passed = sum(test_results.values())
|
||||
total = len(test_results)
|
||||
|
||||
print(f" 测试项通过: {passed}/{total}")
|
||||
|
||||
for test_name, result in test_results.items():
|
||||
status = "✅" if result else "❌"
|
||||
print(f" {status} {test_name}")
|
||||
|
||||
# 9. 总体评分
|
||||
print("\n9️⃣ 总体评分")
|
||||
|
||||
score = (passed / total) * 100
|
||||
|
||||
if score >= 90:
|
||||
rating = "🏆 优秀"
|
||||
status = "🎉 完全兼容"
|
||||
elif score >= 70:
|
||||
rating = "✅ 良好"
|
||||
status = "👍 基本兼容"
|
||||
elif score >= 50:
|
||||
rating = "⚠️ 一般"
|
||||
status = "⚠️ 部分兼容"
|
||||
else:
|
||||
rating = "❌ 差"
|
||||
status = "❌ 不兼容"
|
||||
|
||||
print(f" 🏆 评分: {score:.1f}/100")
|
||||
print(f" 📊 评级: {rating}")
|
||||
print(f" 📋 状态: {status}")
|
||||
|
||||
# 10. 截图
|
||||
screenshot_path = "/tmp/final_windows_test.png"
|
||||
page.screenshot(path=screenshot_path, full_page=True)
|
||||
print(f"\n📸 截图保存: {screenshot_path}")
|
||||
|
||||
# 11. 最终结论
|
||||
print("\n🔟 最终结论")
|
||||
print("=" * 70)
|
||||
|
||||
if score >= 90:
|
||||
print("🎉 🎉 🎉 恭喜! 🎉 🎉 🎉")
|
||||
print("俄罗斯方块游戏在Windows浏览器上完全兼容!")
|
||||
print("所有关键功能都正常工作:")
|
||||
print(" ✅ 页面加载正常")
|
||||
print(" ✅ Canvas渲染正常")
|
||||
print(" ✅ 方块生成正常")
|
||||
print(" ✅ 方块移动正常")
|
||||
print(" ✅ 键盘控制正常")
|
||||
print(" ✅ 无JavaScript错误")
|
||||
print(" ✅ 无NaN/undefined问题")
|
||||
print("\n🚀 游戏已准备好供Windows用户使用!")
|
||||
elif score >= 70:
|
||||
print("👍 良好!")
|
||||
print("游戏在Windows浏览器上基本兼容。")
|
||||
print("主要功能正常工作,但可能有小问题。")
|
||||
print("建议进一步优化。")
|
||||
else:
|
||||
print("⚠️ 需要改进")
|
||||
print("游戏在Windows浏览器上兼容性不佳。")
|
||||
print("需要进一步调试和修复。")
|
||||
|
||||
print("=" * 70)
|
||||
|
||||
finally:
|
||||
page.close()
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
print("\n✅ 最终验证测试完成!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
final_test()
|
||||
@@ -0,0 +1,972 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 - PlayCanvas版</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎮</text></svg>">
|
||||
<!-- crypto.randomUUID 兼容性修复 -->
|
||||
<script>
|
||||
if (!crypto.randomUUID) {
|
||||
crypto.randomUUID = function() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<!-- Poki SDK -->
|
||||
<script src="https://game-cdn.poki.com/scripts/v2/poki-sdk.js" async></script>
|
||||
<!-- PlayCanvas 1.66.0 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
user-select: none;
|
||||
}
|
||||
body {
|
||||
overflow: hidden;
|
||||
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
touch-action: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
/* 手机端:上下布局,按钮在棋盘正下方 */
|
||||
#game-container {
|
||||
display: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
}
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
/* PC宽屏布局 - 使用固定位置避免重叠 */
|
||||
#game-layout {
|
||||
display: none; /* PC端不使用这个容器 */
|
||||
}
|
||||
|
||||
/* PC端:分数面板在左侧 */
|
||||
#score-panel {
|
||||
position: fixed;
|
||||
left: 30px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: white;
|
||||
font-size: 20px;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
background: rgba(0,0,0,0.6);
|
||||
padding: 25px;
|
||||
border-radius: 15px;
|
||||
min-width: 160px;
|
||||
z-index: 101;
|
||||
}
|
||||
#score-panel div {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
#score-panel div:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.label {
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
display: block;
|
||||
}
|
||||
.value {
|
||||
color: #ffd700;
|
||||
font-weight: bold;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
/* PC端:控制按钮在右下方(菜单下方) */
|
||||
#controls-pc {
|
||||
position: fixed;
|
||||
right: 30px;
|
||||
bottom: 30px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
align-items: center;
|
||||
z-index: 101;
|
||||
}
|
||||
#controls-mobile {
|
||||
display: none;
|
||||
}
|
||||
/* 菜单放在右侧 */
|
||||
#menu {
|
||||
position: fixed;
|
||||
right: 30px;
|
||||
top: 20px;
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
z-index: 101;
|
||||
background: rgba(0,0,0,0.7);
|
||||
padding: 25px;
|
||||
border-radius: 20px;
|
||||
max-width: 280px;
|
||||
}
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 28px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
.btn {
|
||||
padding: 18px 50px;
|
||||
font-size: 24px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 35px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
pointer-events: auto;
|
||||
font-weight: bold;
|
||||
}
|
||||
.btn:hover {
|
||||
transform: scale(1.08);
|
||||
box-shadow: 0 12px 35px rgba(102,126,234,0.5);
|
||||
}
|
||||
/* 游戏结束放在左侧 */
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: fixed;
|
||||
left: 30px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.9);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
z-index: 102;
|
||||
min-width: 250px;
|
||||
}
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
/* 虚拟按键 */
|
||||
#controls {
|
||||
position: absolute;
|
||||
bottom: 30px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
.control-row {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
}
|
||||
.control-btn {
|
||||
width: 110px;
|
||||
height: 110px;
|
||||
border-radius: 50%;
|
||||
background: rgba(255,255,255,0.15);
|
||||
border: 4px solid rgba(255,255,255,0.3);
|
||||
color: white;
|
||||
font-size: 44px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
.control-btn:hover {
|
||||
background: rgba(255,255,255,0.25);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
.control-btn:active {
|
||||
background: rgba(255,255,255,0.4);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
.rotate-btn {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
font-size: 52px;
|
||||
background: rgba(255,107,107,0.3);
|
||||
border-color: rgba(255,107,107,0.5);
|
||||
}
|
||||
/* 手机端布局 - 严格三层:记分牌-棋盘-按钮 */
|
||||
@media (max-width: 900px) {
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
background: #1a1a2e;
|
||||
}
|
||||
/* Canvas全屏渲染 */
|
||||
#application {
|
||||
position: fixed !important;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
z-index: 1;
|
||||
}
|
||||
/* UI层 */
|
||||
#ui {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 10;
|
||||
}
|
||||
#ui > * {
|
||||
pointer-events: auto;
|
||||
}
|
||||
/* 记分牌 - 顶部固定 */
|
||||
#score-panel {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 45px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 18px;
|
||||
font-size: 11px;
|
||||
padding: 0 10px;
|
||||
background: rgba(0,0,0,0.9);
|
||||
z-index: 20;
|
||||
}
|
||||
#score-panel div {
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
min-width: 50px;
|
||||
}
|
||||
#score-panel .label {
|
||||
font-size: 9px;
|
||||
}
|
||||
#score-panel .value {
|
||||
font-size: 15px;
|
||||
}
|
||||
/* PC按钮隐藏 */
|
||||
#controls-pc {
|
||||
display: none !important;
|
||||
}
|
||||
/* 手机按钮 - 底部固定 */
|
||||
#controls-mobile {
|
||||
display: flex !important;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 175px;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 8px;
|
||||
background: rgba(0,0,0,0.9);
|
||||
z-index: 20;
|
||||
}
|
||||
#controls-mobile .control-row {
|
||||
gap: 12px;
|
||||
justify-content: center;
|
||||
}
|
||||
.control-btn {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
font-size: 24px;
|
||||
border-width: 2px;
|
||||
}
|
||||
.rotate-btn {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
font-size: 28px;
|
||||
}
|
||||
#mobile-start-btn, #mobile-restart-btn {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid rgba(255,255,255,0.5);
|
||||
color: white;
|
||||
font-size: 11px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
line-height: 1.2;
|
||||
padding: 0;
|
||||
}
|
||||
#mobile-start-btn {
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
}
|
||||
#mobile-restart-btn {
|
||||
background: linear-gradient(135deg, #56ab2f, #a8e063);
|
||||
}
|
||||
#mobile-rules {
|
||||
color: #aaa;
|
||||
font-size: 10px;
|
||||
text-align: center;
|
||||
padding: 4px 10px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
#mobile-rules span {
|
||||
color: #ffd700;
|
||||
}
|
||||
#menu {
|
||||
display: none !important;
|
||||
}
|
||||
#gameOver {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
padding: 25px;
|
||||
min-width: 180px;
|
||||
z-index: 100;
|
||||
}
|
||||
#gameOver h2 {
|
||||
font-size: 26px;
|
||||
}
|
||||
#gameOver .btn {
|
||||
padding: 12px 25px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="application"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<!-- 菜单和结束画面 -->
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; padding: 20px; background: rgba(0,0,0,0.6); border-radius: 15px; max-width: 320px; text-align: left; color: #ccc; font-size: 14px; line-height: 1.8;">
|
||||
<h3 style="color: #00d4ff; margin-bottom: 15px; text-align: center;">📜 游戏规则</h3>
|
||||
<p><span style="color: #4ecdc4;">🎮 控制:</span> 键盘方向键或点击按钮</p>
|
||||
<p><span style="color: #ffeaa7;">← →:</span> 左右移动</p>
|
||||
<p><span style="color: #ff6b6b;">↓:</span> 加速下落</p>
|
||||
<p><span style="color: #a29bfe;">↑/空格:</span> 旋转方块</p>
|
||||
<p><span style="color: #fd79a8;">目标:</span> 填满整行消除得分</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束!</h2>
|
||||
<div style="color: white; font-size: 24px; margin-bottom: 20px;">最终分数: <span id="finalScore">0</span></div>
|
||||
<button class="btn" onclick="restartGame()">再玩一次</button>
|
||||
</div>
|
||||
|
||||
<!-- 分数面板:PC在左侧,手机在顶部 -->
|
||||
<div id="score-panel">
|
||||
<div><span class="label">分数</span> <span id="score" class="value">0</span></div>
|
||||
<div><span class="label">等级</span> <span id="level" class="value">0</span></div>
|
||||
<div><span class="label">消行</span> <span id="lines" class="value">0</span></div>
|
||||
<div><span class="label">速度</span> <span id="speed" class="value">1.0</span></div>
|
||||
</div>
|
||||
|
||||
<!-- PC端控制按钮(在右侧) -->
|
||||
<div id="controls-pc">
|
||||
<div class="control-row">
|
||||
<button class="control-btn rotate-btn" onclick="rotatePiece()">↻</button>
|
||||
</div>
|
||||
<div class="control-row">
|
||||
<button class="control-btn" onclick="moveLeft()">←</button>
|
||||
<button class="control-btn" onclick="moveDown()">↓</button>
|
||||
<button class="control-btn" onclick="moveRight()">→</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 手机端控制按钮(在底部) -->
|
||||
<div id="controls-mobile">
|
||||
<!-- 第一行:开始 + 旋转 + 重新开始 -->
|
||||
<div class="control-row">
|
||||
<button id="mobile-start-btn" onclick="startGame()">开始<br>游戏</button>
|
||||
<button class="control-btn rotate-btn" onclick="rotatePiece()">↻</button>
|
||||
<button id="mobile-restart-btn" onclick="restartGame()">重新<br>开始</button>
|
||||
</div>
|
||||
<!-- 第二行:左 下 右 -->
|
||||
<div class="control-row">
|
||||
<button class="control-btn" onclick="moveLeft()">←</button>
|
||||
<button class="control-btn" onclick="moveDown()">↓</button>
|
||||
<button class="control-btn" onclick="moveRight()">→</button>
|
||||
</div>
|
||||
<!-- 第三行:规则 -->
|
||||
<div id="mobile-rules">
|
||||
<span>← →</span> 移动 <span>↓</span> 加速 <span>↻</span> 旋转
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== Poki SDK ====================
|
||||
let pokiReady = false;
|
||||
function initPoki() {
|
||||
if (typeof PokiSDK !== 'undefined') {
|
||||
return PokiSDK.init().then(() => {
|
||||
console.log('✅ Poki SDK 初始化成功');
|
||||
pokiReady = true;
|
||||
PokiSDK.gameLoadingStart();
|
||||
setTimeout(() => PokiSDK.gameLoadingFinished(), 500);
|
||||
}).catch(err => {
|
||||
console.log('⚠️ Poki SDK 未就绪:', err);
|
||||
return Promise.resolve();
|
||||
});
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// ==================== 游戏配置 ====================
|
||||
const GRID_W = 10;
|
||||
const GRID_H = 20;
|
||||
const CELL_SIZE = 1.5;
|
||||
|
||||
const COLORS = {
|
||||
I: new pc.Color(0, 0.9, 0.9),
|
||||
O: new pc.Color(0.9, 0.9, 0),
|
||||
T: new pc.Color(0.6, 0, 0.6),
|
||||
L: new pc.Color(1, 0.5, 0),
|
||||
J: new pc.Color(0, 0, 0.9),
|
||||
S: new pc.Color(0, 0.9, 0),
|
||||
Z: new pc.Color(0.9, 0, 0)
|
||||
};
|
||||
|
||||
// 方块形状定义
|
||||
const SHAPES = {
|
||||
I: [[1,1,1,1]],
|
||||
O: [[1,1],[1,1]],
|
||||
T: [[0,1,0],[1,1,1]],
|
||||
L: [[1,0,0],[1,1,1]],
|
||||
J: [[0,0,1],[1,1,1]],
|
||||
S: [[0,1,1],[1,1,0]],
|
||||
Z: [[1,1,0],[0,1,1]]
|
||||
};
|
||||
|
||||
// ==================== 全局变量 ====================
|
||||
let app, gameRunning = false, gamePaused = false;
|
||||
let board = [], currentPiece = null;
|
||||
let score = 0, level = 0, lines = 0; // 规则:从Level 0开始
|
||||
let dropTimer = 0, dropInterval = 1.0, lockTimer = 0, lockDelay = 0.5;
|
||||
let isLocking = false; // 正在锁定延迟中
|
||||
let boardEntities = [], pieceEntities = [];
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initGame();
|
||||
});
|
||||
|
||||
function initGame() {
|
||||
console.log('🎮 初始化 PlayCanvas...');
|
||||
const canvas = document.getElementById('application');
|
||||
|
||||
try {
|
||||
app = new pc.Application(canvas, {
|
||||
mouse: new pc.Mouse(canvas),
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas),
|
||||
elementInput: new pc.ElementInput(canvas)
|
||||
});
|
||||
|
||||
app.start();
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
window.addEventListener('resize', () => app.resizeCanvas());
|
||||
|
||||
setupScene();
|
||||
setupInput();
|
||||
initBoard();
|
||||
|
||||
// 设置游戏循环(必须在app创建后)
|
||||
setupGameLoop();
|
||||
|
||||
console.log('✅ PlayCanvas 初始化成功');
|
||||
} catch (e) {
|
||||
console.error('❌ 初始化失败:', e);
|
||||
alert('游戏加载失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function setupGameLoop() {
|
||||
app.on('update', (dt) => {
|
||||
if (!gameRunning || gamePaused) return;
|
||||
|
||||
// 锁定延迟处理
|
||||
if (isLocking) {
|
||||
lockTimer += dt;
|
||||
if (lockTimer >= lockDelay) {
|
||||
// 延迟结束,确认锁定
|
||||
lockAndSpawn();
|
||||
isLocking = false;
|
||||
lockTimer = 0;
|
||||
}
|
||||
return; // 锁定期间不处理自然下落
|
||||
}
|
||||
|
||||
dropTimer += dt;
|
||||
if (dropTimer > dropInterval) {
|
||||
if (currentPiece) {
|
||||
if (!currentPiece.move(0, 1)) {
|
||||
// 规则:无法下落,进入锁定延迟(0.5秒)
|
||||
isLocking = true;
|
||||
lockTimer = 0;
|
||||
}
|
||||
}
|
||||
dropTimer = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setupScene() {
|
||||
// 根据屏幕尺寸计算最佳相机视野
|
||||
const isMobile = window.innerWidth <= 900;
|
||||
// 手机端:根据可视区域比例调整相机
|
||||
const orthoHeight = isMobile ? 32 : 35;
|
||||
|
||||
// 相机
|
||||
const camera = new pc.Entity('Camera');
|
||||
camera.addComponent('camera', {
|
||||
clearColor: new pc.Color(0.102, 0.102, 0.18), // #1a1a2e 与body背景一致
|
||||
orthographic: true,
|
||||
orthoHeight: orthoHeight,
|
||||
nearClip: 0.1,
|
||||
farClip: 100
|
||||
});
|
||||
// 手机端:完全俯视,棋盘微调向右,大小再90%
|
||||
if (isMobile) {
|
||||
camera.setPosition(6.55, 30, 11); // 左移半个格子(回退)
|
||||
camera.setEulerAngles(-90, 0, 0); // 完全俯视
|
||||
camera.camera.orthoHeight = 21.9; // 棋盘再缩90%
|
||||
} else {
|
||||
camera.setPosition(5, 20, 20);
|
||||
camera.setEulerAngles(-60, 0, 0);
|
||||
}
|
||||
app.root.addChild(camera);
|
||||
|
||||
// 灯光
|
||||
const light = new pc.Entity('Light');
|
||||
light.addComponent('light', {
|
||||
type: 'directional',
|
||||
color: new pc.Color(1, 1, 1),
|
||||
intensity: 1.2
|
||||
});
|
||||
light.setEulerAngles(45, 45, 0);
|
||||
app.root.addChild(light);
|
||||
|
||||
// 创建游戏区域背景 - 使用与body一致的颜色 #1a1a2e
|
||||
const bg = new pc.Entity('Background');
|
||||
bg.addComponent('render', { type: 'box' });
|
||||
bg.setLocalScale(GRID_W * CELL_SIZE + 0.5, 0.1, GRID_H * CELL_SIZE + 0.5);
|
||||
bg.setPosition(GRID_W * CELL_SIZE / 2 - CELL_SIZE/2, -0.1, GRID_H * CELL_SIZE / 2 - CELL_SIZE/2);
|
||||
const bgMat = new pc.StandardMaterial();
|
||||
bgMat.diffuse = new pc.Color(0.102, 0.102, 0.18); // #1a1a2e
|
||||
bgMat.update();
|
||||
bg.render.material = bgMat;
|
||||
app.root.addChild(bg);
|
||||
|
||||
// 网格线
|
||||
createGridLines();
|
||||
}
|
||||
|
||||
function createGridLines() {
|
||||
const lineMat = new pc.StandardMaterial();
|
||||
lineMat.diffuse = new pc.Color(0.2, 0.2, 0.25);
|
||||
lineMat.update();
|
||||
|
||||
// 垂直线
|
||||
for (let x = 0; x <= GRID_W; x++) {
|
||||
const line = new pc.Entity();
|
||||
line.addComponent('render', { type: 'box' });
|
||||
line.setLocalScale(0.05, 0.1, GRID_H * CELL_SIZE);
|
||||
line.setPosition(x * CELL_SIZE - CELL_SIZE/2, 0.01, GRID_H * CELL_SIZE / 2 - CELL_SIZE/2);
|
||||
line.render.material = lineMat;
|
||||
app.root.addChild(line);
|
||||
}
|
||||
// 水平线
|
||||
for (let z = 0; z <= GRID_H; z++) {
|
||||
const line = new pc.Entity();
|
||||
line.addComponent('render', { type: 'box' });
|
||||
line.setLocalScale(GRID_W * CELL_SIZE, 0.1, 0.05);
|
||||
line.setPosition(GRID_W * CELL_SIZE / 2 - CELL_SIZE/2, 0.01, z * CELL_SIZE - CELL_SIZE/2);
|
||||
line.render.material = lineMat;
|
||||
app.root.addChild(line);
|
||||
}
|
||||
}
|
||||
|
||||
function initBoard() {
|
||||
board = [];
|
||||
for (let y = 0; y < GRID_H; y++) {
|
||||
board[y] = [];
|
||||
for (let x = 0; x < GRID_W; x++) {
|
||||
board[y][x] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 方块类 ====================
|
||||
class Piece {
|
||||
constructor(type) {
|
||||
this.type = type;
|
||||
this.shape = JSON.parse(JSON.stringify(SHAPES[type]));
|
||||
this.color = COLORS[type];
|
||||
// 规则:I型出生在x=3,其他在x=4,y=0
|
||||
this.x = (type === 'I') ? 3 : 4;
|
||||
this.y = 0;
|
||||
this.entities = [];
|
||||
this.createEntities();
|
||||
}
|
||||
|
||||
createEntities() {
|
||||
// 清理旧实体 - 修复:e是{item}对象,需要访问e.entity
|
||||
this.entities.forEach(item => {
|
||||
if (item.entity && item.entity.parent) {
|
||||
item.entity.destroy();
|
||||
}
|
||||
});
|
||||
this.entities = [];
|
||||
|
||||
for (let row = 0; row < this.shape.length; row++) {
|
||||
for (let col = 0; col < this.shape[row].length; col++) {
|
||||
if (this.shape[row][col]) {
|
||||
const block = new pc.Entity();
|
||||
block.addComponent('render', { type: 'box' });
|
||||
block.setLocalScale(CELL_SIZE * 0.9, 0.5, CELL_SIZE * 0.9);
|
||||
|
||||
const mat = new pc.StandardMaterial();
|
||||
mat.diffuse = this.color;
|
||||
mat.emissive = new pc.Color(this.color.r * 0.3, this.color.g * 0.3, this.color.b * 0.3);
|
||||
mat.update();
|
||||
block.render.material = mat;
|
||||
|
||||
app.root.addChild(block);
|
||||
this.entities.push({ entity: block, row: row, col: col });
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updatePositions();
|
||||
}
|
||||
|
||||
updatePositions() {
|
||||
this.entities.forEach(item => {
|
||||
const worldX = (this.x + item.col) * CELL_SIZE;
|
||||
const worldZ = (this.y + item.row) * CELL_SIZE;
|
||||
item.entity.setPosition(worldX, 0.25, worldZ);
|
||||
});
|
||||
}
|
||||
|
||||
move(dx, dy) {
|
||||
const newX = this.x + dx;
|
||||
const newY = this.y + dy;
|
||||
if (this.isValidPosition(newX, newY, this.shape)) {
|
||||
this.x = newX;
|
||||
this.y = newY;
|
||||
this.updatePositions();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
rotate() {
|
||||
const rows = this.shape.length;
|
||||
const cols = this.shape[0].length;
|
||||
const rotated = [];
|
||||
for (let i = 0; i < cols; i++) {
|
||||
rotated[i] = [];
|
||||
for (let j = 0; j < rows; j++) {
|
||||
rotated[i][j] = this.shape[rows - 1 - j][i];
|
||||
}
|
||||
}
|
||||
if (this.isValidPosition(this.x, this.y, rotated)) {
|
||||
this.shape = rotated;
|
||||
this.createEntities();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isValidPosition(x, y, shape) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
if (newX < 0 || newX >= GRID_W || newY >= GRID_H) return false;
|
||||
if (newY >= 0 && board[newY][newX]) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
lock() {
|
||||
// 将方块固定到游戏板
|
||||
for (let row = 0; row < this.shape.length; row++) {
|
||||
for (let col = 0; col < this.shape[row].length; col++) {
|
||||
if (this.shape[row][col]) {
|
||||
const x = this.x + col;
|
||||
const y = this.y + row;
|
||||
if (y >= 0) {
|
||||
const block = new pc.Entity();
|
||||
block.addComponent('render', { type: 'box' });
|
||||
block.setLocalScale(CELL_SIZE * 0.9, 0.5, CELL_SIZE * 0.9);
|
||||
block.setPosition(x * CELL_SIZE, 0.25, y * CELL_SIZE);
|
||||
|
||||
const mat = new pc.StandardMaterial();
|
||||
mat.diffuse = this.color;
|
||||
mat.emissive = new pc.Color(this.color.r * 0.2, this.color.g * 0.2, this.color.b * 0.2);
|
||||
mat.update();
|
||||
block.render.material = mat;
|
||||
|
||||
app.root.addChild(block);
|
||||
board[y][x] = block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 清理当前方块实体
|
||||
this.entities.forEach(item => item.entity.destroy());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function spawnPiece() {
|
||||
const types = Object.keys(SHAPES);
|
||||
const type = types[Math.floor(Math.random() * types.length)];
|
||||
currentPiece = new Piece(type);
|
||||
|
||||
// 检查游戏结束
|
||||
if (!currentPiece.isValidPosition(currentPiece.x, currentPiece.y, currentPiece.shape)) {
|
||||
gameOver();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
for (let y = GRID_H - 1; y >= 0; y--) {
|
||||
let full = true;
|
||||
for (let x = 0; x < GRID_W; x++) {
|
||||
if (!board[y][x]) { full = false; break; }
|
||||
}
|
||||
if (full) {
|
||||
// 删除这一行
|
||||
for (let x = 0; x < GRID_W; x++) {
|
||||
if (board[y][x]) board[y][x].destroy();
|
||||
}
|
||||
// 上方行下移
|
||||
for (let moveY = y; moveY > 0; moveY--) {
|
||||
board[moveY] = board[moveY - 1];
|
||||
// 更新实体位置
|
||||
for (let x = 0; x < GRID_W; x++) {
|
||||
if (board[moveY][x]) {
|
||||
board[moveY][x].setPosition(x * CELL_SIZE, 0.25, moveY * CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
board[0] = new Array(GRID_W).fill(null);
|
||||
linesCleared++;
|
||||
y++; // 重新检查当前行
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
// 规则:基础分 × (等级+1),等级0时×1,等级1时×2...
|
||||
const basePoints = [0, 100, 300, 500, 800][linesCleared];
|
||||
const multiplier = level + 1;
|
||||
score += basePoints * multiplier;
|
||||
lines += linesCleared;
|
||||
// 规则:每消除10行升1级
|
||||
level = Math.floor(lines / 10);
|
||||
// 速度随等级增加
|
||||
dropInterval = Math.max(0.05, 1.0 - level * 0.05);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏控制 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 清理旧游戏
|
||||
for (let y = 0; y < GRID_H; y++) {
|
||||
for (let x = 0; x < GRID_W; x++) {
|
||||
if (board[y][x]) {
|
||||
board[y][x].destroy();
|
||||
board[y][x] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currentPiece) {
|
||||
currentPiece.entities.forEach(item => item.entity.destroy());
|
||||
currentPiece = null;
|
||||
}
|
||||
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
score = 0;
|
||||
level = 0; // 规则:从Level 0开始
|
||||
lines = 0;
|
||||
dropInterval = 1.0;
|
||||
dropTimer = 0;
|
||||
lockTimer = 0;
|
||||
isLocking = false;
|
||||
|
||||
spawnPiece();
|
||||
updateUI();
|
||||
|
||||
if (pokiReady && typeof PokiSDK !== 'undefined') {
|
||||
PokiSDK.gameplayStart();
|
||||
}
|
||||
};
|
||||
|
||||
window.restartGame = function() {
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
startGame();
|
||||
};
|
||||
|
||||
function gameOver() {
|
||||
gameRunning = false;
|
||||
document.getElementById('finalScore').textContent = score;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
|
||||
if (pokiReady && typeof PokiSDK !== 'undefined') {
|
||||
PokiSDK.gameplayStop();
|
||||
PokiSDK.commercialBreak().catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
document.getElementById('speed').textContent = (1.0 / dropInterval).toFixed(1) + 'x';
|
||||
}
|
||||
|
||||
// ==================== 输入控制 ====================
|
||||
window.moveLeft = function() {
|
||||
if (gameRunning && currentPiece) {
|
||||
if (currentPiece.move(-1, 0)) {
|
||||
// 规则:锁定延迟期间移动成功,重置锁定计时
|
||||
if (isLocking) {
|
||||
lockTimer = 0;
|
||||
// 移动后检查是否还能下落
|
||||
if (currentPiece.isValidPosition(currentPiece.x, currentPiece.y + 1, currentPiece.shape)) {
|
||||
isLocking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
window.moveRight = function() {
|
||||
if (gameRunning && currentPiece) {
|
||||
if (currentPiece.move(1, 0)) {
|
||||
// 规则:锁定延迟期间移动成功,重置锁定计时
|
||||
if (isLocking) {
|
||||
lockTimer = 0;
|
||||
// 移动后检查是否还能下落
|
||||
if (currentPiece.isValidPosition(currentPiece.x, currentPiece.y + 1, currentPiece.shape)) {
|
||||
isLocking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
window.moveDown = function() {
|
||||
if (gameRunning && currentPiece) {
|
||||
if (currentPiece.move(0, 1)) {
|
||||
// 规则:软降每格+1分
|
||||
score += 1;
|
||||
updateUI();
|
||||
// 移动成功,重置锁定状态
|
||||
isLocking = false;
|
||||
lockTimer = 0;
|
||||
} else if (!isLocking) {
|
||||
// 无法下落,立即锁定(软降时)
|
||||
lockAndSpawn();
|
||||
}
|
||||
}
|
||||
};
|
||||
window.rotatePiece = function() {
|
||||
if (gameRunning && currentPiece) {
|
||||
if (currentPiece.rotate()) {
|
||||
// 规则:锁定延迟期间旋转成功,重置锁定计时
|
||||
if (isLocking) {
|
||||
lockTimer = 0;
|
||||
// 旋转后检查是否还能下落
|
||||
if (currentPiece.isValidPosition(currentPiece.x, currentPiece.y + 1, currentPiece.shape)) {
|
||||
isLocking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function lockAndSpawn() {
|
||||
if (currentPiece) {
|
||||
currentPiece.lock();
|
||||
checkLines();
|
||||
spawnPiece();
|
||||
}
|
||||
}
|
||||
|
||||
function setupInput() {
|
||||
app.keyboard.on('keydown', (event) => {
|
||||
if (!gameRunning) return;
|
||||
|
||||
switch(event.key) {
|
||||
case pc.KEY_LEFT:
|
||||
moveLeft();
|
||||
break;
|
||||
case pc.KEY_RIGHT:
|
||||
moveRight();
|
||||
break;
|
||||
case pc.KEY_DOWN:
|
||||
moveDown();
|
||||
break;
|
||||
case pc.KEY_UP:
|
||||
case pc.KEY_SPACE:
|
||||
rotatePiece();
|
||||
break;
|
||||
case pc.KEY_P:
|
||||
gamePaused = !gamePaused;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 启动Poki
|
||||
initPoki().then(() => {
|
||||
console.log('🎮 俄罗斯方块 PlayCanvas版已加载');
|
||||
});
|
||||
</script>
|
||||
<!-- 登录认证 -->
|
||||
<script src="../auth.js?v=1"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
GAME_AUTH.init('tetris', '俄罗斯方块');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,752 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 小游戏中心</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Windows浏览器兼容性修复 -->
|
||||
<script>
|
||||
// 修复 crypto.randomUUID 兼容性问题
|
||||
if (!window.crypto?.randomUUID) {
|
||||
window.crypto = window.crypto || {};
|
||||
window.crypto.randomUUID = function() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0,
|
||||
v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// 模拟Poki SDK(如果加载失败)
|
||||
window.PokiSDK = window.PokiSDK || {
|
||||
init: () => Promise.resolve(),
|
||||
gameLoadingFinished: () => console.log('🎮 游戏加载完成'),
|
||||
gameplayStart: () => console.log('🎮 游戏开始'),
|
||||
gameplayStop: () => console.log('🎮 游戏停止'),
|
||||
commercialBreak: () => Promise.resolve()
|
||||
};
|
||||
</script>
|
||||
|
||||
<!-- 本地PlayCanvas库 -->
|
||||
<script>
|
||||
// 简化的PlayCanvas模拟(如果CDN加载失败)
|
||||
if (typeof pc === 'undefined') {
|
||||
console.warn('⚠️ PlayCanvas CDN加载失败,使用简化版本');
|
||||
window.pc = {
|
||||
Application: class {
|
||||
constructor(canvas, options) {
|
||||
this.canvas = canvas;
|
||||
this.graphicsDevice = {
|
||||
resize: () => console.log('📐 调整画布大小')
|
||||
};
|
||||
console.log('🎮 PlayCanvas应用已创建');
|
||||
}
|
||||
start() { console.log('▶️ PlayCanvas已启动'); }
|
||||
setCanvasFillMode() {}
|
||||
},
|
||||
FILLMODE_NONE: 'none',
|
||||
Mouse: class {},
|
||||
TouchDevice: class {},
|
||||
ElementInput: class {}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- 延迟加载外部库 -->
|
||||
<script src="https://game-cdn.poki.com/scripts/v2/poki-sdk.js" async defer onerror="console.warn('⚠️ Poki SDK加载失败,使用模拟版本')"></script>
|
||||
<script src="https://code.playcanvas.com/playcanvas-stable.min.js" async defer onerror="console.warn('⚠️ PlayCanvas加载失败,使用模拟版本')"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#game-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
box-shadow: 0 0 40px rgba(0, 100, 255, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮容器 */
|
||||
.controls-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background: rgba(220, 38, 38, 0.9);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
max-width: 400px;
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
<div class="error-message" id="error-message"></div>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<canvas id="application" width="540" height="720"></canvas>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-info" id="debug-info">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 调试日志
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug-info');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// 显示状态消息
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// 显示错误
|
||||
function showError(message) {
|
||||
const errorEl = document.getElementById('error-message');
|
||||
errorEl.innerHTML = `<h3>⚠️ 错误</h3><p>${message}</p><button onclick="location.reload()" style="margin-top: 10px; padding: 8px 16px; background: white; color: #dc2626; border: none; border-radius: 5px; cursor: pointer;">刷新页面</button>`;
|
||||
errorEl.style.display = 'block';
|
||||
}
|
||||
|
||||
// 隐藏加载界面
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// 游戏状态
|
||||
const game = {
|
||||
canvas: null,
|
||||
ctx: null,
|
||||
gridWidth: 10,
|
||||
gridHeight: 20,
|
||||
cellSize: 24,
|
||||
board: [],
|
||||
currentPiece: null,
|
||||
score: 0,
|
||||
level: 0,
|
||||
lines: 0,
|
||||
speed: 1.0,
|
||||
isPaused: true,
|
||||
isGameOver: false,
|
||||
gameLoop: null,
|
||||
lastTime: 0
|
||||
};
|
||||
|
||||
// 方块类型
|
||||
const pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff7f00' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#800080' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' }
|
||||
];
|
||||
|
||||
// 初始化游戏
|
||||
function initGame() {
|
||||
debugLog('初始化游戏...');
|
||||
|
||||
// 获取画布和上下文
|
||||
game.canvas = document.getElementById('application');
|
||||
game.ctx = game.canvas.getContext('2d');
|
||||
|
||||
// 清空游戏板
|
||||
game.board = Array(game.gridHeight).fill().map(() => Array(game.gridWidth).fill(0));
|
||||
|
||||
// 重置状态
|
||||
game.score = 0;
|
||||
game.level = 0;
|
||||
game.lines = 0;
|
||||
game.speed = 1.0;
|
||||
game.isPaused = false;
|
||||
game.isGameOver = false;
|
||||
|
||||
// 生成新方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
updateUI();
|
||||
render();
|
||||
|
||||
debugLog('游戏初始化完成');
|
||||
showStatus('🎮 游戏开始!');
|
||||
}
|
||||
|
||||
// 生成新方块
|
||||
function spawnNewPiece() {
|
||||
const randomType = pieceTypes[Math.floor(Math.random() * pieceTypes.length)];
|
||||
game.currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(game.gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${game.currentPiece.type}`);
|
||||
}
|
||||
|
||||
// 游戏循环
|
||||
function startGameLoop() {
|
||||
if (game.gameLoop) cancelAnimationFrame(game.gameLoop);
|
||||
|
||||
function gameLoop(timestamp) {
|
||||
if (!game.lastTime) game.lastTime = timestamp;
|
||||
const deltaTime = timestamp - game.lastTime;
|
||||
|
||||
if (deltaTime > 1000 / game.speed) {
|
||||
if (!game.isPaused && !game.isGameOver) {
|
||||
movePiece(0, 1);
|
||||
game.lastTime = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
render();
|
||||
game.gameLoop = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
|
||||
game.gameLoop = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
|
||||
// 移动方块
|
||||
function movePiece(dx, dy) {
|
||||
if (!game.currentPiece || game.isPaused || game.isGameOver) return;
|
||||
|
||||
const newX = game.currentPiece.x + dx;
|
||||
const newY = game.currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(game.currentPiece.shape, newX, newY)) {
|
||||
game.currentPiece.x = newX;
|
||||
game.currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 如果向下移动失败,固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(game.currentPiece.shape, game.currentPiece.x, game.currentPiece.y)) {
|
||||
gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 旋转方块
|
||||
function rotatePiece() {
|
||||
if (!game.currentPiece || game.isPaused || game.isGameOver) return;
|
||||
|
||||
const rotated = rotateMatrix(game.currentPiece.shape);
|
||||
if (isValidMove(rotated, game.currentPiece.x, game.currentPiece.y)) {
|
||||
game.currentPiece.shape = rotated;
|
||||
}
|
||||
}
|
||||
|
||||
// 旋转矩阵
|
||||
function rotateMatrix(matrix) {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 检查移动是否有效
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= game.gridWidth || newY >= game.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && game.board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 固定方块
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = game.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
game.board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查并消除完整的行
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = game.gridHeight - 1; y >= 0; y--) {
|
||||
if (game.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
game.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
game.board.unshift(Array(game.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置(因为行下移了)
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
game.lines += linesCleared;
|
||||
game.score += linesCleared * 100 * (game.level + 1);
|
||||
game.level = Math.floor(game.lines / 10);
|
||||
game.speed = 1.0 + game.level * 0.1;
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (game.level + 1)}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 游戏结束
|
||||
function gameOver() {
|
||||
game.isGameOver = true;
|
||||
cancelAnimationFrame(game.gameLoop);
|
||||
showStatus(`游戏结束!最终得分: ${game.score}`);
|
||||
debugLog('游戏结束');
|
||||
}
|
||||
|
||||
// 暂停/继续游戏
|
||||
function togglePause() {
|
||||
game.isPaused = !game.isPaused;
|
||||
|
||||
if (game.isPaused) {
|
||||
showStatus('⏸️ 游戏暂停');
|
||||
debugLog('游戏暂停');
|
||||
} else {
|
||||
showStatus('▶️ 游戏继续');
|
||||
debugLog('游戏继续');
|
||||
}
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
// 渲染游戏
|
||||
function render() {
|
||||
const ctx = game.ctx;
|
||||
const canvas = game.canvas;
|
||||
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= game.gridWidth; x++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x * game.cellSize, 0);
|
||||
ctx.lineTo(x * game.cellSize, canvas.height);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= game.gridHeight; y++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, y * game.cellSize);
|
||||
ctx.lineTo(canvas.width, y * game.cellSize);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < game.gridHeight; y++) {
|
||||
for (let x = 0; x < game.gridWidth; x++) {
|
||||
if (game.board[y][x]) {
|
||||
ctx.fillStyle = game.board[y][x];
|
||||
ctx.fillRect(x * game.cellSize, y * game.cellSize, game.cellSize, game.cellSize);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(x * game.cellSize, y * game.cellSize, game.cellSize, game.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (game.currentPiece) {
|
||||
const { shape, x, y, color } = game.currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
ctx.fillRect((x + col) * game.cellSize, (y + row) * game.cellSize, game.cellSize, game.cellSize);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect((x + col) * game.cellSize, (y + row) * game.cellSize, game.cellSize, game.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新UI
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = game.score;
|
||||
document.getElementById('level').textContent = game.level;
|
||||
document.getElementById('lines').textContent = game.lines;
|
||||
document.getElementById('speed').textContent = game.speed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!game.currentPiece && !game.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (game.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (game.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
// 设置控件
|
||||
function setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
debugLog('开始按钮点击');
|
||||
if (!game.currentPiece && !game.isGameOver) {
|
||||
initGame();
|
||||
} else if (game.isPaused) {
|
||||
togglePause();
|
||||
} else if (game.isGameOver) {
|
||||
initGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
debugLog('重来按钮点击');
|
||||
initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
debugLog('左按钮点击');
|
||||
movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
debugLog('右按钮点击');
|
||||
movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
debugLog('下按钮点击');
|
||||
movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
debugLog('旋转按钮点击');
|
||||
rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!game.currentPiece && !game.isGameOver) {
|
||||
initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.isPaused || game.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
// 页面加载完成
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 检查浏览器兼容性
|
||||
if (!window.crypto?.randomUUID) {
|
||||
debugLog('⚠️ crypto.randomUUID 需要兼容性修复');
|
||||
}
|
||||
|
||||
if (typeof pc === 'undefined') {
|
||||
debugLog('⚠️ PlayCanvas 未加载,使用Canvas 2D渲染');
|
||||
}
|
||||
|
||||
// 设置控件
|
||||
setupControls();
|
||||
updateUI();
|
||||
|
||||
// 隐藏加载界面
|
||||
hideLoading();
|
||||
|
||||
// 初始渲染
|
||||
render();
|
||||
|
||||
showStatus('✅ 俄罗斯方块已加载,点击开始按钮或按任意键开始游戏', 3000);
|
||||
});
|
||||
|
||||
// 错误处理
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
showError(`JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,255 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
快速俄罗斯方块测试
|
||||
使用同步Playwright API
|
||||
"""
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
# 测试配置
|
||||
BASE_URL = "http://129.211.173.87:8895/games/tetris/"
|
||||
OUTPUT_DIR = Path("/tmp/tetris_quick_test")
|
||||
OUTPUT_DIR.mkdir(exist_ok=True)
|
||||
|
||||
# 测试版本
|
||||
TEST_VERSIONS = [
|
||||
{"file": "tetris_playcanvas_working.html", "name": "PlayCanvas工作版"},
|
||||
{"file": "tetris_final_canvas2d.html", "name": "最终Canvas 2D版"},
|
||||
{"file": "tetris_simple_fall_test.html", "name": "简单下落测试版"},
|
||||
{"file": "index.html", "name": "默认版"},
|
||||
]
|
||||
|
||||
def test_game(page, version):
|
||||
"""测试游戏基本功能"""
|
||||
print(f"\n🎮 测试: {version['name']}")
|
||||
print("-" * 50)
|
||||
|
||||
url = BASE_URL + version["file"]
|
||||
print(f"📡 URL: {url}")
|
||||
|
||||
# 导航到页面
|
||||
page.goto(url, wait_until="networkidle", timeout=10000)
|
||||
print("✅ 页面加载成功")
|
||||
|
||||
# 等待页面初始化
|
||||
time.sleep(2)
|
||||
|
||||
# 检查Canvas
|
||||
canvas_elements = page.query_selector_all("canvas")
|
||||
canvas_count = len(canvas_elements)
|
||||
print(f"🎨 Canvas数量: {canvas_count}")
|
||||
|
||||
if canvas_count > 0:
|
||||
canvas = canvas_elements[0]
|
||||
box = canvas.bounding_box()
|
||||
if box:
|
||||
print(f"📐 Canvas尺寸: {int(box['width'])}x{int(box['height'])}")
|
||||
|
||||
# 收集控制台日志
|
||||
console_logs = []
|
||||
|
||||
def on_console(msg):
|
||||
console_logs.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S"),
|
||||
"type": msg.type,
|
||||
"text": msg.text[:100] # 只取前100字符
|
||||
})
|
||||
|
||||
page.on("console", on_console)
|
||||
|
||||
# 尝试点击开始按钮
|
||||
print("🔘 尝试点击开始按钮...")
|
||||
|
||||
# 多种方式尝试点击开始
|
||||
click_success = False
|
||||
|
||||
# 方法1: 通过ID
|
||||
start_btn = page.query_selector("#start-btn")
|
||||
if start_btn:
|
||||
try:
|
||||
start_btn.click(timeout=2000)
|
||||
print("✅ 通过#start-btn点击成功")
|
||||
click_success = True
|
||||
except Exception as e:
|
||||
print(f"⚠️ #start-btn点击失败: {e}")
|
||||
|
||||
# 方法2: 通过文本
|
||||
if not click_success:
|
||||
start_btns = page.query_selector_all("button:has-text('开始')")
|
||||
if start_btns:
|
||||
try:
|
||||
start_btns[0].click(timeout=2000)
|
||||
print("✅ 通过'开始'文本点击成功")
|
||||
click_success = True
|
||||
except Exception as e:
|
||||
print(f"⚠️ '开始'文本点击失败: {e}")
|
||||
|
||||
# 方法3: 按空格键
|
||||
if not click_success:
|
||||
print("⚠️ 按钮点击失败,尝试按空格键...")
|
||||
page.keyboard.press(" ")
|
||||
|
||||
# 等待游戏运行
|
||||
print("⏳ 等待游戏运行5秒...")
|
||||
time.sleep(5)
|
||||
|
||||
# 分析日志
|
||||
spawn_count = sum(1 for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["生成", "spawn", "new piece", "方块"]))
|
||||
move_count = sum(1 for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["移动", "move", "下落", "drop", "位置"]))
|
||||
error_count = sum(1 for log in console_logs if log["type"] == "error")
|
||||
|
||||
print(f"📊 日志分析:")
|
||||
print(f" 总日志: {len(console_logs)}条")
|
||||
print(f" 方块生成: {spawn_count}次")
|
||||
print(f" 方块移动: {move_count}次")
|
||||
print(f" 错误日志: {error_count}条")
|
||||
|
||||
# 显示关键日志
|
||||
if spawn_count > 0:
|
||||
spawn_logs = [log for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["生成", "spawn", "new piece", "方块"])]
|
||||
print(f" 最后生成: {spawn_logs[-1]['text'][:60]}...")
|
||||
|
||||
if move_count > 0:
|
||||
move_logs = [log for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["移动", "move", "下落", "drop", "位置"])]
|
||||
recent_moves = move_logs[-3:] if len(move_logs) >= 3 else move_logs
|
||||
print(f" 最近移动:")
|
||||
for i, move in enumerate(recent_moves):
|
||||
print(f" {i+1}. {move['text'][:50]}...")
|
||||
|
||||
# 截图
|
||||
screenshot_path = OUTPUT_DIR / f"{version['name'].replace(' ', '_')}.png"
|
||||
page.screenshot(path=str(screenshot_path), full_page=True)
|
||||
print(f"📸 截图保存: {screenshot_path}")
|
||||
|
||||
# 判断游戏状态
|
||||
if spawn_count > 0 and move_count > 0:
|
||||
status = "🎉 完美工作"
|
||||
score = 100
|
||||
elif spawn_count > 0 and move_count == 0:
|
||||
status = "⚠️ 方块生成但不下落"
|
||||
score = 60
|
||||
elif spawn_count == 0:
|
||||
status = "❌ 方块未生成"
|
||||
score = 30
|
||||
else:
|
||||
status = "❓ 未知状态"
|
||||
score = 50
|
||||
|
||||
print(f"📈 状态: {status}")
|
||||
print(f"🏆 评分: {score}/100")
|
||||
|
||||
return {
|
||||
"version": version,
|
||||
"spawn_count": spawn_count,
|
||||
"move_count": move_count,
|
||||
"error_count": error_count,
|
||||
"total_logs": len(console_logs),
|
||||
"status": status,
|
||||
"score": score,
|
||||
"screenshot": str(screenshot_path),
|
||||
"url": url
|
||||
}
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print("🚀 俄罗斯方块快速测试开始")
|
||||
print(f"测试时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print(f"测试版本: {len(TEST_VERSIONS)}个")
|
||||
|
||||
results = []
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
|
||||
try:
|
||||
for i, version in enumerate(TEST_VERSIONS):
|
||||
print(f"\n{'#'*60}")
|
||||
print(f"测试进度: {i+1}/{len(TEST_VERSIONS)}")
|
||||
|
||||
context = browser.new_context(
|
||||
viewport={"width": 1280, "height": 720}
|
||||
)
|
||||
page = context.new_page()
|
||||
|
||||
try:
|
||||
result = test_game(page, version)
|
||||
results.append(result)
|
||||
finally:
|
||||
page.close()
|
||||
context.close()
|
||||
|
||||
# 版本间间隔
|
||||
time.sleep(1)
|
||||
|
||||
finally:
|
||||
browser.close()
|
||||
|
||||
# 生成报告
|
||||
generate_report(results)
|
||||
|
||||
print(f"\n✅ 所有测试完成!")
|
||||
print(f"📁 结果保存在: {OUTPUT_DIR}")
|
||||
|
||||
def generate_report(results):
|
||||
"""生成测试报告"""
|
||||
report_file = OUTPUT_DIR / "quick_test_report.md"
|
||||
|
||||
with open(report_file, "w", encoding="utf-8") as f:
|
||||
f.write("# 🎮 俄罗斯方块游戏快速测试报告\n\n")
|
||||
f.write(f"**测试时间**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n")
|
||||
|
||||
f.write("## 📊 测试结果\n\n")
|
||||
f.write("| 版本 | 评分 | 状态 | 方块生成 | 方块移动 | 错误数 |\n")
|
||||
f.write("|------|------|------|----------|----------|--------|\n")
|
||||
|
||||
for result in sorted(results, key=lambda x: x["score"], reverse=True):
|
||||
f.write(f"| {result['version']['name']} | ")
|
||||
f.write(f"{result['score']}/100 | {result['status']} | ")
|
||||
f.write(f"{result['spawn_count']} | {result['move_count']} | ")
|
||||
f.write(f"{result['error_count']} |\n")
|
||||
|
||||
f.write("\n## 🏆 推荐版本\n\n")
|
||||
|
||||
# 找出最佳版本
|
||||
if results:
|
||||
best_result = max(results, key=lambda x: x["score"])
|
||||
f.write(f"### 最佳版本: **{best_result['version']['name']}**\n")
|
||||
f.write(f"- **评分**: {best_result['score']}/100\n")
|
||||
f.write(f"- **状态**: {best_result['status']}\n")
|
||||
f.write(f"- **访问地址**: {best_result['url']}\n")
|
||||
f.write(f"- **截图**: {best_result['screenshot']}\n")
|
||||
|
||||
f.write("\n## 🔧 技术总结\n\n")
|
||||
|
||||
# 总结技术问题
|
||||
f.write("### 发现的问题:\n")
|
||||
|
||||
for result in results:
|
||||
if result["score"] < 80:
|
||||
f.write(f"\n#### {result['version']['name']}:\n")
|
||||
if result["spawn_count"] > 0 and result["move_count"] == 0:
|
||||
f.write("- 问题: 方块生成但不下落\n")
|
||||
f.write("- 可能原因: 游戏循环未正确启动\n")
|
||||
f.write("- 解决方案: 检查游戏循环逻辑和时间计算\n")
|
||||
elif result["spawn_count"] == 0:
|
||||
f.write("- 问题: 方块未生成\n")
|
||||
f.write("- 可能原因: 游戏初始化失败\n")
|
||||
f.write("- 解决方案: 检查游戏初始化代码\n")
|
||||
|
||||
f.write("\n## 🚀 下一步建议\n\n")
|
||||
f.write("1. **立即部署**: 使用评分最高的版本作为默认版本\n")
|
||||
f.write("2. **问题修复**: 针对问题版本进行调试\n")
|
||||
f.write("3. **兼容性测试**: 在不同浏览器和设备上测试\n")
|
||||
f.write("4. **性能优化**: 优化游戏循环和渲染性能\n")
|
||||
|
||||
print(f"📄 报告生成: {report_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
快速测试修复
|
||||
"""
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
|
||||
def quick_test():
|
||||
"""快速测试修复"""
|
||||
print("🔧 快速测试修复")
|
||||
print("=" * 50)
|
||||
|
||||
url = "http://129.211.173.87:8895/games/tetris/index.html"
|
||||
print(f"🌐 测试URL: {url}")
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
|
||||
context = browser.new_context(
|
||||
viewport={"width": 1280, "height": 720},
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
||||
)
|
||||
|
||||
page = context.new_page()
|
||||
|
||||
try:
|
||||
# 加载页面
|
||||
print("📡 加载页面...")
|
||||
page.goto(url, wait_until="networkidle", timeout=10000)
|
||||
print("✅ 页面加载成功")
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
# 收集日志
|
||||
logs = []
|
||||
page.on("console", lambda msg: logs.append({
|
||||
"type": msg.type,
|
||||
"text": msg.text
|
||||
}))
|
||||
|
||||
# 点击开始按钮
|
||||
print("🔘 点击开始按钮...")
|
||||
start_btn = page.query_selector("#start-btn")
|
||||
if start_btn:
|
||||
start_btn.click(timeout=3000)
|
||||
print("✅ 开始按钮点击成功")
|
||||
else:
|
||||
print("❌ 未找到开始按钮")
|
||||
return
|
||||
|
||||
# 等待游戏运行
|
||||
print("⏳ 等待游戏运行10秒...")
|
||||
time.sleep(10)
|
||||
|
||||
# 分析日志
|
||||
print("\n📊 日志分析:")
|
||||
|
||||
spawn_logs = [log for log in logs if "生成新方块" in log["text"]]
|
||||
move_logs = [log for log in logs if "移动方块" in log["text"]]
|
||||
error_logs = [log for log in logs if log["type"] == "error"]
|
||||
nan_logs = [log for log in logs if "NaN" in log["text"] or "undefined" in log["text"]]
|
||||
|
||||
print(f" 总日志数: {len(logs)}")
|
||||
print(f" 方块生成日志: {len(spawn_logs)}")
|
||||
print(f" 方块移动日志: {len(move_logs)}")
|
||||
print(f" 错误日志: {len(error_logs)}")
|
||||
print(f" NaN/undefined日志: {len(nan_logs)}")
|
||||
|
||||
# 显示关键日志
|
||||
if spawn_logs:
|
||||
print(f"\n🧱 方块生成记录:")
|
||||
for i, log in enumerate(spawn_logs[-5:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if move_logs:
|
||||
print(f"\n🚀 方块移动记录:")
|
||||
valid_moves = [log for log in move_logs if "移动方块到:" in log["text"]]
|
||||
for i, log in enumerate(valid_moves[-5:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if error_logs:
|
||||
print(f"\n❌ 错误记录:")
|
||||
for i, log in enumerate(error_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if nan_logs:
|
||||
print(f"\n⚠️ NaN/undefined问题:")
|
||||
for i, log in enumerate(nan_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
# 评估修复
|
||||
print("\n📈 修复评估:")
|
||||
|
||||
if len(nan_logs) == 0:
|
||||
print(" ✅ NaN/undefined问题已修复!")
|
||||
else:
|
||||
print(f" ❌ 仍有{len(nan_logs)}个NaN/undefined问题")
|
||||
|
||||
if len(spawn_logs) > 0:
|
||||
# 检查位置是否正确
|
||||
correct_positions = 0
|
||||
for log in spawn_logs:
|
||||
if "位置: (" in log["text"] and "undefined" not in log["text"]:
|
||||
correct_positions += 1
|
||||
|
||||
print(f" ✅ 方块生成正常 ({len(spawn_logs)}次)")
|
||||
print(f" 📍 正确位置: {correct_positions}/{len(spawn_logs)}")
|
||||
else:
|
||||
print(" ❌ 方块未生成")
|
||||
|
||||
if len(move_logs) > 0:
|
||||
valid_moves_count = len([log for log in move_logs if "NaN" not in log["text"]])
|
||||
print(f" ✅ 方块移动正常 ({valid_moves_count}次有效移动)")
|
||||
else:
|
||||
print(" ❌ 方块未移动")
|
||||
|
||||
# 截图
|
||||
screenshot_path = "/tmp/quick_test_fix.png"
|
||||
page.screenshot(path=screenshot_path, full_page=True)
|
||||
print(f"\n📸 截图保存: {screenshot_path}")
|
||||
|
||||
finally:
|
||||
page.close()
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
print("\n✅ 快速测试完成!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
quick_test()
|
||||
@@ -0,0 +1,256 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
简单俄罗斯方块测试脚本
|
||||
使用Playwright无头浏览器
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
# 测试配置
|
||||
BASE_URL = "http://129.211.173.87:8895/games/tetris/"
|
||||
OUTPUT_DIR = Path("/tmp/tetris_simple_test")
|
||||
OUTPUT_DIR.mkdir(exist_ok=True)
|
||||
|
||||
# 测试版本
|
||||
TEST_VERSIONS = [
|
||||
{"file": "tetris_playcanvas_working.html", "name": "PlayCanvas工作版"},
|
||||
{"file": "tetris_final_canvas2d.html", "name": "最终Canvas 2D版"},
|
||||
{"file": "tetris_simple_fall_test.html", "name": "简单下落测试版"},
|
||||
{"file": "index.html", "name": "默认版"},
|
||||
]
|
||||
|
||||
async def test_game(page, version):
|
||||
"""测试游戏基本功能"""
|
||||
print(f"\n🎮 测试: {version['name']}")
|
||||
print("-" * 50)
|
||||
|
||||
url = BASE_URL + version["file"]
|
||||
print(f"📡 URL: {url}")
|
||||
|
||||
# 导航到页面
|
||||
await page.goto(url, wait_until="networkidle", timeout=10000)
|
||||
print("✅ 页面加载成功")
|
||||
|
||||
# 等待页面初始化
|
||||
await page.wait_for_timeout(2000)
|
||||
|
||||
# 检查Canvas
|
||||
canvas_count = await page.locator("canvas").count()
|
||||
print(f"🎨 Canvas数量: {canvas_count}")
|
||||
|
||||
if canvas_count > 0:
|
||||
canvas = page.locator("canvas").first()
|
||||
box = await canvas.bounding_box()
|
||||
if box:
|
||||
print(f"📐 Canvas尺寸: {int(box['width'])}x{int(box['height'])}")
|
||||
|
||||
# 监听控制台日志
|
||||
console_logs = []
|
||||
page.on("console", lambda msg: console_logs.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S"),
|
||||
"type": msg.type,
|
||||
"text": msg.text[:100] # 只取前100字符
|
||||
}))
|
||||
|
||||
# 尝试点击开始按钮
|
||||
print("🔘 尝试点击开始按钮...")
|
||||
|
||||
# 多种方式尝试点击开始
|
||||
click_success = False
|
||||
click_methods = [
|
||||
("#start-btn", "通过ID选择器"),
|
||||
("button:has-text('开始')", "通过文本选择器"),
|
||||
("button:has-text('Start')", "通过英文文本"),
|
||||
("button:first-child", "第一个按钮"),
|
||||
]
|
||||
|
||||
for selector, method in click_methods:
|
||||
try:
|
||||
if await page.locator(selector).count() > 0:
|
||||
await page.locator(selector).first.click(timeout=2000)
|
||||
print(f"✅ {method}点击成功")
|
||||
click_success = True
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"⚠️ {method}点击失败: {e}")
|
||||
|
||||
# 如果按钮点击失败,尝试按空格键
|
||||
if not click_success:
|
||||
print("⚠️ 按钮点击失败,尝试按空格键...")
|
||||
await page.keyboard.press(" ")
|
||||
|
||||
# 等待游戏运行
|
||||
print("⏳ 等待游戏运行5秒...")
|
||||
await page.wait_for_timeout(5000)
|
||||
|
||||
# 分析日志
|
||||
spawn_count = sum(1 for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["生成", "spawn", "new piece", "方块"]))
|
||||
move_count = sum(1 for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["移动", "move", "下落", "drop", "位置"]))
|
||||
error_count = sum(1 for log in console_logs if log["type"] == "error")
|
||||
|
||||
print(f"📊 日志分析:")
|
||||
print(f" 总日志: {len(console_logs)}条")
|
||||
print(f" 方块生成: {spawn_count}次")
|
||||
print(f" 方块移动: {move_count}次")
|
||||
print(f" 错误日志: {error_count}条")
|
||||
|
||||
# 显示关键日志
|
||||
if spawn_count > 0:
|
||||
spawn_logs = [log for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["生成", "spawn", "new piece", "方块"])]
|
||||
print(f" 最后生成: {spawn_logs[-1]['text'][:60]}...")
|
||||
|
||||
if move_count > 0:
|
||||
move_logs = [log for log in console_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["移动", "move", "下落", "drop", "位置"])]
|
||||
recent_moves = move_logs[-3:] if len(move_logs) >= 3 else move_logs
|
||||
print(f" 最近移动:")
|
||||
for i, move in enumerate(recent_moves):
|
||||
print(f" {i+1}. {move['text'][:50]}...")
|
||||
|
||||
# 截图
|
||||
screenshot_path = OUTPUT_DIR / f"{version['name'].replace(' ', '_')}.png"
|
||||
await page.screenshot(path=str(screenshot_path), full_page=True)
|
||||
print(f"📸 截图保存: {screenshot_path}")
|
||||
|
||||
# 判断游戏状态
|
||||
if spawn_count > 0 and move_count > 0:
|
||||
status = "🎉 完美工作"
|
||||
score = 100
|
||||
elif spawn_count > 0 and move_count == 0:
|
||||
status = "⚠️ 方块生成但不下落"
|
||||
score = 60
|
||||
elif spawn_count == 0:
|
||||
status = "❌ 方块未生成"
|
||||
score = 30
|
||||
else:
|
||||
status = "❓ 未知状态"
|
||||
score = 50
|
||||
|
||||
print(f"📈 状态: {status}")
|
||||
print(f"🏆 评分: {score}/100")
|
||||
|
||||
return {
|
||||
"version": version,
|
||||
"spawn_count": spawn_count,
|
||||
"move_count": move_count,
|
||||
"error_count": error_count,
|
||||
"total_logs": len(console_logs),
|
||||
"status": status,
|
||||
"score": score,
|
||||
"screenshot": str(screenshot_path),
|
||||
"url": url
|
||||
}
|
||||
|
||||
async def main():
|
||||
"""主函数"""
|
||||
print("🚀 俄罗斯方块简单测试开始")
|
||||
print(f"测试时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print(f"测试版本: {len(TEST_VERSIONS)}个")
|
||||
|
||||
results = []
|
||||
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
|
||||
try:
|
||||
for i, version in enumerate(TEST_VERSIONS):
|
||||
print(f"\n{'#'*60}")
|
||||
print(f"测试进度: {i+1}/{len(TEST_VERSIONS)}")
|
||||
|
||||
context = await browser.new_context(
|
||||
viewport={"width": 1280, "height": 720}
|
||||
)
|
||||
page = await context.new_page()
|
||||
|
||||
try:
|
||||
result = await test_game(page, version)
|
||||
results.append(result)
|
||||
finally:
|
||||
await page.close()
|
||||
await context.close()
|
||||
|
||||
# 版本间间隔
|
||||
await asyncio.sleep(1)
|
||||
|
||||
finally:
|
||||
await browser.close()
|
||||
|
||||
# 生成报告
|
||||
generate_report(results)
|
||||
|
||||
print(f"\n✅ 所有测试完成!")
|
||||
print(f"📁 结果保存在: {OUTPUT_DIR}")
|
||||
|
||||
def generate_report(results):
|
||||
"""生成测试报告"""
|
||||
report_file = OUTPUT_DIR / "test_report.md"
|
||||
|
||||
with open(report_file, "w", encoding="utf-8") as f:
|
||||
f.write("# 🎮 俄罗斯方块游戏测试报告\n\n")
|
||||
f.write(f"**测试时间**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n")
|
||||
|
||||
f.write("## 📊 测试结果\n\n")
|
||||
f.write("| 版本 | 评分 | 状态 | 方块生成 | 方块移动 | 错误数 |\n")
|
||||
f.write("|------|------|------|----------|----------|--------|\n")
|
||||
|
||||
for result in sorted(results, key=lambda x: x["score"], reverse=True):
|
||||
f.write(f"| {result['version']['name']} | ")
|
||||
f.write(f"{result['score']}/100 | {result['status']} | ")
|
||||
f.write(f"{result['spawn_count']} | {result['move_count']} | ")
|
||||
f.write(f"{result['error_count']} |\n")
|
||||
|
||||
f.write("\n## 🏆 推荐版本\n\n")
|
||||
|
||||
# 找出最佳版本
|
||||
best_result = max(results, key=lambda x: x["score"])
|
||||
f.write(f"### 最佳版本: **{best_result['version']['name']}**\n")
|
||||
f.write(f"- **评分**: {best_result['score']}/100\n")
|
||||
f.write(f"- **状态**: {best_result['status']}\n")
|
||||
f.write(f"- **访问地址**: {best_result['url']}\n")
|
||||
f.write(f"- **截图**: {best_result['screenshot']}\n")
|
||||
|
||||
f.write("\n### 所有版本详情\n\n")
|
||||
for result in results:
|
||||
f.write(f"#### {result['version']['name']}\n")
|
||||
f.write(f"- 文件: `{result['version']['file']}`\n")
|
||||
f.write(f"- 评分: {result['score']}/100\n")
|
||||
f.write(f"- 状态: {result['status']}\n")
|
||||
f.write(f"- 方块生成: {result['spawn_count']}次\n")
|
||||
f.write(f"- 方块移动: {result['move_count']}次\n")
|
||||
f.write(f"- 错误数: {result['error_count']}个\n")
|
||||
f.write(f"- 访问: {result['url']}\n")
|
||||
f.write("\n")
|
||||
|
||||
f.write("## 🔧 问题分析\n\n")
|
||||
|
||||
# 分析问题
|
||||
problem_versions = [r for r in results if r["score"] < 80]
|
||||
if problem_versions:
|
||||
f.write("### 需要修复的版本:\n")
|
||||
for result in problem_versions:
|
||||
f.write(f"- **{result['version']['name']}**: {result['status']}\n")
|
||||
if result["spawn_count"] > 0 and result["move_count"] == 0:
|
||||
f.write(" - 问题: 方块生成但不下落\n")
|
||||
f.write(" - 可能原因: 游戏循环未启动或时间计算错误\n")
|
||||
elif result["spawn_count"] == 0:
|
||||
f.write(" - 问题: 方块未生成\n")
|
||||
f.write(" - 可能原因: 游戏初始化失败\n")
|
||||
f.write("\n")
|
||||
|
||||
f.write("## 🚀 建议\n\n")
|
||||
f.write("1. **立即使用**: 评分最高的版本\n")
|
||||
f.write("2. **问题修复**: 检查游戏循环逻辑\n")
|
||||
f.write("3. **兼容性**: 确保在不同浏览器上都能工作\n")
|
||||
f.write("4. **移动端**: 测试触摸控制\n")
|
||||
|
||||
print(f"📄 报告生成: {report_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,232 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>俄罗斯方块 - 所有版本测试</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background: #1a202c;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.version-card {
|
||||
background: #2d3748;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin: 20px 0;
|
||||
border-left: 5px solid;
|
||||
}
|
||||
|
||||
.version-1 { border-color: #10b981; }
|
||||
.version-2 { border-color: #f59e0b; }
|
||||
.version-3 { border-color: #3b82f6; }
|
||||
.version-4 { border-color: #8b5cf6; }
|
||||
|
||||
.version-title {
|
||||
font-size: 24px;
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.version-desc {
|
||||
color: #aaa;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.features {
|
||||
background: #4a5568;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.feature-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.test-button {
|
||||
display: inline-block;
|
||||
padding: 12px 24px;
|
||||
background: #2563eb;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 8px;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.test-button:hover {
|
||||
background: #1d4ed8;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.status {
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.status-stable { background: #10b981; }
|
||||
.status-experimental { background: #f59e0b; }
|
||||
.status-fixed { background: #3b82f6; }
|
||||
|
||||
.debug-info {
|
||||
background: #4a5568;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-top: 20px;
|
||||
font-family: monospace;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #fc8181;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: #68d391;
|
||||
}
|
||||
|
||||
.warning {
|
||||
color: #f6ad55;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🎮 俄罗斯方块 - 所有版本测试</h1>
|
||||
<p>针对Windows浏览器兼容性问题,提供了多个版本进行测试。</p>
|
||||
|
||||
<div class="debug-info">
|
||||
<div><strong>当前问题诊断:</strong></div>
|
||||
<div class="error">1. ❌ PlayCanvas版本兼容性问题 (verticesByteSize错误)</div>
|
||||
<div class="error">2. ❌ Poki SDK授权问题 (域名未授权)</div>
|
||||
<div class="error">3. ❌ resize方法不兼容 (graphicsDevice.resize不存在)</div>
|
||||
<div class="success">4. ✅ 贪吃蛇游戏可正常运行 (参考基准)</div>
|
||||
</div>
|
||||
|
||||
<div class="version-card version-1">
|
||||
<div class="version-title">
|
||||
🎯 版本1: Canvas 2D简化版
|
||||
<span class="status status-stable">推荐测试</span>
|
||||
</div>
|
||||
<div class="version-desc">使用原生Canvas 2D API,无外部依赖,兼容性最好</div>
|
||||
<div class="features">
|
||||
<div class="feature-item">✅ 纯Canvas 2D实现,无PlayCanvas依赖</div>
|
||||
<div class="feature-item">✅ 无Poki SDK授权问题</div>
|
||||
<div class="feature-item">✅ 完整的游戏逻辑和UI</div>
|
||||
<div class="feature-item">✅ 支持键盘和触摸控制</div>
|
||||
<div class="feature-item">✅ Windows浏览器兼容性最佳</div>
|
||||
</div>
|
||||
<a href="tetris_simple_canvas.html" class="test-button" target="_blank">测试此版本</a>
|
||||
</div>
|
||||
|
||||
<div class="version-card version-2">
|
||||
<div class="version-title">
|
||||
🔧 版本2: 无Poki SDK版
|
||||
<span class="status status-fixed">已修复</span>
|
||||
</div>
|
||||
<div class="version-desc">移除Poki SDK依赖,保留PlayCanvas 1.66.0版本</div>
|
||||
<div class="features">
|
||||
<div class="feature-item">✅ 使用贪吃蛇相同的PlayCanvas版本 (1.66.0)</div>
|
||||
<div class="feature-item">✅ 移除Poki SDK授权问题</div>
|
||||
<div class="feature-item">✅ 采用贪吃蛇的初始化模式</div>
|
||||
<div class="feature-item">✅ 添加错误处理</div>
|
||||
<div class="feature-item">⚠️ 仍可能有PlayCanvas兼容性问题</div>
|
||||
</div>
|
||||
<a href="tetris_no_poki.html" class="test-button" target="_blank">测试此版本</a>
|
||||
</div>
|
||||
|
||||
<div class="version-card version-3">
|
||||
<div class="version-title">
|
||||
🎮 版本3: 原始修复版
|
||||
<span class="status status-experimental">实验性</span>
|
||||
</div>
|
||||
<div class="version-desc">原始游戏页面的修复版本,尝试解决所有问题</div>
|
||||
<div class="features">
|
||||
<div class="feature-item">✅ 使用PlayCanvas 1.66.0固定版本</div>
|
||||
<div class="feature-item">✅ 添加crypto.randomUUID兼容性修复</div>
|
||||
<div class="feature-item">✅ 修复resize方法兼容性</div>
|
||||
<div class="feature-item">⚠️ 仍有Poki SDK授权警告</div>
|
||||
<div class="feature-item">⚠️ 需要清除浏览器缓存</div>
|
||||
</div>
|
||||
<a href="index_fixed.html" class="test-button" target="_blank">测试此版本</a>
|
||||
</div>
|
||||
|
||||
<div class="version-card version-4">
|
||||
<div class="version-title">
|
||||
📱 版本4: 原始游戏页面
|
||||
<span class="status status-experimental">有问题</span>
|
||||
</div>
|
||||
<div class="version-desc">原始游戏页面,包含所有已知问题</div>
|
||||
<div class="features">
|
||||
<div class="feature-item">❌ PlayCanvas版本兼容性问题</div>
|
||||
<div class="feature-item">❌ Poki SDK授权警告</div>
|
||||
<div class="feature-item">❌ resize方法错误</div>
|
||||
<div class="feature-item">⚠️ 需要强制清除浏览器缓存</div>
|
||||
<div class="feature-item">⚠️ 仅用于对比测试</div>
|
||||
</div>
|
||||
<a href="index.html" class="test-button" target="_blank">测试此版本</a>
|
||||
</div>
|
||||
|
||||
<div class="debug-info">
|
||||
<div><strong>测试建议:</strong></div>
|
||||
<div class="success">1. 首先测试 <strong>版本1 (Canvas 2D简化版)</strong> - 应该能正常工作</div>
|
||||
<div class="success">2. 然后测试 <strong>版本2 (无Poki SDK版)</strong> - 检查PlayCanvas兼容性</div>
|
||||
<div class="warning">3. 最后测试 <strong>版本3 (原始修复版)</strong> - 验证完整修复</div>
|
||||
<div class="error">4. 对比测试 <strong>版本4 (原始游戏页面)</strong> - 查看原始问题</div>
|
||||
<br>
|
||||
<div><strong>Windows浏览器操作:</strong></div>
|
||||
<div>1. 按 <strong>F12</strong> 打开开发者工具</div>
|
||||
<div>2. 点击 <strong>Console</strong> 标签查看错误</div>
|
||||
<div>3. 按 <strong>Ctrl+Shift+R</strong> 强制刷新页面(清除缓存)</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 环境检测
|
||||
console.log('🎮 俄罗斯方块测试页面');
|
||||
console.log('🌐 用户代理:', navigator.userAgent);
|
||||
console.log('🖥️ 平台:', navigator.platform);
|
||||
console.log('🔧 浏览器特性检测:');
|
||||
|
||||
const tests = {
|
||||
'Canvas支持': !!document.createElement('canvas').getContext,
|
||||
'requestAnimationFrame': !!window.requestAnimationFrame,
|
||||
'crypto.randomUUID': !!window.crypto?.randomUUID,
|
||||
'PlayCanvas加载': typeof pc !== 'undefined',
|
||||
'控制台可用': typeof console !== 'undefined'
|
||||
};
|
||||
|
||||
Object.entries(tests).forEach(([name, result]) => {
|
||||
console.log(`${result ? '✅' : '❌'} ${name}: ${result}`);
|
||||
});
|
||||
|
||||
// 显示环境信息
|
||||
const envInfo = document.createElement('div');
|
||||
envInfo.className = 'debug-info';
|
||||
envInfo.innerHTML = `
|
||||
<div><strong>当前浏览器环境:</strong></div>
|
||||
<div>🌐 ${navigator.userAgent}</div>
|
||||
<div>🖥️ 平台: ${navigator.platform}</div>
|
||||
<div>✅ Canvas支持: ${tests['Canvas支持'] ? '是' : '否'}</div>
|
||||
<div>✅ requestAnimationFrame: ${tests['requestAnimationFrame'] ? '是' : '否'}</div>
|
||||
<div>✅ crypto.randomUUID: ${tests['crypto.randomUUID'] ? '是' : '否'}</div>
|
||||
<div>⚠️ PlayCanvas加载: ${tests['PlayCanvas加载'] ? '是 (可能缓存)' : '否'}</div>
|
||||
`;
|
||||
document.body.appendChild(envInfo);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,344 @@
|
||||
const { chromium } = require('playwright');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 测试配置
|
||||
const BASE_URL = 'http://129.211.173.87:8895/games/tetris/';
|
||||
const TEST_VERSIONS = [
|
||||
{ file: 'tetris_final_canvas2d.html', name: '最终Canvas 2D版', expected: '工作' },
|
||||
{ file: 'tetris_simple_fall_test.html', name: '简单下落测试版', expected: '工作' },
|
||||
{ file: 'tetris_playcanvas_working.html', name: 'PlayCanvas工作版', expected: '可能工作' },
|
||||
{ file: 'index.html', name: '默认版', expected: '可能失败' },
|
||||
];
|
||||
|
||||
async function testGameVersion(browser, version) {
|
||||
console.log(`\n🎮 测试: ${version.name} (${version.file})`);
|
||||
console.log('='.repeat(60));
|
||||
|
||||
const page = await browser.newPage();
|
||||
const logs = [];
|
||||
const errors = [];
|
||||
|
||||
try {
|
||||
// 页面事件监听
|
||||
page.on('console', msg => {
|
||||
logs.push(`[${msg.type()}] ${msg.text()}`);
|
||||
if (msg.type() === 'error') {
|
||||
errors.push(msg.text());
|
||||
}
|
||||
});
|
||||
|
||||
page.on('pageerror', error => {
|
||||
errors.push(`页面错误: ${error.message}`);
|
||||
});
|
||||
|
||||
// 导航到页面
|
||||
const url = BASE_URL + version.file;
|
||||
console.log(`📡 访问: ${url}`);
|
||||
|
||||
await page.goto(url, { waitUntil: 'networkidle', timeout: 10000 });
|
||||
console.log('✅ 页面加载成功');
|
||||
|
||||
// 等待页面完全加载
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
// 检查Canvas
|
||||
const canvasCount = await page.locator('canvas').count();
|
||||
console.log(`🎨 Canvas数量: ${canvasCount}`);
|
||||
|
||||
if (canvasCount === 0) {
|
||||
console.log('❌ 未找到Canvas元素');
|
||||
return { ...version, status: '失败', reason: '未找到Canvas' };
|
||||
}
|
||||
|
||||
// 获取Canvas信息
|
||||
const canvas = page.locator('canvas').first();
|
||||
const canvasBox = await canvas.boundingBox();
|
||||
console.log(`📐 Canvas尺寸: ${canvasBox?.width || '未知'}x${canvasBox?.height || '未知'}`);
|
||||
|
||||
// 检查按钮
|
||||
const buttonSelectors = ['#start-btn', 'button:has-text("开始")', 'button:has-text("Start")', 'button'];
|
||||
let startButton = null;
|
||||
|
||||
for (const selector of buttonSelectors) {
|
||||
if (await page.locator(selector).count() > 0) {
|
||||
startButton = page.locator(selector).first();
|
||||
console.log(`🔘 找到按钮: ${selector}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!startButton) {
|
||||
console.log('⚠️ 未找到开始按钮,尝试按空格键');
|
||||
await page.keyboard.press(' ');
|
||||
} else {
|
||||
// 点击开始按钮
|
||||
await startButton.click();
|
||||
console.log('✅ 点击开始按钮');
|
||||
}
|
||||
|
||||
// 等待游戏开始
|
||||
await page.waitForTimeout(3000);
|
||||
|
||||
// 分析日志
|
||||
const spawnLogs = logs.filter(log =>
|
||||
log.includes('生成') ||
|
||||
log.includes('spawn') ||
|
||||
log.includes('方块') ||
|
||||
log.includes('piece')
|
||||
);
|
||||
|
||||
const moveLogs = logs.filter(log =>
|
||||
log.includes('移动') ||
|
||||
log.includes('move') ||
|
||||
log.includes('下落') ||
|
||||
log.includes('drop') ||
|
||||
log.includes('位置')
|
||||
);
|
||||
|
||||
console.log(`📊 方块生成日志: ${spawnLogs.length}条`);
|
||||
console.log(`📊 方块移动日志: ${moveLogs.length}条`);
|
||||
|
||||
// 显示关键日志
|
||||
if (spawnLogs.length > 0) {
|
||||
console.log(`📝 生成日志: ${spawnLogs[0]}`);
|
||||
}
|
||||
|
||||
if (moveLogs.length > 0) {
|
||||
console.log(`📝 移动日志: ${moveLogs.slice(0, 3).join(' | ')}`);
|
||||
}
|
||||
|
||||
// 检查错误
|
||||
if (errors.length > 0) {
|
||||
console.log(`⚠️ 发现错误: ${errors.length}个`);
|
||||
errors.slice(0, 3).forEach(err => console.log(` - ${err}`));
|
||||
}
|
||||
|
||||
// 截图
|
||||
const screenshotDir = '/tmp/tetris_tests';
|
||||
if (!fs.existsSync(screenshotDir)) {
|
||||
fs.mkdirSync(screenshotDir, { recursive: true });
|
||||
}
|
||||
|
||||
const screenshotPath = path.join(screenshotDir, `${version.name.replace(/\s+/g, '_')}.png`);
|
||||
await page.screenshot({ path: screenshotPath, fullPage: true });
|
||||
console.log(`📸 截图保存: ${screenshotPath}`);
|
||||
|
||||
// 判断测试结果
|
||||
let status = '未知';
|
||||
let reason = '';
|
||||
|
||||
if (errors.length > 5) {
|
||||
status = '失败';
|
||||
reason = `发现${errors.length}个错误`;
|
||||
} else if (spawnLogs.length === 0) {
|
||||
status = '失败';
|
||||
reason = '方块未生成';
|
||||
} else if (moveLogs.length === 0) {
|
||||
status = '部分工作';
|
||||
reason = '方块生成但未移动';
|
||||
} else {
|
||||
status = '成功';
|
||||
reason = `方块生成并移动${moveLogs.length}次`;
|
||||
}
|
||||
|
||||
console.log(`📈 测试结果: ${status} - ${reason}`);
|
||||
|
||||
return {
|
||||
...version,
|
||||
status,
|
||||
reason,
|
||||
canvasCount,
|
||||
canvasSize: canvasBox ? `${canvasBox.width}x${canvasBox.height}` : '未知',
|
||||
spawnLogs: spawnLogs.length,
|
||||
moveLogs: moveLogs.length,
|
||||
errors: errors.length,
|
||||
screenshot: screenshotPath,
|
||||
logs: logs.slice(-10) // 最后10条日志
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.log(`❌ 测试异常: ${error.message}`);
|
||||
return {
|
||||
...version,
|
||||
status: '异常',
|
||||
reason: error.message,
|
||||
errors: 1
|
||||
};
|
||||
} finally {
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('🚀 开始全面测试俄罗斯方块游戏');
|
||||
console.log(`测试时间: ${new Date().toLocaleString()}`);
|
||||
console.log(`基础URL: ${BASE_URL}`);
|
||||
console.log('='.repeat(80));
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
});
|
||||
|
||||
const results = [];
|
||||
|
||||
try {
|
||||
// 测试每个版本
|
||||
for (const version of TEST_VERSIONS) {
|
||||
const result = await testGameVersion(browser, version);
|
||||
results.push(result);
|
||||
|
||||
// 版本间间隔
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
|
||||
// 生成测试报告
|
||||
console.log('\n' + '='.repeat(80));
|
||||
console.log('📋 俄罗斯方块游戏测试报告');
|
||||
console.log('='.repeat(80));
|
||||
|
||||
const successful = results.filter(r => r.status === '成功');
|
||||
const failed = results.filter(r => r.status !== '成功');
|
||||
|
||||
console.log(`\n✅ 成功版本 (${successful.length}/${results.length}):`);
|
||||
successful.forEach(result => {
|
||||
console.log(` 🏆 ${result.name}`);
|
||||
console.log(` 文件: ${result.file}`);
|
||||
console.log(` Canvas: ${result.canvasSize}`);
|
||||
console.log(` 生成: ${result.spawnLogs}次, 移动: ${result.moveLogs}次`);
|
||||
console.log(` 错误: ${result.errors}个`);
|
||||
console.log(` 截图: ${result.screenshot}`);
|
||||
console.log('');
|
||||
});
|
||||
|
||||
if (failed.length > 0) {
|
||||
console.log(`\n❌ 失败版本 (${failed.length}/${results.length}):`);
|
||||
failed.forEach(result => {
|
||||
console.log(` ⚠️ ${result.name}`);
|
||||
console.log(` 状态: ${result.status}`);
|
||||
console.log(` 原因: ${result.reason}`);
|
||||
console.log(` 错误: ${result.errors}个`);
|
||||
console.log('');
|
||||
});
|
||||
}
|
||||
|
||||
// 推荐最佳版本
|
||||
if (successful.length > 0) {
|
||||
const bestVersion = successful.reduce((best, current) => {
|
||||
// 优先选择移动次数多的版本
|
||||
if (current.moveLogs > (best.moveLogs || 0)) {
|
||||
return current;
|
||||
}
|
||||
return best;
|
||||
});
|
||||
|
||||
console.log('\n' + '='.repeat(80));
|
||||
console.log('🎯 推荐使用版本');
|
||||
console.log('='.repeat(80));
|
||||
console.log(`🏆 ${bestVersion.name}`);
|
||||
console.log(`📁 文件: ${bestVersion.file}`);
|
||||
console.log(`🌐 访问: ${BASE_URL}${bestVersion.file}`);
|
||||
console.log(`📊 测试结果: ${bestVersion.spawnLogs}次生成, ${bestVersion.moveLogs}次移动`);
|
||||
console.log(`📸 截图: ${bestVersion.screenshot}`);
|
||||
|
||||
// 生成HTML报告
|
||||
generateHtmlReport(results, bestVersion);
|
||||
} else {
|
||||
console.log('\n⚠️ 警告: 没有找到完全成功的版本!');
|
||||
}
|
||||
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
}
|
||||
|
||||
function generateHtmlReport(results, bestVersion) {
|
||||
const reportDir = '/tmp/tetris_tests';
|
||||
const reportPath = path.join(reportDir, 'test_report.html');
|
||||
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>俄罗斯方块游戏测试报告</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
|
||||
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
|
||||
h1 { color: #333; border-bottom: 2px solid #4CAF50; padding-bottom: 10px; }
|
||||
h2 { color: #555; margin-top: 30px; }
|
||||
.summary { background: #e8f5e9; padding: 15px; border-radius: 5px; margin: 20px 0; }
|
||||
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; margin: 20px 0; }
|
||||
.card { border: 1px solid #ddd; border-radius: 5px; padding: 15px; }
|
||||
.card.success { border-left: 5px solid #4CAF50; }
|
||||
.card.failed { border-left: 5px solid #f44336; }
|
||||
.card.partial { border-left: 5px solid #ff9800; }
|
||||
.status { font-weight: bold; padding: 3px 8px; border-radius: 3px; display: inline-block; }
|
||||
.status-success { background: #4CAF50; color: white; }
|
||||
.status-failed { background: #f44336; color: white; }
|
||||
.status-partial { background: #ff9800; color: white; }
|
||||
.screenshot { max-width: 100%; height: auto; border: 1px solid #ddd; margin-top: 10px; }
|
||||
.recommendation { background: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; border-radius: 5px; margin: 20px 0; }
|
||||
.log { background: #f8f9fa; padding: 10px; border-radius: 3px; font-family: monospace; font-size: 12px; max-height: 200px; overflow-y: auto; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🎮 俄罗斯方块游戏测试报告</h1>
|
||||
<p>测试时间: ${new Date().toLocaleString()}</p>
|
||||
|
||||
<div class="summary">
|
||||
<h2>📊 测试摘要</h2>
|
||||
<p>测试版本数: ${results.length}</p>
|
||||
<p>成功版本: ${results.filter(r => r.status === '成功').length}</p>
|
||||
<p>失败版本: ${results.filter(r => r.status !== '成功').length}</p>
|
||||
</div>
|
||||
|
||||
<div class="recommendation">
|
||||
<h2>🏆 推荐版本</h2>
|
||||
<h3>${bestVersion.name}</h3>
|
||||
<p><strong>文件:</strong> ${bestVersion.file}</p>
|
||||
<p><strong>访问地址:</strong> <a href="${BASE_URL}${bestVersion.file}" target="_blank">${BASE_URL}${bestVersion.file}</a></p>
|
||||
<p><strong>测试结果:</strong> ${bestVersion.spawnLogs}次方块生成, ${bestVersion.moveLogs}次方块移动</p>
|
||||
<p><strong>Canvas尺寸:</strong> ${bestVersion.canvasSize}</p>
|
||||
${bestVersion.screenshot ? `<img src="file://${bestVersion.screenshot}" alt="${bestVersion.name}截图" class="screenshot">` : ''}
|
||||
</div>
|
||||
|
||||
<h2>📋 详细测试结果</h2>
|
||||
<div class="result-grid">
|
||||
${results.map(result => `
|
||||
<div class="card ${result.status === '成功' ? 'success' : result.status === '部分工作' ? 'partial' : 'failed'}">
|
||||
<h3>${result.name}</h3>
|
||||
<p><strong>状态:</strong> <span class="status status-${result.status === '成功' ? 'success' : result.status === '部分工作' ? 'partial' : 'failed'}">${result.status}</span></p>
|
||||
<p><strong>文件:</strong> ${result.file}</p>
|
||||
<p><strong>Canvas:</strong> ${result.canvasSize || '未找到'}</p>
|
||||
<p><strong>方块生成:</strong> ${result.spawnLogs || 0}次</p>
|
||||
<p><strong>方块移动:</strong> ${result.moveLogs || 0}次</p>
|
||||
<p><strong>错误:</strong> ${result.errors || 0}个</p>
|
||||
<p><strong>原因:</strong> ${result.reason || '无'}</p>
|
||||
${result.screenshot ? `<img src="file://${result.screenshot}" alt="${result.name}截图" class="screenshot">` : ''}
|
||||
${result.logs ? `<div class="log">${result.logs.slice(-5).join('<br>')}</div>` : ''}
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
|
||||
<h2>🔧 测试环境</h2>
|
||||
<ul>
|
||||
<li>测试工具: Playwright 1.58.0</li>
|
||||
<li>浏览器: Chromium</li>
|
||||
<li>测试模式: Headless</li>
|
||||
<li>基础URL: ${BASE_URL}</li>
|
||||
<li>截图保存: /tmp/tetris_tests/</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
fs.writeFileSync(reportPath, html);
|
||||
console.log(`📄 HTML报告生成: ${reportPath}`);
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试修复后的最终Canvas 2D版
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
import time
|
||||
|
||||
async def test_final_version():
|
||||
"""测试最终Canvas 2D版"""
|
||||
print("🎮 测试修复后的最终Canvas 2D版")
|
||||
print("="*60)
|
||||
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
context = await browser.new_context(
|
||||
viewport={'width': 1280, 'height': 720},
|
||||
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
||||
)
|
||||
|
||||
page = await context.new_page()
|
||||
|
||||
try:
|
||||
# 导航到页面
|
||||
await page.goto("http://129.211.173.87:8895/games/tetris/tetris_final_canvas2d.html", timeout=10000)
|
||||
print("✅ 页面加载成功")
|
||||
|
||||
# 等待页面完全加载
|
||||
await page.wait_for_load_state('networkidle', timeout=5000)
|
||||
|
||||
# 捕获控制台日志
|
||||
console_logs = []
|
||||
|
||||
def handle_console(msg):
|
||||
console_logs.append(msg.text)
|
||||
print(f" 控制台: {msg.text}")
|
||||
|
||||
page.on('console', handle_console)
|
||||
|
||||
# 检查Canvas
|
||||
canvas_count = await page.locator('canvas').count()
|
||||
print(f"✅ Canvas数量: {canvas_count}")
|
||||
|
||||
if canvas_count > 0:
|
||||
canvas = page.locator('canvas').first
|
||||
canvas_size = await canvas.bounding_box()
|
||||
if canvas_size:
|
||||
print(f"✅ Canvas尺寸: {canvas_size['width']}x{canvas_size['height']}")
|
||||
|
||||
# 点击开始按钮
|
||||
await page.locator('#start-btn').click(timeout=3000)
|
||||
print("✅ 点击开始按钮")
|
||||
|
||||
# 等待游戏开始
|
||||
await asyncio.sleep(2)
|
||||
|
||||
# 检查日志
|
||||
spawn_logs = [log for log in console_logs if '生成新方块' in log]
|
||||
move_logs = [log for log in console_logs if '移动方块到' in log]
|
||||
|
||||
if spawn_logs:
|
||||
print(f"✅ 方块生成: {spawn_logs[-1]}")
|
||||
else:
|
||||
print("❌ 未检测到方块生成")
|
||||
|
||||
if move_logs:
|
||||
print(f"✅ 方块移动: {len(move_logs)}次")
|
||||
for i, log in enumerate(move_logs[:3]): # 显示前3次移动
|
||||
print(f" 移动{i+1}: {log}")
|
||||
else:
|
||||
print("❌ 未检测到方块移动")
|
||||
|
||||
# 等待更多移动
|
||||
await asyncio.sleep(3)
|
||||
|
||||
# 检查是否有更多移动
|
||||
move_logs = [log for log in console_logs if '移动方块到' in log]
|
||||
print(f"✅ 总移动次数: {len(move_logs)}")
|
||||
|
||||
# 检查位置是否正确
|
||||
valid_positions = [log for log in move_logs if 'NaN' not in log]
|
||||
if valid_positions:
|
||||
print(f"✅ 有效位置: {len(valid_positions)}/{len(move_logs)}")
|
||||
print(f" 示例: {valid_positions[-1]}")
|
||||
else:
|
||||
print("⚠️ 所有位置都是NaN,需要进一步调试")
|
||||
|
||||
# 截图
|
||||
screenshot_path = "/tmp/test_final_fixed.png"
|
||||
await page.screenshot(path=screenshot_path, full_page=True)
|
||||
print(f"✅ 截图保存: {screenshot_path}")
|
||||
|
||||
# 显示所有相关日志
|
||||
print("\n📋 相关日志:")
|
||||
for log in console_logs:
|
||||
if any(keyword in log for keyword in ['生成', '移动', 'Canvas', '初始化', '开始']):
|
||||
print(f" {log}")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 测试失败: {str(e)}")
|
||||
return False
|
||||
|
||||
finally:
|
||||
await browser.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = asyncio.run(test_final_version())
|
||||
if success:
|
||||
print("\n🎉 测试成功!最终Canvas 2D版工作正常!")
|
||||
print("访问: http://129.211.173.87:8895/games/tetris/tetris_final_canvas2d.html")
|
||||
else:
|
||||
print("\n⚠️ 测试失败,需要进一步调试")
|
||||
@@ -0,0 +1,342 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>🎮 俄罗斯方块 - 游戏循环测试</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
background: #0a0a1a;
|
||||
color: white;
|
||||
font-family: monospace;
|
||||
padding: 20px;
|
||||
}
|
||||
canvas {
|
||||
border: 2px solid white;
|
||||
background: #111827;
|
||||
display: block;
|
||||
margin: 20px auto;
|
||||
}
|
||||
.info {
|
||||
text-align: center;
|
||||
margin: 20px;
|
||||
}
|
||||
.debug {
|
||||
background: black;
|
||||
color: lime;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin: 10px auto;
|
||||
max-width: 600px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
background: #00d4ff;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
margin: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="info">
|
||||
<h1>🎮 俄罗斯方块 - 游戏循环测试</h1>
|
||||
<p>测试游戏循环是否正常工作</p>
|
||||
</div>
|
||||
|
||||
<canvas id="game-canvas" width="240" height="480"></canvas>
|
||||
|
||||
<div class="info">
|
||||
<button onclick="startGame()">▶️ 开始游戏</button>
|
||||
<button onclick="pauseGame()">⏸️ 暂停</button>
|
||||
<button onclick="resetGame()">🔄 重置</button>
|
||||
</div>
|
||||
|
||||
<div class="debug" id="debug">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 调试日志
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// 游戏配置
|
||||
const canvas = document.getElementById('game-canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
const gridWidth = 10;
|
||||
const gridHeight = 20;
|
||||
const cellSize = 24;
|
||||
|
||||
let board = Array(gridHeight).fill().map(() => Array(gridWidth).fill(0));
|
||||
let currentPiece = null;
|
||||
let gameLoop = null;
|
||||
let dropTimer = 0;
|
||||
let lastFrameTime = 0;
|
||||
let isPaused = false;
|
||||
let isGameOver = false;
|
||||
|
||||
// 方块类型
|
||||
const pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' }
|
||||
];
|
||||
|
||||
// 游戏函数
|
||||
function spawnNewPiece() {
|
||||
const randomType = pieceTypes[Math.floor(Math.random() * pieceTypes.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type}`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= gridWidth || newY >= gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || isPaused || isGameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
lockPiece();
|
||||
spawnNewPiece();
|
||||
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function gameOver() {
|
||||
isGameOver = true;
|
||||
if (gameLoop) {
|
||||
cancelAnimationFrame(gameLoop);
|
||||
gameLoop = null;
|
||||
}
|
||||
|
||||
debugLog(`游戏结束!`);
|
||||
}
|
||||
|
||||
// 渲染函数
|
||||
function render() {
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= gridWidth; x++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x * cellSize, 0);
|
||||
ctx.lineTo(x * cellSize, canvas.height);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= gridHeight; y++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, y * cellSize);
|
||||
ctx.lineTo(canvas.width, y * cellSize);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < gridHeight; y++) {
|
||||
for (let x = 0; x < gridWidth; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
ctx.fillRect((x + col) * cellSize, (y + row) * cellSize, cellSize, cellSize);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect((x + col) * cellSize, (y + row) * cellSize, cellSize, cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 游戏循环
|
||||
function startGameLoop() {
|
||||
if (gameLoop) {
|
||||
cancelAnimationFrame(gameLoop);
|
||||
}
|
||||
|
||||
const loop = (timestamp) => {
|
||||
if (!lastFrameTime) lastFrameTime = timestamp;
|
||||
|
||||
const deltaTime = timestamp - lastFrameTime;
|
||||
|
||||
// 自动下落
|
||||
if (!isPaused && !isGameOver) {
|
||||
dropTimer += deltaTime;
|
||||
|
||||
if (dropTimer > 1000) { // 每秒下落一次
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
debugLog('方块自动下落');
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染
|
||||
render();
|
||||
|
||||
// 继续循环
|
||||
gameLoop = requestAnimationFrame(loop);
|
||||
lastFrameTime = timestamp;
|
||||
};
|
||||
|
||||
gameLoop = requestAnimationFrame(loop);
|
||||
debugLog('✅ 游戏循环已启动');
|
||||
}
|
||||
|
||||
// 控制函数
|
||||
window.startGame = function() {
|
||||
debugLog('🎮 开始游戏...');
|
||||
|
||||
// 重置游戏状态
|
||||
board = Array(gridHeight).fill().map(() => Array(gridWidth).fill(0));
|
||||
isPaused = false;
|
||||
isGameOver = false;
|
||||
dropTimer = 0;
|
||||
lastFrameTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
startGameLoop();
|
||||
|
||||
debugLog('✅ 游戏开始!');
|
||||
};
|
||||
|
||||
window.pauseGame = function() {
|
||||
isPaused = !isPaused;
|
||||
debugLog(isPaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
};
|
||||
|
||||
window.resetGame = function() {
|
||||
debugLog('🔄 重置游戏');
|
||||
startGame();
|
||||
};
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (!currentPiece || isPaused || isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
debugLog('← 左移');
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
debugLog('→ 右移');
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
debugLog('↓ 下移');
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
// 旋转
|
||||
debugLog('↑ 旋转');
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// 页面加载完成
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 自动开始游戏
|
||||
setTimeout(() => {
|
||||
startGame();
|
||||
}, 1000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,417 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>俄罗斯方块模拟测试</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#game-container {
|
||||
width: 540px;
|
||||
height: 720px;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.game-canvas {
|
||||
width: 500px;
|
||||
height: 400px;
|
||||
background: #111827;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #fff;
|
||||
font-size: 24px;
|
||||
border: 2px solid #2563eb;
|
||||
}
|
||||
|
||||
.controls-container {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.debug-panel {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<div class="game-canvas" id="game-canvas">
|
||||
🎮 俄罗斯方块模拟测试
|
||||
</div>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-panel" id="debug-panel">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 游戏状态
|
||||
let gameState = {
|
||||
score: 0,
|
||||
level: 0,
|
||||
lines: 0,
|
||||
speed: 1.0,
|
||||
isPaused: true,
|
||||
isGameOver: false,
|
||||
currentPiece: null
|
||||
};
|
||||
|
||||
// 调试日志
|
||||
function debugLog(message) {
|
||||
const debugPanel = document.getElementById('debug-panel');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugPanel.appendChild(logEntry);
|
||||
debugPanel.scrollTop = debugPanel.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// 显示状态消息
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// 更新UI
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = gameState.score;
|
||||
document.getElementById('level').textContent = gameState.level;
|
||||
document.getElementById('lines').textContent = gameState.lines;
|
||||
document.getElementById('speed').textContent = gameState.speed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!gameState.currentPiece && !gameState.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (gameState.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (gameState.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
// 游戏控制函数
|
||||
function initGame() {
|
||||
gameState = {
|
||||
score: 0,
|
||||
level: 0,
|
||||
lines: 0,
|
||||
speed: 1.0,
|
||||
isPaused: false,
|
||||
isGameOver: false,
|
||||
currentPiece: { type: 'I', x: 5, y: 0 }
|
||||
};
|
||||
updateUI();
|
||||
showStatus('🎮 游戏开始!');
|
||||
debugLog('游戏初始化完成');
|
||||
}
|
||||
|
||||
function togglePause() {
|
||||
gameState.isPaused = !gameState.isPaused;
|
||||
showStatus(gameState.isPaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
debugLog(`游戏${gameState.isPaused ? '暂停' : '继续'}`);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (gameState.isPaused || gameState.isGameOver) return;
|
||||
debugLog(`移动方块: dx=${dx}, dy=${dy}`);
|
||||
showStatus(`移动: ${dx > 0 ? '右' : dx < 0 ? '左' : ''}${dy > 0 ? '下' : ''}`);
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (gameState.isPaused || gameState.isGameOver) return;
|
||||
debugLog('旋转方块');
|
||||
showStatus('旋转方块');
|
||||
}
|
||||
|
||||
// 按钮事件绑定
|
||||
function setupControls() {
|
||||
debugLog('开始设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
debugLog('开始按钮被点击');
|
||||
if (!gameState.currentPiece && !gameState.isGameOver) {
|
||||
initGame();
|
||||
} else if (gameState.isPaused) {
|
||||
togglePause();
|
||||
} else if (gameState.isGameOver) {
|
||||
initGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
debugLog('重来按钮被点击');
|
||||
initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
debugLog('左按钮被点击');
|
||||
movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
debugLog('右按钮被点击');
|
||||
movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
debugLog('下按钮被点击');
|
||||
movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
debugLog('旋转按钮被点击');
|
||||
rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key} (keyCode: ${e.keyCode})`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameState.currentPiece && !gameState.isGameOver) {
|
||||
initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameState.isPaused || gameState.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
// 页面加载完成
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`用户代理: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
debugLog(`语言: ${navigator.language}`);
|
||||
|
||||
setupControls();
|
||||
updateUI();
|
||||
|
||||
showStatus('✅ 模拟测试已加载,点击按钮测试功能', 3000);
|
||||
});
|
||||
|
||||
// 添加按钮按下效果
|
||||
document.querySelectorAll('.action-button, .control-button').forEach(btn => {
|
||||
btn.addEventListener('mousedown', () => {
|
||||
btn.style.transform = 'scale(0.95)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseup', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,143 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>俄罗斯方块键盘控制测试</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background: #1a202c;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
background: #2d3748;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
margin: 10px 0;
|
||||
padding: 10px;
|
||||
background: #4a5568;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: #68d391;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #fc8181;
|
||||
}
|
||||
|
||||
.key {
|
||||
display: inline-block;
|
||||
padding: 5px 10px;
|
||||
background: #718096;
|
||||
border-radius: 3px;
|
||||
margin: 0 5px;
|
||||
font-family: monospace;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🎮 俄罗斯方块键盘控制测试</h1>
|
||||
|
||||
<div class="test-container">
|
||||
<h2>测试步骤</h2>
|
||||
|
||||
<div class="test-item">
|
||||
<h3>1. 打开游戏页面</h3>
|
||||
<p>访问: <a href="http://129.211.173.87:8895/games/tetris/" target="_blank">http://129.211.173.87:8895/games/tetris/</a></p>
|
||||
</div>
|
||||
|
||||
<div class="test-item">
|
||||
<h3>2. 测试键盘控制</h3>
|
||||
<p>按以下键测试功能:</p>
|
||||
<ul>
|
||||
<li><span class="key">←</span> 左箭头 - 方块向左移动</li>
|
||||
<li><span class="key">→</span> 右箭头 - 方块向右移动</li>
|
||||
<li><span class="key">↓</span> 下箭头 - 方块加速下落</li>
|
||||
<li><span class="key">↑</span> 或 <span class="key">空格</span> - 方块旋转</li>
|
||||
<li><span class="key">P</span> - 暂停/继续游戏</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="test-item">
|
||||
<h3>3. 自动开始功能</h3>
|
||||
<p>游戏初始状态:显示"开始"按钮</p>
|
||||
<p>按任意方向键或空格键 → 游戏自动开始</p>
|
||||
<p>按"开始"按钮 → 游戏开始</p>
|
||||
</div>
|
||||
|
||||
<div class="test-item">
|
||||
<h3>4. 按钮状态验证</h3>
|
||||
<p>游戏运行中 → 按钮显示"暂停"</p>
|
||||
<p>游戏暂停 → 按钮显示"继续"</p>
|
||||
<p>游戏结束 → 按钮显示"重新开始"</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-container">
|
||||
<h2>预期结果</h2>
|
||||
<div class="test-item success">
|
||||
✅ 键盘控制正常响应
|
||||
</div>
|
||||
<div class="test-item success">
|
||||
✅ 按任意键自动开始游戏
|
||||
</div>
|
||||
<div class="test-item success">
|
||||
✅ 按钮状态正确显示
|
||||
</div>
|
||||
<div class="test-item success">
|
||||
✅ 游戏逻辑正常运行
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-container">
|
||||
<h2>问题排查</h2>
|
||||
<div class="test-item">
|
||||
<h3>如果键盘控制无效:</h3>
|
||||
<ol>
|
||||
<li>检查游戏是否已开始(按"开始"按钮)</li>
|
||||
<li>检查游戏是否暂停(按P键继续)</li>
|
||||
<li>刷新页面重新加载</li>
|
||||
<li>检查浏览器控制台是否有错误</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<div class="test-item">
|
||||
<h3>技术支持</h3>
|
||||
<p>如果问题持续存在,请提供以下信息:</p>
|
||||
<ul>
|
||||
<li>浏览器类型和版本</li>
|
||||
<li>操作系统</li>
|
||||
<li>控制台错误信息(按F12打开开发者工具)</li>
|
||||
<li>具体操作步骤</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 简单的键盘测试
|
||||
document.addEventListener('keydown', (e) => {
|
||||
console.log(`按键测试: ${e.key} (keyCode: ${e.keyCode})`);
|
||||
|
||||
// 显示按键反馈
|
||||
const feedback = document.createElement('div');
|
||||
feedback.className = 'test-item';
|
||||
feedback.innerHTML = `<span class="key">${e.key}</span> 键已按下`;
|
||||
document.querySelector('.test-container:last-child').appendChild(feedback);
|
||||
|
||||
// 3秒后移除反馈
|
||||
setTimeout(() => feedback.remove(), 3000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,669 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>俄罗斯方块 - 无CDN测试版</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#game-container {
|
||||
width: 540px;
|
||||
height: 720px;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.game-area {
|
||||
width: 300px;
|
||||
height: 600px;
|
||||
background: #111827;
|
||||
border: 2px solid #2563eb;
|
||||
border-radius: 8px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.grid {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(10, 1fr);
|
||||
grid-template-rows: repeat(20, 1fr);
|
||||
gap: 1px;
|
||||
}
|
||||
|
||||
.grid-cell {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.block {
|
||||
position: absolute;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 2px solid;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.block.I { background: #00f5ff; border-color: #00bcd4; }
|
||||
.block.J { background: #0000ff; border-color: #0000cd; }
|
||||
.block.L { background: #ff7f00; border-color: #ff8c00; }
|
||||
.block.O { background: #ffff00; border-color: #ffd700; }
|
||||
.block.S { background: #00ff00; border-color: #32cd32; }
|
||||
.block.T { background: #800080; border-color: #9400d3; }
|
||||
.block.Z { background: #ff0000; border-color: #dc143c; }
|
||||
|
||||
.controls-container {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
display: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.log {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="game-container">
|
||||
<div class="game-area" id="game-area">
|
||||
<div class="grid" id="grid"></div>
|
||||
<div class="status" id="status">
|
||||
<h2 id="status-title">游戏暂停</h2>
|
||||
<p id="status-message">点击按钮继续游戏</p>
|
||||
<button id="status-button" style="margin-top: 10px; padding: 10px 20px; background: #2563eb; color: white; border: none; border-radius: 5px; cursor: pointer;">继续游戏</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="log" id="log">
|
||||
<div>游戏日志:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 游戏状态
|
||||
const game = {
|
||||
gridWidth: 10,
|
||||
gridHeight: 20,
|
||||
board: [],
|
||||
currentPiece: null,
|
||||
score: 0,
|
||||
level: 0,
|
||||
lines: 0,
|
||||
speed: 1.0,
|
||||
isPaused: true,
|
||||
isGameOver: false,
|
||||
gameLoop: null
|
||||
};
|
||||
|
||||
// 方块类型定义
|
||||
const pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff7f00' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#800080' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' }
|
||||
];
|
||||
|
||||
// 日志函数
|
||||
function log(message) {
|
||||
const logEl = document.getElementById('log');
|
||||
const entry = document.createElement('div');
|
||||
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
logEl.appendChild(entry);
|
||||
logEl.scrollTop = logEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// 显示状态
|
||||
function showStatus(title, message, buttonText = '继续游戏') {
|
||||
document.getElementById('status-title').textContent = title;
|
||||
document.getElementById('status-message').textContent = message;
|
||||
document.getElementById('status-button').textContent = buttonText;
|
||||
document.getElementById('status').style.display = 'block';
|
||||
}
|
||||
|
||||
function hideStatus() {
|
||||
document.getElementById('status').style.display = 'none';
|
||||
}
|
||||
|
||||
// 初始化游戏
|
||||
function initGame() {
|
||||
log('初始化游戏...');
|
||||
|
||||
// 清空游戏板
|
||||
game.board = Array(game.gridHeight).fill().map(() => Array(game.gridWidth).fill(0));
|
||||
|
||||
// 重置状态
|
||||
game.score = 0;
|
||||
game.level = 0;
|
||||
game.lines = 0;
|
||||
game.speed = 1.0;
|
||||
game.isPaused = false;
|
||||
game.isGameOver = false;
|
||||
|
||||
// 生成网格
|
||||
const gridEl = document.getElementById('grid');
|
||||
gridEl.innerHTML = '';
|
||||
for (let y = 0; y < game.gridHeight; y++) {
|
||||
for (let x = 0; x < game.gridWidth; x++) {
|
||||
const cell = document.createElement('div');
|
||||
cell.className = 'grid-cell';
|
||||
cell.dataset.x = x;
|
||||
cell.dataset.y = y;
|
||||
gridEl.appendChild(cell);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成新方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
updateUI();
|
||||
hideStatus();
|
||||
|
||||
log('游戏初始化完成');
|
||||
}
|
||||
|
||||
// 生成新方块
|
||||
function spawnNewPiece() {
|
||||
const randomType = pieceTypes[Math.floor(Math.random() * pieceTypes.length)];
|
||||
game.currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(game.gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
log(`生成新方块: ${game.currentPiece.type}`);
|
||||
}
|
||||
|
||||
// 游戏循环
|
||||
function startGameLoop() {
|
||||
if (game.gameLoop) clearInterval(game.gameLoop);
|
||||
|
||||
game.gameLoop = setInterval(() => {
|
||||
if (!game.isPaused && !game.isGameOver) {
|
||||
movePiece(0, 1);
|
||||
}
|
||||
}, 1000 / game.speed);
|
||||
}
|
||||
|
||||
// 移动方块
|
||||
function movePiece(dx, dy) {
|
||||
if (!game.currentPiece || game.isPaused || game.isGameOver) return;
|
||||
|
||||
const newX = game.currentPiece.x + dx;
|
||||
const newY = game.currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(game.currentPiece.shape, newX, newY)) {
|
||||
game.currentPiece.x = newX;
|
||||
game.currentPiece.y = newY;
|
||||
log(`移动方块到: (${newX}, ${newY})`);
|
||||
render();
|
||||
} else if (dy > 0) {
|
||||
// 如果向下移动失败,固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(game.currentPiece.shape, game.currentPiece.x, game.currentPiece.y)) {
|
||||
gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 旋转方块
|
||||
function rotatePiece() {
|
||||
if (!game.currentPiece || game.isPaused || game.isGameOver) return;
|
||||
|
||||
const rotated = rotateMatrix(game.currentPiece.shape);
|
||||
if (isValidMove(rotated, game.currentPiece.x, game.currentPiece.y)) {
|
||||
game.currentPiece.shape = rotated;
|
||||
log('旋转方块');
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// 旋转矩阵
|
||||
function rotateMatrix(matrix) {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 检查移动是否有效
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= game.gridWidth || newY >= game.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && game.board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 固定方块
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = game.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
game.board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log('方块固定到游戏板');
|
||||
}
|
||||
|
||||
// 检查并消除完整的行
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = game.gridHeight - 1; y >= 0; y--) {
|
||||
if (game.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
game.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
game.board.unshift(Array(game.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置(因为行下移了)
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
game.lines += linesCleared;
|
||||
game.score += linesCleared * 100 * game.level;
|
||||
game.level = Math.floor(game.lines / 10);
|
||||
game.speed = 1.0 + game.level * 0.1;
|
||||
|
||||
log(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * game.level}`);
|
||||
startGameLoop(); // 更新游戏速度
|
||||
}
|
||||
}
|
||||
|
||||
// 游戏结束
|
||||
function gameOver() {
|
||||
game.isGameOver = true;
|
||||
clearInterval(game.gameLoop);
|
||||
showStatus('游戏结束', `最终得分: ${game.score}`, '重新开始');
|
||||
log('游戏结束');
|
||||
}
|
||||
|
||||
// 暂停/继续游戏
|
||||
function togglePause() {
|
||||
game.isPaused = !game.isPaused;
|
||||
|
||||
if (game.isPaused) {
|
||||
showStatus('游戏暂停', '点击按钮继续游戏', '继续游戏');
|
||||
log('游戏暂停');
|
||||
} else {
|
||||
hideStatus();
|
||||
log('游戏继续');
|
||||
}
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
// 渲染游戏
|
||||
function render() {
|
||||
// 清空之前的方块
|
||||
document.querySelectorAll('.block').forEach(el => el.remove());
|
||||
|
||||
// 渲染已固定的方块
|
||||
for (let y = 0; y < game.gridHeight; y++) {
|
||||
for (let x = 0; x < game.gridWidth; x++) {
|
||||
if (game.board[y][x]) {
|
||||
const block = document.createElement('div');
|
||||
block.className = 'block';
|
||||
block.style.backgroundColor = game.board[y][x];
|
||||
block.style.borderColor = game.board[y][x];
|
||||
block.style.left = `${x * 30}px`;
|
||||
block.style.top = `${y * 30}px`;
|
||||
document.getElementById('game-area').appendChild(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染当前方块
|
||||
if (game.currentPiece) {
|
||||
const { shape, x, y, color } = game.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const block = document.createElement('div');
|
||||
block.className = `block ${game.currentPiece.type}`;
|
||||
block.style.left = `${(x + col) * 30}px`;
|
||||
block.style.top = `${(y + row) * 30}px`;
|
||||
document.getElementById('game-area').appendChild(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新UI
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = game.score;
|
||||
document.getElementById('level').textContent = game.level;
|
||||
document.getElementById('lines').textContent = game.lines;
|
||||
document.getElementById('speed').textContent = game.speed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!game.currentPiece && !game.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (game.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (game.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
// 设置控件
|
||||
function setupControls() {
|
||||
log('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
log('开始按钮点击');
|
||||
if (!game.currentPiece && !game.isGameOver) {
|
||||
initGame();
|
||||
} else if (game.isPaused) {
|
||||
togglePause();
|
||||
} else if (game.isGameOver) {
|
||||
initGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
log('重来按钮点击');
|
||||
initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
log('左按钮点击');
|
||||
movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
log('右按钮点击');
|
||||
movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
log('下按钮点击');
|
||||
movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
log('旋转按钮点击');
|
||||
rotatePiece();
|
||||
});
|
||||
|
||||
// 状态按钮
|
||||
document.getElementById('status-button').addEventListener('click', () => {
|
||||
log('状态按钮点击');
|
||||
if (game.isGameOver) {
|
||||
initGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
log(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!game.currentPiece && !game.isGameOver) {
|
||||
initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.isPaused || game.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
log('控件事件设置完成');
|
||||
}
|
||||
|
||||
// 初始化
|
||||
window.addEventListener('load', () => {
|
||||
log('页面加载完成');
|
||||
log(`浏览器: ${navigator.userAgent}`);
|
||||
|
||||
setupControls();
|
||||
updateUI();
|
||||
showStatus('俄罗斯方块', '点击开始按钮或按任意键开始游戏', '开始游戏');
|
||||
|
||||
// 初始渲染
|
||||
render();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试新的PlayCanvas版俄罗斯方块
|
||||
"""
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
|
||||
def test_playcanvas_tetris():
|
||||
print("🎮 测试 PlayCanvas版俄罗斯方块")
|
||||
print("=" * 60)
|
||||
|
||||
url = "http://129.211.173.87:8895/games/tetris/"
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
context = browser.new_context(
|
||||
viewport={"width": 1280, "height": 720},
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
|
||||
)
|
||||
page = context.new_page()
|
||||
|
||||
# 收集日志
|
||||
logs = []
|
||||
page.on("console", lambda msg: logs.append({"type": msg.type, "text": msg.text}))
|
||||
|
||||
try:
|
||||
print("📡 加载页面...")
|
||||
page.goto(url, wait_until="networkidle", timeout=15000)
|
||||
time.sleep(3)
|
||||
|
||||
# 检查PlayCanvas加载
|
||||
playcanvas_logs = [l for l in logs if "PlayCanvas" in l["text"]]
|
||||
print(f"✅ PlayCanvas日志: {len(playcanvas_logs)}条")
|
||||
for log in playcanvas_logs[:3]:
|
||||
print(f" {log['text']}")
|
||||
|
||||
# 点击开始
|
||||
print("\n🔘 点击开始游戏...")
|
||||
start_btn = page.query_selector("text=开始游戏")
|
||||
if start_btn:
|
||||
start_btn.click()
|
||||
print("✅ 开始按钮点击成功")
|
||||
else:
|
||||
print("❌ 未找到开始按钮")
|
||||
return
|
||||
|
||||
# 等待游戏运行
|
||||
print("⏳ 等待游戏运行5秒...")
|
||||
time.sleep(5)
|
||||
|
||||
# 测试键盘控制
|
||||
print("\n⌨️ 测试键盘控制...")
|
||||
page.keyboard.press("ArrowLeft")
|
||||
time.sleep(0.5)
|
||||
page.keyboard.press("ArrowRight")
|
||||
time.sleep(0.5)
|
||||
page.keyboard.press("ArrowUp")
|
||||
time.sleep(0.5)
|
||||
|
||||
# 分析日志
|
||||
print("\n📊 日志分析:")
|
||||
errors = [l for l in logs if l["type"] == "error"]
|
||||
print(f" 错误数: {len(errors)}")
|
||||
|
||||
if errors:
|
||||
print(" ❌ 错误日志:")
|
||||
for err in errors[:5]:
|
||||
print(f" {err['text'][:100]}")
|
||||
else:
|
||||
print(" ✅ 无JavaScript错误")
|
||||
|
||||
# 截图
|
||||
page.screenshot(path="/tmp/playcanvas_tetris_test.png")
|
||||
print("\n📸 截图保存: /tmp/playcanvas_tetris_test.png")
|
||||
|
||||
print("\n✅ 测试完成!")
|
||||
|
||||
finally:
|
||||
browser.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_playcanvas_tetris()
|
||||
@@ -0,0 +1,252 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Playwright自动化测试俄罗斯方块游戏
|
||||
测试多个版本,找出真正能工作的版本
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
import os
|
||||
import time
|
||||
|
||||
# 要测试的版本列表
|
||||
VERSIONS_TO_TEST = [
|
||||
# 1. 最终Canvas 2D版(应该工作)
|
||||
("tetris_final_canvas2d.html", "最终Canvas 2D版"),
|
||||
|
||||
# 2. 简单修复版(用户确认能玩)
|
||||
("tetris_simple_fixed.html", "简单修复版"),
|
||||
|
||||
# 3. 工作版(纯Canvas 2D)
|
||||
("tetris_working.html", "工作版"),
|
||||
|
||||
# 4. 手机优化版
|
||||
("tetris_mobile.html", "手机优化版"),
|
||||
|
||||
# 5. 默认版(小游戏中心当前版本)
|
||||
("index.html", "默认版"),
|
||||
|
||||
# 6. PlayCanvas工作版(对比测试)
|
||||
("tetris_playcanvas_working.html", "PlayCanvas工作版"),
|
||||
|
||||
# 7. PlayCanvas超级调试版
|
||||
("tetris_playcanvas_super_debug.html", "PlayCanvas超级调试版"),
|
||||
|
||||
# 8. 简单下落测试版(已验证工作)
|
||||
("tetris_simple_fall_test.html", "简单下落测试版"),
|
||||
]
|
||||
|
||||
BASE_URL = "http://129.211.173.87:8895/games/tetris/"
|
||||
|
||||
async def test_version(page, version_file, version_name):
|
||||
"""测试单个版本"""
|
||||
print(f"\n{'='*60}")
|
||||
print(f"测试: {version_name} ({version_file})")
|
||||
print(f"URL: {BASE_URL}{version_file}")
|
||||
print('='*60)
|
||||
|
||||
try:
|
||||
# 导航到页面
|
||||
await page.goto(f"{BASE_URL}{version_file}", timeout=10000)
|
||||
print("✅ 页面加载成功")
|
||||
|
||||
# 等待页面完全加载
|
||||
await page.wait_for_load_state('networkidle', timeout=5000)
|
||||
|
||||
# 捕获控制台日志
|
||||
console_logs = []
|
||||
|
||||
def handle_console(msg):
|
||||
console_logs.append(msg.text)
|
||||
print(f" 控制台: {msg.text}")
|
||||
|
||||
page.on('console', handle_console)
|
||||
|
||||
# 检查Canvas是否存在
|
||||
canvas_count = await page.locator('canvas').count()
|
||||
print(f"✅ Canvas数量: {canvas_count}")
|
||||
|
||||
if canvas_count > 0:
|
||||
# 获取Canvas尺寸
|
||||
canvas = page.locator('canvas').first
|
||||
canvas_size = await canvas.bounding_box()
|
||||
if canvas_size:
|
||||
print(f"✅ Canvas尺寸: {canvas_size['width']}x{canvas_size['height']}")
|
||||
|
||||
# 检查按钮
|
||||
button_selectors = ['button', '#start-btn', '.control-btn', '#start-button']
|
||||
for selector in button_selectors:
|
||||
button_count = await page.locator(selector).count()
|
||||
if button_count > 0:
|
||||
print(f"✅ 找到按钮: {selector} ({button_count}个)")
|
||||
break
|
||||
|
||||
# 尝试点击开始按钮
|
||||
start_selectors = [
|
||||
'#start-btn',
|
||||
'button:has-text("开始")',
|
||||
'button:has-text("Start")',
|
||||
'button:has-text("▶️")',
|
||||
'button:first-child'
|
||||
]
|
||||
|
||||
clicked = False
|
||||
for selector in start_selectors:
|
||||
if await page.locator(selector).count() > 0:
|
||||
try:
|
||||
await page.locator(selector).click(timeout=3000)
|
||||
print(f"✅ 点击开始按钮: {selector}")
|
||||
clicked = True
|
||||
break
|
||||
except:
|
||||
continue
|
||||
|
||||
if not clicked:
|
||||
print("⚠️ 未找到开始按钮,尝试按空格键开始")
|
||||
await page.keyboard.press(' ')
|
||||
|
||||
# 等待游戏开始
|
||||
await asyncio.sleep(2)
|
||||
|
||||
# 检查是否有方块生成
|
||||
game_started = False
|
||||
for log in console_logs:
|
||||
if any(keyword in log.lower() for keyword in ['生成', 'spawn', 'new piece', '方块']):
|
||||
print(f"✅ 方块生成: {log}")
|
||||
game_started = True
|
||||
break
|
||||
|
||||
if not game_started:
|
||||
print("⚠️ 未检测到方块生成日志")
|
||||
|
||||
# 等待方块下落
|
||||
await asyncio.sleep(3)
|
||||
|
||||
# 检查是否有下落日志
|
||||
piece_moved = False
|
||||
for log in console_logs:
|
||||
if any(keyword in log.lower() for keyword in ['移动', 'move', '下落', 'drop', '位置']):
|
||||
print(f"✅ 方块移动: {log}")
|
||||
piece_moved = True
|
||||
break
|
||||
|
||||
# 截图保存
|
||||
screenshot_path = f"/tmp/test_{version_name.replace(' ', '_')}.png"
|
||||
await page.screenshot(path=screenshot_path, full_page=True)
|
||||
print(f"✅ 截图保存: {screenshot_path}")
|
||||
|
||||
# 总结测试结果
|
||||
print(f"\n📊 测试总结:")
|
||||
print(f" 页面加载: ✅")
|
||||
print(f" Canvas存在: ✅ ({canvas_count}个)")
|
||||
print(f" 按钮点击: {'✅' if clicked else '⚠️'}")
|
||||
print(f" 方块生成: {'✅' if game_started else '❌'}")
|
||||
print(f" 方块下落: {'✅' if piece_moved else '❌'}")
|
||||
|
||||
# 检查是否有错误
|
||||
errors = [log for log in console_logs if 'error' in log.lower() or '❌' in log or '失败' in log]
|
||||
if errors:
|
||||
print(f"⚠️ 发现错误 ({len(errors)}个):")
|
||||
for err in errors[:3]: # 只显示前3个错误
|
||||
print(f" - {err}")
|
||||
|
||||
return {
|
||||
'version': version_name,
|
||||
'file': version_file,
|
||||
'canvas_found': canvas_count > 0,
|
||||
'button_clicked': clicked,
|
||||
'piece_spawned': game_started,
|
||||
'piece_moved': piece_moved,
|
||||
'errors': len(errors),
|
||||
'screenshot': screenshot_path
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 测试失败: {str(e)}")
|
||||
return {
|
||||
'version': version_name,
|
||||
'file': version_file,
|
||||
'error': str(e),
|
||||
'canvas_found': False,
|
||||
'button_clicked': False,
|
||||
'piece_spawned': False,
|
||||
'piece_moved': False,
|
||||
'errors': 1
|
||||
}
|
||||
|
||||
async def main():
|
||||
"""主测试函数"""
|
||||
print("🎮 开始自动化测试俄罗斯方块游戏")
|
||||
print(f"测试时间: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print(f"基础URL: {BASE_URL}")
|
||||
print(f"测试版本数: {len(VERSIONS_TO_TEST)}")
|
||||
|
||||
results = []
|
||||
|
||||
async with async_playwright() as p:
|
||||
# 使用Chromium浏览器
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
context = await browser.new_context(
|
||||
viewport={'width': 1280, 'height': 720},
|
||||
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
||||
)
|
||||
|
||||
page = await context.new_page()
|
||||
|
||||
# 测试每个版本
|
||||
for version_file, version_name in VERSIONS_TO_TEST:
|
||||
result = await test_version(page, version_file, version_name)
|
||||
results.append(result)
|
||||
|
||||
# 清理页面状态
|
||||
await page.goto('about:blank')
|
||||
await asyncio.sleep(1)
|
||||
|
||||
await browser.close()
|
||||
|
||||
# 输出测试报告
|
||||
print("\n" + "="*80)
|
||||
print("🎯 俄罗斯方块游戏测试报告")
|
||||
print("="*80)
|
||||
|
||||
working_versions = []
|
||||
failing_versions = []
|
||||
|
||||
for result in results:
|
||||
if result.get('piece_moved', False):
|
||||
working_versions.append(result)
|
||||
else:
|
||||
failing_versions.append(result)
|
||||
|
||||
print(f"\n✅ 工作版本 ({len(working_versions)}个):")
|
||||
for result in working_versions:
|
||||
print(f" • {result['version']} ({result['file']})")
|
||||
print(f" Canvas: {'✅' if result['canvas_found'] else '❌'}, "
|
||||
f"按钮: {'✅' if result['button_clicked'] else '❌'}, "
|
||||
f"生成: {'✅' if result['piece_spawned'] else '❌'}, "
|
||||
f"下落: ✅, 错误: {result.get('errors', 0)}个")
|
||||
|
||||
print(f"\n❌ 失败版本 ({len(failing_versions)}个):")
|
||||
for result in failing_versions:
|
||||
error_msg = result.get('error', '未知错误')
|
||||
print(f" • {result['version']} ({result['file']})")
|
||||
print(f" 错误: {error_msg[:100]}...")
|
||||
|
||||
print(f"\n📈 成功率: {len(working_versions)}/{len(VERSIONS_TO_TEST)} ({len(working_versions)/len(VERSIONS_TO_TEST)*100:.1f}%)")
|
||||
|
||||
# 推荐最佳版本
|
||||
if working_versions:
|
||||
best_version = max(working_versions, key=lambda x: (
|
||||
x.get('piece_spawned', False),
|
||||
x.get('button_clicked', False),
|
||||
-x.get('errors', 0)
|
||||
))
|
||||
print(f"\n🏆 推荐版本: {best_version['version']} ({best_version['file']})")
|
||||
print(f" 访问: {BASE_URL}{best_version['file']}")
|
||||
else:
|
||||
print("\n⚠️ 警告: 没有找到能工作的版本!")
|
||||
|
||||
print("\n📁 截图保存在: /tmp/test_*.png")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,218 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>俄罗斯方块简单测试</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background: #1a202c;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.test-area {
|
||||
background: #2d3748;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.button {
|
||||
padding: 15px 30px;
|
||||
margin: 10px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.start-btn {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.restart-btn {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
color: white;
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
border-radius: 50%;
|
||||
font-size: 24px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.log {
|
||||
background: #4a5568;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin-top: 10px;
|
||||
font-family: monospace;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: #68d391;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #fc8181;
|
||||
}
|
||||
|
||||
.info {
|
||||
color: #63b3ed;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🎮 俄罗斯方块功能测试</h1>
|
||||
|
||||
<div class="test-area">
|
||||
<h2>1. 按钮点击测试</h2>
|
||||
<p>点击以下按钮,查看控制台输出:</p>
|
||||
|
||||
<button class="button start-btn" id="test-start">▶️ 开始</button>
|
||||
<button class="button restart-btn" id="test-restart">🔄 重来</button>
|
||||
|
||||
<div style="margin: 20px 0;">
|
||||
<div class="control-btn" id="test-left">←</div>
|
||||
<div class="control-btn" id="test-down">↓</div>
|
||||
<div class="control-btn" id="test-right">→</div>
|
||||
<div class="control-btn" id="test-rotate">↻</div>
|
||||
</div>
|
||||
|
||||
<div class="log" id="click-log">
|
||||
<div class="info">点击按钮日志将显示在这里...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-area">
|
||||
<h2>2. 键盘事件测试</h2>
|
||||
<p>按以下键测试键盘事件:</p>
|
||||
<ul>
|
||||
<li><strong>← → ↓</strong> - 方向键</li>
|
||||
<li><strong>空格键</strong> - 旋转</li>
|
||||
<li><strong>P键</strong> - 暂停/继续</li>
|
||||
<li><strong>任意键</strong> - 自动开始游戏</li>
|
||||
</ul>
|
||||
|
||||
<div class="log" id="keyboard-log">
|
||||
<div class="info">键盘事件日志将显示在这里...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-area">
|
||||
<h2>3. JavaScript环境检测</h2>
|
||||
<div class="log" id="env-log">
|
||||
<div class="info">正在检测JavaScript环境...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-area">
|
||||
<h2>4. 链接到实际游戏</h2>
|
||||
<p><a href="http://129.211.173.87:8895/games/tetris/" target="_blank" style="color: #63b3ed; font-weight: bold;">点击这里打开俄罗斯方块游戏</a></p>
|
||||
|
||||
<h3>如果游戏按钮无响应:</h3>
|
||||
<ol>
|
||||
<li>按 <strong>F12</strong> 打开开发者工具</li>
|
||||
<li>点击 <strong>Console(控制台)</strong> 标签页</li>
|
||||
<li>刷新页面</li>
|
||||
<li>查看是否有红色错误信息</li>
|
||||
<li>将错误信息截图或复制给我</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 环境检测
|
||||
const envLog = document.getElementById('env-log');
|
||||
envLog.innerHTML = '';
|
||||
|
||||
const tests = [
|
||||
{ name: 'JavaScript支持', test: () => typeof window !== 'undefined', message: '✅ JavaScript已启用' },
|
||||
{ name: '控制台支持', test: () => typeof console !== 'undefined', message: '✅ 控制台可用' },
|
||||
{ name: '事件监听支持', test: () => typeof document.addEventListener === 'function', message: '✅ 事件监听可用' },
|
||||
{ name: '按钮元素', test: () => document.getElementById('test-start'), message: '✅ 按钮元素存在' },
|
||||
{ name: '键盘事件', test: () => typeof KeyboardEvent !== 'undefined', message: '✅ 键盘事件支持' },
|
||||
{ name: '触摸事件', test: () => typeof TouchEvent !== 'undefined', message: '✅ 触摸事件支持' },
|
||||
];
|
||||
|
||||
tests.forEach(test => {
|
||||
const div = document.createElement('div');
|
||||
try {
|
||||
const result = test.test();
|
||||
div.innerHTML = result ? `<span class="success">${test.message}</span>` : `<span class="error">❌ ${test.name}失败</span>`;
|
||||
} catch (e) {
|
||||
div.innerHTML = `<span class="error">❌ ${test.name}错误: ${e.message}</span>`;
|
||||
}
|
||||
envLog.appendChild(div);
|
||||
});
|
||||
|
||||
// 按钮点击测试
|
||||
const clickLog = document.getElementById('click-log');
|
||||
const buttons = [
|
||||
{ id: 'test-start', name: '开始按钮' },
|
||||
{ id: 'test-restart', name: '重来按钮' },
|
||||
{ id: 'test-left', name: '左按钮' },
|
||||
{ id: 'test-down', name: '下按钮' },
|
||||
{ id: 'test-right', name: '右按钮' },
|
||||
{ id: 'test-rotate', name: '旋转按钮' }
|
||||
];
|
||||
|
||||
buttons.forEach(btn => {
|
||||
const element = document.getElementById(btn.id);
|
||||
if (element) {
|
||||
element.addEventListener('click', () => {
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.innerHTML = `<span class="success">✅ ${btn.name} 点击成功</span> (时间: ${new Date().toLocaleTimeString()})`;
|
||||
clickLog.appendChild(logEntry);
|
||||
clickLog.scrollTop = clickLog.scrollHeight;
|
||||
|
||||
// 模拟按钮反馈
|
||||
element.style.transform = 'scale(0.95)';
|
||||
setTimeout(() => {
|
||||
element.style.transform = 'scale(1)';
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 键盘事件测试
|
||||
const keyboardLog = document.getElementById('keyboard-log');
|
||||
document.addEventListener('keydown', (e) => {
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.innerHTML = `<span class="info">⌨️ 按键: <strong>${e.key}</strong> (keyCode: ${e.keyCode})</span>`;
|
||||
keyboardLog.appendChild(logEntry);
|
||||
keyboardLog.scrollTop = keyboardLog.scrollHeight;
|
||||
|
||||
// 阻止某些键的默认行为(如空格键滚动页面)
|
||||
if (e.key === ' ' || e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
// 添加测试说明
|
||||
const infoDiv = document.createElement('div');
|
||||
infoDiv.innerHTML = '<div class="info" style="margin-top: 10px;">📝 如果所有测试都通过✅,但实际游戏按钮无响应,可能是游戏代码问题。</div>';
|
||||
envLog.appendChild(infoDiv);
|
||||
|
||||
console.log('🎮 俄罗斯方块测试页面已加载');
|
||||
console.log('📱 用户代理:', navigator.userAgent);
|
||||
console.log('🌐 语言:', navigator.language);
|
||||
console.log('🖥️ 平台:', navigator.platform);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试简单循环版本
|
||||
"""
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
|
||||
def test_simple_loop():
|
||||
"""测试简单循环版本"""
|
||||
print("🎮 测试简单循环版本")
|
||||
print("=" * 60)
|
||||
|
||||
url = "http://129.211.173.87:8895/games/tetris/tetris_simple_loop.html"
|
||||
print(f"🌐 测试URL: {url}")
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
|
||||
context = browser.new_context(
|
||||
viewport={"width": 1280, "height": 720},
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
||||
)
|
||||
|
||||
page = context.new_page()
|
||||
|
||||
try:
|
||||
# 导航到页面
|
||||
print("📡 加载页面...")
|
||||
page.goto(url, wait_until="networkidle", timeout=10000)
|
||||
print("✅ 页面加载成功")
|
||||
|
||||
# 等待初始化
|
||||
time.sleep(2)
|
||||
|
||||
# 收集日志
|
||||
logs = []
|
||||
page.on("console", lambda msg: logs.append({
|
||||
"type": msg.type,
|
||||
"text": msg.text
|
||||
}))
|
||||
|
||||
# 点击开始按钮
|
||||
print("🔘 点击开始按钮...")
|
||||
start_btn = page.query_selector("#start-btn")
|
||||
if start_btn:
|
||||
start_btn.click(timeout=3000)
|
||||
print("✅ 开始按钮点击成功")
|
||||
else:
|
||||
print("❌ 未找到开始按钮")
|
||||
return
|
||||
|
||||
# 等待游戏运行
|
||||
print("⏳ 等待游戏运行20秒...")
|
||||
time.sleep(20)
|
||||
|
||||
# 分析日志
|
||||
print("\n📊 日志分析:")
|
||||
|
||||
spawn_logs = [log for log in logs if "生成新方块" in log["text"]]
|
||||
move_logs = [log for log in logs if "移动方块" in log["text"] or "游戏循环" in log["text"]]
|
||||
error_logs = [log for log in logs if log["type"] == "error"]
|
||||
|
||||
print(f" 总日志数: {len(logs)}")
|
||||
print(f" 方块生成日志: {len(spawn_logs)}")
|
||||
print(f" 方块移动日志: {len(move_logs)}")
|
||||
print(f" 错误日志: {len(error_logs)}")
|
||||
|
||||
# 显示关键日志
|
||||
if spawn_logs:
|
||||
print(f"\n🧱 方块生成记录:")
|
||||
for i, log in enumerate(spawn_logs[-3:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if move_logs:
|
||||
print(f"\n🚀 方块移动记录:")
|
||||
for i, log in enumerate(move_logs[-10:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if error_logs:
|
||||
print(f"\n❌ 错误记录:")
|
||||
for i, log in enumerate(error_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
# 评估
|
||||
print("\n📈 测试结果:")
|
||||
|
||||
if len(spawn_logs) > 0:
|
||||
print(f" ✅ 方块生成正常 ({len(spawn_logs)}次)")
|
||||
else:
|
||||
print(" ❌ 方块未生成")
|
||||
|
||||
if len(move_logs) > 0:
|
||||
print(f" ✅ 方块移动正常 ({len(move_logs)}次)")
|
||||
print(f" ✅ 游戏循环工作正常")
|
||||
else:
|
||||
print(" ❌ 方块未移动")
|
||||
print(" ❌ 游戏循环可能有问题")
|
||||
|
||||
if len(error_logs) == 0:
|
||||
print(" ✅ 无JavaScript错误")
|
||||
else:
|
||||
print(f" ❌ 有{len(error_logs)}个JavaScript错误")
|
||||
|
||||
# 截图
|
||||
screenshot_path = "/tmp/simple_loop_test.png"
|
||||
page.screenshot(path=screenshot_path, full_page=True)
|
||||
print(f"\n📸 截图保存: {screenshot_path}")
|
||||
|
||||
# 总体评估
|
||||
print("\n🏆 总体评估:")
|
||||
if len(spawn_logs) > 0 and len(move_logs) > 0:
|
||||
print(" 🎉 完美! 简单循环版本工作正常!")
|
||||
print(" 🚀 游戏可以在Windows浏览器上正常运行!")
|
||||
elif len(spawn_logs) > 0:
|
||||
print(" 👍 部分成功! 方块生成但未移动")
|
||||
print(" 🔧 需要检查移动逻辑")
|
||||
else:
|
||||
print(" ⚠️ 失败! 游戏未正常工作")
|
||||
print(" 🔧 需要深入调试")
|
||||
|
||||
finally:
|
||||
page.close()
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
print("\n✅ 测试完成!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_simple_loop()
|
||||
@@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Windows修复验证测试
|
||||
"""
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
def test_windows_fix():
|
||||
"""测试Windows修复"""
|
||||
print("🪟 Windows修复验证测试")
|
||||
print("=" * 60)
|
||||
|
||||
url = "http://129.211.173.87:8895/games/tetris/index.html"
|
||||
print(f"🌐 测试URL: {url}")
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
|
||||
# 使用Windows用户代理
|
||||
context = browser.new_context(
|
||||
viewport={"width": 1280, "height": 720},
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
)
|
||||
|
||||
page = context.new_page()
|
||||
|
||||
try:
|
||||
# 导航到页面
|
||||
print("📡 加载页面...")
|
||||
page.goto(url, wait_until="networkidle", timeout=10000)
|
||||
print("✅ 页面加载成功")
|
||||
|
||||
# 等待初始化
|
||||
time.sleep(2)
|
||||
|
||||
# 收集日志
|
||||
logs = []
|
||||
page.on("console", lambda msg: logs.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S"),
|
||||
"type": msg.type,
|
||||
"text": msg.text
|
||||
}))
|
||||
|
||||
# 点击开始按钮
|
||||
print("🔘 点击开始按钮...")
|
||||
start_btn = page.query_selector("#start-btn")
|
||||
if start_btn:
|
||||
start_btn.click(timeout=3000)
|
||||
print("✅ 开始按钮点击成功")
|
||||
else:
|
||||
print("❌ 未找到开始按钮")
|
||||
return
|
||||
|
||||
# 等待游戏运行
|
||||
print("⏳ 等待游戏运行15秒...")
|
||||
time.sleep(15)
|
||||
|
||||
# 分析日志
|
||||
print("\n📊 日志分析:")
|
||||
|
||||
# 查找关键日志
|
||||
init_logs = [log for log in logs if "初始化" in log["text"] or "Canvas" in log["text"]]
|
||||
spawn_logs = [log for log in logs if "生成新方块" in log["text"]]
|
||||
move_logs = [log for log in logs if "移动方块" in log["text"] or "自动下落" in log["text"]]
|
||||
error_logs = [log for log in logs if log["type"] == "error"]
|
||||
nan_logs = [log for log in logs if "NaN" in log["text"] or "undefined" in log["text"]]
|
||||
|
||||
print(f" 总日志数: {len(logs)}")
|
||||
print(f" 初始化日志: {len(init_logs)}")
|
||||
print(f" 方块生成日志: {len(spawn_logs)}")
|
||||
print(f" 方块移动日志: {len(move_logs)}")
|
||||
print(f" 错误日志: {len(error_logs)}")
|
||||
print(f" NaN/undefined日志: {len(nan_logs)}")
|
||||
|
||||
# 显示关键日志
|
||||
if spawn_logs:
|
||||
print(f"\n🧱 方块生成记录:")
|
||||
for i, log in enumerate(spawn_logs[-3:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if move_logs:
|
||||
print(f"\n🚀 方块移动记录:")
|
||||
for i, log in enumerate(move_logs[-5:]):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if error_logs:
|
||||
print(f"\n❌ 错误记录:")
|
||||
for i, log in enumerate(error_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
if nan_logs:
|
||||
print(f"\n⚠️ NaN/undefined问题:")
|
||||
for i, log in enumerate(nan_logs):
|
||||
print(f" {i+1}. {log['text']}")
|
||||
|
||||
# 评估修复效果
|
||||
print("\n📈 修复效果评估:")
|
||||
|
||||
if len(nan_logs) == 0:
|
||||
print(" ✅ NaN/undefined问题已完全修复!")
|
||||
else:
|
||||
print(f" ❌ 仍有{len(nan_logs)}个NaN/undefined问题")
|
||||
|
||||
if len(spawn_logs) > 0:
|
||||
print(f" ✅ 方块生成正常 ({len(spawn_logs)}次)")
|
||||
else:
|
||||
print(" ❌ 方块未生成")
|
||||
|
||||
if len(move_logs) > 0:
|
||||
print(f" ✅ 方块移动正常 ({len(move_logs)}次)")
|
||||
else:
|
||||
print(" ❌ 方块未移动")
|
||||
|
||||
if len(error_logs) == 0:
|
||||
print(" ✅ 无JavaScript错误")
|
||||
else:
|
||||
print(f" ❌ 有{len(error_logs)}个JavaScript错误")
|
||||
|
||||
# 总体评估
|
||||
print("\n🏆 总体评估:")
|
||||
|
||||
if len(nan_logs) == 0 and len(spawn_logs) > 0 and len(move_logs) > 0 and len(error_logs) == 0:
|
||||
print(" 🎉 完美! Windows兼容性问题已完全解决!")
|
||||
print(" 🚀 游戏可以在Windows浏览器上正常运行!")
|
||||
elif len(nan_logs) == 0 and len(spawn_logs) > 0:
|
||||
print(" 👍 良好! 主要问题已修复,但仍有小问题")
|
||||
print(" 🔧 需要进一步优化移动逻辑")
|
||||
else:
|
||||
print(" ⚠️ 一般! 仍有问题需要修复")
|
||||
print(" 🔧 需要深入调试")
|
||||
|
||||
# 截图
|
||||
screenshot_path = "/tmp/windows_fix_test.png"
|
||||
page.screenshot(path=screenshot_path, full_page=True)
|
||||
print(f"\n📸 截图保存: {screenshot_path}")
|
||||
|
||||
finally:
|
||||
page.close()
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
print("\n✅ 测试完成!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_windows_fix()
|
||||
@@ -0,0 +1,668 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 贪吃蛇精确复制版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- Poki SDK (async load) - 和贪吃蛇完全一样 -->
|
||||
<script src="https://game-cdn.poki.com/scripts/v2/poki-sdk.js" async></script>
|
||||
|
||||
<!-- PlayCanvas 1.66.0 - 和贪吃蛇完全一样 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* UI层 - 和贪吃蛇一样的结构 */
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#score {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#level {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#lines {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 15px 40px;
|
||||
font-size: 20px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#finalScore {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮 */
|
||||
.controls-container {
|
||||
position: absolute;
|
||||
bottom: 30px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
|
||||
<canvas id="application" width="540" height="720"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<div id="score">分数: 0</div>
|
||||
<div id="level">等级: 0</div>
|
||||
<div id="lines">消行: 0</div>
|
||||
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">▶️ 开始游戏</button>
|
||||
<button class="btn" onclick="showInstructions()">📖 游戏说明</button>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束!</h2>
|
||||
<div id="finalScore">最终得分: 0</div>
|
||||
<button class="btn" onclick="restartGame()">🔄 重新开始</button>
|
||||
<button class="btn" onclick="backToMenu()">🏠 返回菜单</button>
|
||||
</div>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:旋转按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== Poki SDK 初始化 ====================
|
||||
let pokiReady = false;
|
||||
|
||||
function initPoki() {
|
||||
return new Promise((resolve) => {
|
||||
if (typeof PokiSDK === 'undefined') {
|
||||
console.log('⚠️ Poki SDK 未加载,继续游戏');
|
||||
pokiReady = false;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
PokiSDK.init().then(() => {
|
||||
console.log('✅ Poki SDK 初始化成功');
|
||||
pokiReady = true;
|
||||
|
||||
// 设置广告回调
|
||||
PokiSDK.setDebug(true);
|
||||
|
||||
// 游戏加载完成
|
||||
PokiSDK.gameLoadingFinished();
|
||||
|
||||
resolve();
|
||||
}).catch((error) => {
|
||||
console.error('❌ Poki SDK 初始化失败:', error);
|
||||
pokiReady = false;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== PlayCanvas 游戏 ====================
|
||||
function initGame() {
|
||||
console.log('🎮 初始化 PlayCanvas...');
|
||||
|
||||
const canvas = document.getElementById('application');
|
||||
if (!canvas) {
|
||||
console.error('❌ Canvas 元素未找到!');
|
||||
alert('游戏加载失败:Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
let app;
|
||||
try {
|
||||
app = new pc.Application(canvas, {
|
||||
mouse: new pc.Mouse(canvas),
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas),
|
||||
elementInput: new pc.ElementInput(canvas)
|
||||
});
|
||||
console.log('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
console.error('❌ PlayCanvas 初始化失败:', e);
|
||||
alert('游戏引擎初始化失败: ' + e.message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.start();
|
||||
console.log('✅ PlayCanvas 已启动');
|
||||
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
window.addEventListener('resize', () => app.resizeCanvas());
|
||||
|
||||
// ==================== 游戏状态 ====================
|
||||
let gameRunning = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let gameSpeed = 1.0;
|
||||
let isPaused = false;
|
||||
let isGameOver = false;
|
||||
|
||||
// 游戏场地
|
||||
const gridWidth = 10;
|
||||
const gridHeight = 20;
|
||||
const cellSize = 24;
|
||||
let board = Array(gridHeight).fill().map(() => Array(gridWidth).fill(0));
|
||||
|
||||
// 当前方块
|
||||
let currentPiece = null;
|
||||
|
||||
// 方块类型
|
||||
const pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: new pc.Color(0, 0.96, 1) },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: new pc.Color(0, 0, 1) },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: new pc.Color(1, 0.5, 0) },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: new pc.Color(1, 1, 0) },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: new pc.Color(0, 1, 0) },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: new pc.Color(0.5, 0, 0.5) },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: new pc.Color(1, 0, 0) }
|
||||
];
|
||||
|
||||
// ==================== 游戏函数 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = pieceTypes[Math.floor(Math.random() * pieceTypes.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
console.log(`生成新方块: ${currentPiece.type}`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= gridWidth || newY >= gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || isPaused || isGameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = gridHeight - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
board.splice(y, 1);
|
||||
board.unshift(Array(gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
gameSpeed = 1.0 + level * 0.1;
|
||||
|
||||
updateUI();
|
||||
console.log(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || isPaused || isGameOver) return;
|
||||
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
}
|
||||
}
|
||||
|
||||
function gameOver() {
|
||||
isGameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (pokiReady) {
|
||||
PokiSDK.gameplayStop();
|
||||
}
|
||||
|
||||
document.getElementById('finalScore').textContent = `最终得分: ${score}`;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
console.log(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = `分数: ${score}`;
|
||||
document.getElementById('level').textContent = `等级: ${level}`;
|
||||
document.getElementById('lines').textContent = `消行: ${lines}`;
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function render() {
|
||||
const ctx = app.graphicsDevice.gl;
|
||||
if (!ctx) return;
|
||||
|
||||
ctx.clearColor(0.1, 0.1, 0.15, 1.0);
|
||||
ctx.clear(ctx.COLOR_BUFFER_BIT);
|
||||
|
||||
// 使用2D Canvas渲染游戏
|
||||
const canvasCtx = canvas.getContext('2d');
|
||||
if (!canvasCtx) return;
|
||||
|
||||
// 清空画布
|
||||
canvasCtx.fillStyle = '#111827';
|
||||
canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
canvasCtx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
canvasCtx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= gridWidth; x++) {
|
||||
canvasCtx.beginPath();
|
||||
canvasCtx.moveTo(x * cellSize, 0);
|
||||
canvasCtx.lineTo(x * cellSize, canvas.height);
|
||||
canvasCtx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= gridHeight; y++) {
|
||||
canvasCtx.beginPath();
|
||||
canvasCtx.moveTo(0, y * cellSize);
|
||||
canvasCtx.lineTo(canvas.width, y * cellSize);
|
||||
canvasCtx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < gridHeight; y++) {
|
||||
for (let x = 0; x < gridWidth; x++) {
|
||||
if (board[y][x]) {
|
||||
const color = board[y][x];
|
||||
canvasCtx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
|
||||
canvasCtx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
||||
|
||||
canvasCtx.strokeStyle = 'white';
|
||||
canvasCtx.lineWidth = 2;
|
||||
canvasCtx.strokeRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
canvasCtx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
canvasCtx.fillRect((x + col) * cellSize, (y + row) * cellSize, cellSize, cellSize);
|
||||
|
||||
canvasCtx.strokeStyle = 'white';
|
||||
canvasCtx.lineWidth = 2;
|
||||
canvasCtx.strokeRect((x + col) * cellSize, (y + row) * cellSize, cellSize, cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
let lastDropTime = 0;
|
||||
|
||||
app.on('update', (dt) => {
|
||||
try {
|
||||
if (gameRunning && !isPaused && !isGameOver) {
|
||||
const now = Date.now();
|
||||
|
||||
if (!lastDropTime) lastDropTime = now;
|
||||
|
||||
if (now - lastDropTime > 1000 / gameSpeed) {
|
||||
movePiece(0, 1);
|
||||
lastDropTime = now;
|
||||
}
|
||||
|
||||
render();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('❌ 游戏循环错误:', e);
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 输入控制 ====================
|
||||
function setupInput() {
|
||||
console.log('设置输入控制...');
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
if (gameRunning) movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
if (gameRunning) movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
if (gameRunning) movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
if (gameRunning) rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (!gameRunning || isPaused || isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
console.log('✅ 输入控制设置完成');
|
||||
}
|
||||
|
||||
function togglePause() {
|
||||
isPaused = !isPaused;
|
||||
console.log(isPaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
}
|
||||
|
||||
// ==================== 游戏控制函数 ====================
|
||||
window.startGame = function() {
|
||||
console.log('🎮 开始游戏...');
|
||||
|
||||
// 重置游戏状态
|
||||
board = Array(gridHeight).fill().map(() => Array(gridWidth).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameSpeed = 1.0;
|
||||
isPaused = false;
|
||||
isGameOver = false;
|
||||
lastDropTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 更新UI
|
||||
updateUI();
|
||||
|
||||
// 隐藏菜单
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
if (pokiReady) {
|
||||
PokiSDK.gameplayStart();
|
||||
}
|
||||
|
||||
console.log('✅ 游戏开始!');
|
||||
};
|
||||
|
||||
window.restartGame = function() {
|
||||
console.log('🔄 重新开始游戏');
|
||||
startGame();
|
||||
};
|
||||
|
||||
window.backToMenu = function() {
|
||||
console.log('🏠 返回菜单');
|
||||
gameRunning = false;
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
document.getElementById('menu').style.display = 'block';
|
||||
};
|
||||
|
||||
window.showInstructions = function() {
|
||||
alert('🎮 俄罗斯方块游戏说明:\n\n' +
|
||||
'← → ↓:移动方块\n' +
|
||||
'↑ 或 空格:旋转方块\n' +
|
||||
'P:暂停/继续游戏\n\n' +
|
||||
'目标:消除完整的行来得分!');
|
||||
};
|
||||
|
||||
// 初始化输入控制
|
||||
setupInput();
|
||||
|
||||
console.log('✅ 俄罗斯方块游戏初始化完成');
|
||||
hideLoading();
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// 启动游戏初始化
|
||||
initPoki().then(() => {
|
||||
console.log('🎮 开始初始化游戏...');
|
||||
initGame();
|
||||
});
|
||||
|
||||
// 错误处理
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
alert('游戏加载错误: ' + e.message);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,686 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 最终版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- PlayCanvas 1.66.0 - 和贪吃蛇完全一样 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* UI层 */
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#score {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#level {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#lines {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 15px 40px;
|
||||
font-size: 20px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#finalScore {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮 */
|
||||
.controls-container {
|
||||
position: absolute;
|
||||
bottom: 30px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
|
||||
<canvas id="application" width="540" height="720"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<div id="score">分数: 0</div>
|
||||
<div id="level">等级: 0</div>
|
||||
<div id="lines">消行: 0</div>
|
||||
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">▶️ 开始游戏</button>
|
||||
<button class="btn" onclick="showInstructions()">📖 游戏说明</button>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束!</h2>
|
||||
<div id="finalScore">最终得分: 0</div>
|
||||
<button class="btn" onclick="restartGame()">🔄 重新开始</button>
|
||||
<button class="btn" onclick="backToMenu()">🏠 返回菜单</button>
|
||||
</div>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:旋转按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-info" id="debug-info">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug-info');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// ==================== PlayCanvas 游戏 ====================
|
||||
function initGame() {
|
||||
debugLog('🎮 初始化 PlayCanvas...');
|
||||
|
||||
const canvas = document.getElementById('application');
|
||||
if (!canvas) {
|
||||
debugLog('❌ Canvas 元素未找到!');
|
||||
alert('游戏加载失败:Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
let app;
|
||||
try {
|
||||
app = new pc.Application(canvas, {
|
||||
mouse: new pc.Mouse(canvas),
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas),
|
||||
elementInput: new pc.ElementInput(canvas)
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog(`❌ PlayCanvas 初始化失败: ${e.message}`);
|
||||
alert('游戏引擎初始化失败: ' + e.message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
try {
|
||||
app.resizeCanvas();
|
||||
debugLog('✅ 画布大小已调整');
|
||||
} catch (e) {
|
||||
debugLog(`❌ 画布调整失败: ${e.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 游戏状态 ====================
|
||||
let gameRunning = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let gameSpeed = 1.0;
|
||||
let isPaused = false;
|
||||
let isGameOver = false;
|
||||
|
||||
// 游戏场地
|
||||
const gridWidth = 10;
|
||||
const gridHeight = 20;
|
||||
const cellSize = 24;
|
||||
let board = Array(gridHeight).fill().map(() => Array(gridWidth).fill(0));
|
||||
|
||||
// 当前方块
|
||||
let currentPiece = null;
|
||||
|
||||
// 方块类型
|
||||
const pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: new pc.Color(0, 0.96, 1) },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: new pc.Color(0, 0, 1) },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: new pc.Color(1, 0.5, 0) },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: new pc.Color(1, 1, 0) },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: new pc.Color(0, 1, 0) },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: new pc.Color(0.5, 0, 0.5) },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: new pc.Color(1, 0, 0) }
|
||||
];
|
||||
|
||||
// ==================== 游戏函数 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = pieceTypes[Math.floor(Math.random() * pieceTypes.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type}`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= gridWidth || newY >= gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || isPaused || isGameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = gridHeight - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
board.splice(y, 1);
|
||||
board.unshift(Array(gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
gameSpeed = 1.0 + level * 0.1;
|
||||
|
||||
updateUI();
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || isPaused || isGameOver) return;
|
||||
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
function gameOver() {
|
||||
isGameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
document.getElementById('finalScore').textContent = `最终得分: ${score}`;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
debugLog(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = `分数: ${score}`;
|
||||
document.getElementById('level').textContent = `等级: ${level}`;
|
||||
document.getElementById('lines').textContent = `消行: ${lines}`;
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function render() {
|
||||
const ctx = app.graphicsDevice.gl;
|
||||
if (!ctx) return;
|
||||
|
||||
ctx.clearColor(0.1, 0.1, 0.15, 1.0);
|
||||
ctx.clear(ctx.COLOR_BUFFER_BIT);
|
||||
|
||||
// 使用2D Canvas渲染游戏
|
||||
const canvasCtx = canvas.getContext('2d');
|
||||
if (!canvasCtx) return;
|
||||
|
||||
// 清空画布
|
||||
canvasCtx.fillStyle = '#111827';
|
||||
canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
canvasCtx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
canvasCtx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= gridWidth; x++) {
|
||||
canvasCtx.beginPath();
|
||||
canvasCtx.moveTo(x * cellSize, 0);
|
||||
canvasCtx.lineTo(x * cellSize, canvas.height);
|
||||
canvasCtx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= gridHeight; y++) {
|
||||
canvasCtx.beginPath();
|
||||
canvasCtx.moveTo(0, y * cellSize);
|
||||
canvasCtx.lineTo(canvas.width, y * cellSize);
|
||||
canvasCtx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < gridHeight; y++) {
|
||||
for (let x = 0; x < gridWidth; x++) {
|
||||
if (board[y][x]) {
|
||||
const color = board[y][x];
|
||||
canvasCtx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
|
||||
canvasCtx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
||||
|
||||
canvasCtx.strokeStyle = 'white';
|
||||
canvasCtx.lineWidth = 2;
|
||||
canvasCtx.strokeRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
canvasCtx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
canvasCtx.fillRect((x + col) * cellSize, (y + row) * cellSize, cellSize, cellSize);
|
||||
|
||||
canvasCtx.strokeStyle = 'white';
|
||||
canvasCtx.lineWidth = 2;
|
||||
canvasCtx.strokeRect((x + col) * cellSize, (y + row) * cellSize, cellSize, cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
let dropTimer = 0;
|
||||
let lastFrameTime = 0;
|
||||
|
||||
app.on('update', (dt) => {
|
||||
try {
|
||||
if (gameRunning && !isPaused && !isGameOver) {
|
||||
const now = performance.now();
|
||||
|
||||
if (!lastFrameTime) lastFrameTime = now;
|
||||
|
||||
// 累积时间
|
||||
dropTimer += dt * 1000; // dt是秒,转换为毫秒
|
||||
|
||||
// 每1000ms/游戏速度下落一次
|
||||
if (dropTimer > 1000 / gameSpeed) {
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
|
||||
// 每帧都渲染
|
||||
render();
|
||||
|
||||
lastFrameTime = now;
|
||||
}
|
||||
} catch (e) {
|
||||
debugLog(`❌ 游戏循环错误: ${e.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 输入控制 ====================
|
||||
function setupInput() {
|
||||
debugLog('设置输入控制...');
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
if (gameRunning) movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
if (gameRunning) movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
if (gameRunning) movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
if (gameRunning) rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (!gameRunning || isPaused || isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('✅ 输入控制设置完成');
|
||||
}
|
||||
|
||||
function togglePause() {
|
||||
isPaused = !isPaused;
|
||||
debugLog(isPaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
}
|
||||
|
||||
// ==================== 游戏控制函数 ====================
|
||||
window.startGame = function() {
|
||||
debugLog('🎮 开始游戏...');
|
||||
|
||||
// 重置游戏状态
|
||||
board = Array(gridHeight).fill().map(() => Array(gridWidth).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameSpeed = 1.0;
|
||||
isPaused = false;
|
||||
isGameOver = false;
|
||||
dropTimer = 0;
|
||||
lastFrameTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 更新UI
|
||||
updateUI();
|
||||
|
||||
// 隐藏菜单
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
debugLog('✅ 游戏开始!');
|
||||
};
|
||||
|
||||
window.restartGame = function() {
|
||||
debugLog('🔄 重新开始游戏');
|
||||
startGame();
|
||||
};
|
||||
|
||||
window.backToMenu = function() {
|
||||
debugLog('🏠 返回菜单');
|
||||
gameRunning = false;
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
document.getElementById('menu').style.display = 'block';
|
||||
};
|
||||
|
||||
window.showInstructions = function() {
|
||||
alert('🎮 俄罗斯方块游戏说明:\n\n' +
|
||||
'← → ↓:移动方块\n' +
|
||||
'↑ 或 空格:旋转方块\n' +
|
||||
'P:暂停/继续游戏\n\n' +
|
||||
'目标:消除完整的行来得分!');
|
||||
};
|
||||
|
||||
// 初始化输入控制
|
||||
setupInput();
|
||||
|
||||
debugLog('✅ 俄罗斯方块游戏初始化完成');
|
||||
hideLoading();
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// 页面加载完成后初始化游戏
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 检查PlayCanvas是否加载
|
||||
if (typeof pc === 'undefined') {
|
||||
debugLog('❌ PlayCanvas 未加载');
|
||||
alert('游戏引擎加载失败,请刷新页面');
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ PlayCanvas 已加载');
|
||||
|
||||
// 初始化游戏
|
||||
initGame();
|
||||
});
|
||||
|
||||
// 错误处理
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
alert('游戏加载错误: ' + e.message);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,871 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 最终Canvas 2D版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
#game-container {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
border: 2px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 10px;
|
||||
background: #111827;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
width: 540px;
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 10px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 14px;
|
||||
color: #aaa;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #00d4ff;
|
||||
}
|
||||
|
||||
#controls {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
padding: 12px 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.control-btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
.control-btn:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
#pause-btn {
|
||||
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
#menu p {
|
||||
color: #ccc;
|
||||
margin-bottom: 30px;
|
||||
max-width: 400px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
#game-over {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#game-over h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#final-score {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 移动端虚拟按钮 */
|
||||
#mobile-controls {
|
||||
display: none;
|
||||
position: absolute;
|
||||
bottom: 50px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.mobile-btn {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 28px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.mobile-btn:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
canvas {
|
||||
width: 300px;
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
width: 300px;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
flex: 1;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
#controls {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#mobile-controls {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
canvas {
|
||||
width: 280px;
|
||||
height: 380px;
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
#menu, #game-over {
|
||||
width: 90%;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
font-size: 36px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div id="info-panel">
|
||||
<div class="info-item">
|
||||
<div class="info-label">分数</div>
|
||||
<div class="info-value" id="score">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">等级</div>
|
||||
<div class="info-value" id="level">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">消行</div>
|
||||
<div class="info-value" id="lines">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">下一个</div>
|
||||
<div class="info-value" id="next-piece">?</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="controls">
|
||||
<button class="control-btn" id="start-btn">▶️ 开始</button>
|
||||
<button class="control-btn" id="pause-btn">⏸️ 暂停</button>
|
||||
<button class="control-btn" id="restart-btn">🔄 重来</button>
|
||||
</div>
|
||||
|
||||
<!-- 移动端虚拟按钮 -->
|
||||
<div id="mobile-controls">
|
||||
<div class="mobile-btn" id="mobile-left">←</div>
|
||||
<div class="mobile-btn" id="mobile-down">↓</div>
|
||||
<div class="mobile-btn" id="mobile-right">→</div>
|
||||
<div class="mobile-btn" id="mobile-rotate">↻</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 开始菜单 -->
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<p>经典的下落式方块游戏。使用方向键移动和旋转方块,填满整行消除得分!</p>
|
||||
<button class="control-btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; color: #888; font-size: 14px;">
|
||||
<p>🎮 控制:键盘方向键或虚拟按钮</p>
|
||||
<p>⬆️ 旋转:上箭头或旋转按钮</p>
|
||||
<p>⏸️ 暂停:P键或暂停按钮</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏结束界面 -->
|
||||
<div id="game-over">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="final-score">最终分数: 0</div>
|
||||
<button class="control-btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 游戏配置 ====================
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff', name: '长条' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff', name: 'J形' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000', name: 'L形' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00', name: '方块' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00', name: 'S形' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff', name: 'T形' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000', name: 'Z形' }
|
||||
];
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let canvas, ctx;
|
||||
let board = [];
|
||||
let currentPiece = null;
|
||||
let nextPiece = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
let gameLoopId = null;
|
||||
let lastTime = 0;
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
function init() {
|
||||
console.log('🎮 初始化俄罗斯方块游戏...');
|
||||
|
||||
// 获取Canvas和上下文
|
||||
canvas = document.getElementById('game-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
console.error('❌ 无法获取Canvas 2D上下文!');
|
||||
alert('游戏初始化失败:无法获取Canvas上下文');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ Canvas 2D上下文获取成功');
|
||||
console.log(`Canvas尺寸: ${canvas.width}x${canvas.height}`);
|
||||
|
||||
// 初始化游戏板
|
||||
resetBoard();
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
generateNextPiece();
|
||||
|
||||
// 设置事件监听器
|
||||
setupEventListeners();
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
|
||||
console.log('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
function resetBoard() {
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
}
|
||||
|
||||
function spawnNewPiece() {
|
||||
if (nextPiece) {
|
||||
// 使用预览方块 - 直接复制所有属性
|
||||
currentPiece = {
|
||||
type: nextPiece.type,
|
||||
shape: nextPiece.shape,
|
||||
color: nextPiece.color,
|
||||
name: nextPiece.name,
|
||||
x: nextPiece.x, // 直接使用nextPiece的x
|
||||
y: nextPiece.y // 直接使用nextPiece的y
|
||||
};
|
||||
} else {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
}
|
||||
|
||||
generateNextPiece();
|
||||
console.log(`生成新方块: ${currentPiece.type} (${currentPiece.name}) 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
}
|
||||
|
||||
function generateNextPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
nextPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
|
||||
document.getElementById('next-piece').textContent = nextPiece.name;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
console.log(`移动方块到: (${newX}, ${newY})`);
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
renderGame();
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
|
||||
// 计算得分:一次消除多行得分更高
|
||||
const lineScores = [0, 100, 300, 500, 800]; // 0-4行的得分
|
||||
score += lineScores[Math.min(linesCleared, 4)] * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
console.log(`消除 ${linesCleared} 行,得分: ${lineScores[Math.min(linesCleared, 4)] * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
console.log('旋转方块');
|
||||
renderGame();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvas.width - gameWidth) / 2;
|
||||
const offsetY = (canvas.height - gameHeight) / 2;
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制预览(下一个方块)
|
||||
if (nextPiece) {
|
||||
const previewX = offsetX + GRID_WIDTH * CELL_SIZE + 20;
|
||||
const previewY = offsetY;
|
||||
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
||||
ctx.fillRect(previewX, previewY, 100, 100);
|
||||
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.font = '14px Arial';
|
||||
ctx.fillText('下一个:', previewX + 10, previewY + 20);
|
||||
|
||||
// 绘制预览方块
|
||||
const previewShape = nextPiece.shape;
|
||||
const shapeWidth = previewShape[0].length;
|
||||
const shapeHeight = previewShape.length;
|
||||
const cellSize = 20;
|
||||
const shapeOffsetX = previewX + 50 - (shapeWidth * cellSize) / 2;
|
||||
const shapeOffsetY = previewY + 60 - (shapeHeight * cellSize) / 2;
|
||||
|
||||
for (let row = 0; row < shapeHeight; row++) {
|
||||
for (let col = 0; col < shapeWidth; col++) {
|
||||
if (previewShape[row][col]) {
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.fillRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameLoop(currentTime) {
|
||||
if (!gameRunning || gameOver) return;
|
||||
|
||||
// 计算时间增量
|
||||
const deltaTime = (currentTime - lastTime) / 1000; // 转换为秒
|
||||
lastTime = currentTime;
|
||||
|
||||
if (!gamePaused) {
|
||||
// 自动下落
|
||||
dropTimer += deltaTime;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
|
||||
// ==================== 游戏控制 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
console.log('🎮 开始游戏...');
|
||||
|
||||
// 隐藏菜单
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 重置游戏状态
|
||||
resetBoard();
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成方块
|
||||
spawnNewPiece();
|
||||
generateNextPiece();
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
lastTime = performance.now();
|
||||
|
||||
updateUI();
|
||||
renderGame();
|
||||
|
||||
// 启动游戏循环
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = '⏸️ 暂停';
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
console.log(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
document.getElementById('pause-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
}
|
||||
|
||||
window.restartGame = function() {
|
||||
console.log('🔄 重新开始游戏...');
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('game-over').style.display = 'none';
|
||||
|
||||
// 停止当前游戏循环
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
// 重新开始游戏
|
||||
startGame();
|
||||
};
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
document.getElementById('final-score').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('game-over').style.display = 'block';
|
||||
|
||||
console.log(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// ==================== 事件监听器 ====================
|
||||
function setupEventListeners() {
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
console.log(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// 按钮控制
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('pause-btn').addEventListener('click', togglePause);
|
||||
document.getElementById('restart-btn').addEventListener('click', restartGame);
|
||||
|
||||
// 移动端虚拟按钮
|
||||
document.getElementById('mobile-left').addEventListener('click', () => movePiece(-1, 0));
|
||||
document.getElementById('mobile-right').addEventListener('click', () => movePiece(1, 0));
|
||||
document.getElementById('mobile-down').addEventListener('click', () => movePiece(0, 1));
|
||||
document.getElementById('mobile-rotate').addEventListener('click', rotatePiece);
|
||||
|
||||
// 触摸事件(移动端)
|
||||
let touchStartX = 0;
|
||||
let touchStartY = 0;
|
||||
|
||||
canvas.addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
const touch = e.touches[0];
|
||||
touchStartX = touch.clientX;
|
||||
touchStartY = touch.clientY;
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchmove', (e) => {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchend', (e) => {
|
||||
e.preventDefault();
|
||||
const touch = e.changedTouches[0];
|
||||
const deltaX = touch.clientX - touchStartX;
|
||||
const deltaY = touch.clientY - touchStartY;
|
||||
|
||||
// 滑动控制
|
||||
if (Math.abs(deltaX) > Math.abs(deltaY)) {
|
||||
// 水平滑动
|
||||
if (deltaX > 30) movePiece(1, 0); // 右滑
|
||||
else if (deltaX < -30) movePiece(-1, 0); // 左滑
|
||||
} else {
|
||||
// 垂直滑动
|
||||
if (deltaY > 30) movePiece(0, 1); // 下滑
|
||||
else if (deltaY < -30) rotatePiece(); // 上滑(旋转)
|
||||
}
|
||||
});
|
||||
|
||||
// 窗口大小改变时调整Canvas
|
||||
window.addEventListener('resize', () => {
|
||||
renderGame();
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
console.log('页面加载完成');
|
||||
console.log(`浏览器: ${navigator.userAgent}`);
|
||||
console.log(`平台: ${navigator.platform}`);
|
||||
|
||||
init();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,877 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 最终Canvas 2D版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
#game-container {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
border: 2px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 10px;
|
||||
background: #111827;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
width: 540px;
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 10px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 14px;
|
||||
color: #aaa;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #00d4ff;
|
||||
}
|
||||
|
||||
#controls {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
padding: 12px 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.control-btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
.control-btn:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
#pause-btn {
|
||||
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
#menu p {
|
||||
color: #ccc;
|
||||
margin-bottom: 30px;
|
||||
max-width: 400px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
#game-over {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#game-over h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#final-score {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 移动端虚拟按钮 */
|
||||
#mobile-controls {
|
||||
display: none;
|
||||
position: absolute;
|
||||
bottom: 50px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.mobile-btn {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 28px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.mobile-btn:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
canvas {
|
||||
width: 300px;
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
width: 300px;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
flex: 1;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
#controls {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#mobile-controls {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
canvas {
|
||||
width: 280px;
|
||||
height: 380px;
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
#menu, #game-over {
|
||||
width: 90%;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
font-size: 36px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div id="info-panel">
|
||||
<div class="info-item">
|
||||
<div class="info-label">分数</div>
|
||||
<div class="info-value" id="score">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">等级</div>
|
||||
<div class="info-value" id="level">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">消行</div>
|
||||
<div class="info-value" id="lines">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">下一个</div>
|
||||
<div class="info-value" id="next-piece">?</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="controls">
|
||||
<button class="control-btn" id="start-btn">▶️ 开始</button>
|
||||
<button class="control-btn" id="pause-btn">⏸️ 暂停</button>
|
||||
<button class="control-btn" id="restart-btn">🔄 重来</button>
|
||||
</div>
|
||||
|
||||
<!-- 移动端虚拟按钮 -->
|
||||
<div id="mobile-controls">
|
||||
<div class="mobile-btn" id="mobile-left">←</div>
|
||||
<div class="mobile-btn" id="mobile-down">↓</div>
|
||||
<div class="mobile-btn" id="mobile-right">→</div>
|
||||
<div class="mobile-btn" id="mobile-rotate">↻</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 开始菜单 -->
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<p>经典的下落式方块游戏。使用方向键移动和旋转方块,填满整行消除得分!</p>
|
||||
<button class="control-btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; color: #888; font-size: 14px;">
|
||||
<p>🎮 控制:键盘方向键或虚拟按钮</p>
|
||||
<p>⬆️ 旋转:上箭头或旋转按钮</p>
|
||||
<p>⏸️ 暂停:P键或暂停按钮</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏结束界面 -->
|
||||
<div id="game-over">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="final-score">最终分数: 0</div>
|
||||
<button class="control-btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 游戏配置 ====================
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff', name: '长条' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff', name: 'J形' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000', name: 'L形' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00', name: '方块' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00', name: 'S形' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff', name: 'T形' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000', name: 'Z形' }
|
||||
];
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let canvas, ctx;
|
||||
let board = [];
|
||||
let currentPiece = null;
|
||||
let nextPiece = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
let gameLoopId = null;
|
||||
let lastTime = 0;
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
function init() {
|
||||
console.log('🎮 初始化俄罗斯方块游戏...');
|
||||
|
||||
// 获取Canvas和上下文
|
||||
canvas = document.getElementById('game-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
console.error('❌ 无法获取Canvas 2D上下文!');
|
||||
alert('游戏初始化失败:无法获取Canvas上下文');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ Canvas 2D上下文获取成功');
|
||||
console.log(`Canvas尺寸: ${canvas.width}x${canvas.height}`);
|
||||
|
||||
// 初始化游戏板
|
||||
resetBoard();
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
generateNextPiece();
|
||||
|
||||
// 设置事件监听器
|
||||
setupEventListeners();
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
|
||||
console.log('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
function resetBoard() {
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
}
|
||||
|
||||
function spawnNewPiece() {
|
||||
if (nextPiece) {
|
||||
currentPiece = {
|
||||
type: nextPiece.type,
|
||||
shape: nextPiece.shape,
|
||||
color: nextPiece.color,
|
||||
name: nextPiece.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(nextPiece.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
} else {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
}
|
||||
|
||||
generateNextPiece();
|
||||
console.log(`生成新方块: ${currentPiece.type} (${currentPiece.name}) 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
}
|
||||
|
||||
function generateNextPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
nextPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
|
||||
document.getElementById('next-piece').textContent = nextPiece.name;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
console.log(`移动方块到: (${newX}, ${newY})`);
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
renderGame();
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
|
||||
// 计算得分:一次消除多行得分更高
|
||||
const lineScores = [0, 100, 300, 500, 800]; // 0-4行的得分
|
||||
score += lineScores[Math.min(linesCleared, 4)] * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
console.log(`消除 ${linesCleared} 行,得分: ${lineScores[Math.min(linesCleared, 4)] * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
console.log('旋转方块');
|
||||
renderGame();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvas.width - gameWidth) / 2;
|
||||
const offsetY = (canvas.height - gameHeight) / 2;
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制预览(下一个方块)
|
||||
if (nextPiece) {
|
||||
const previewX = offsetX + GRID_WIDTH * CELL_SIZE + 20;
|
||||
const previewY = offsetY;
|
||||
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
||||
ctx.fillRect(previewX, previewY, 100, 100);
|
||||
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.font = '14px Arial';
|
||||
ctx.fillText('下一个:', previewX + 10, previewY + 20);
|
||||
|
||||
// 绘制预览方块
|
||||
const previewShape = nextPiece.shape;
|
||||
const shapeWidth = previewShape[0].length;
|
||||
const shapeHeight = previewShape.length;
|
||||
const cellSize = 20;
|
||||
const shapeOffsetX = previewX + 50 - (shapeWidth * cellSize) / 2;
|
||||
const shapeOffsetY = previewY + 60 - (shapeHeight * cellSize) / 2;
|
||||
|
||||
for (let row = 0; row < shapeHeight; row++) {
|
||||
for (let col = 0; col < shapeWidth; col++) {
|
||||
if (previewShape[row][col]) {
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.fillRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameLoop(currentTime) {
|
||||
if (!gameRunning || gameOver) return;
|
||||
|
||||
// 计算时间增量
|
||||
const deltaTime = (currentTime - lastTime) / 1000; // 转换为秒
|
||||
lastTime = currentTime;
|
||||
|
||||
if (!gamePaused) {
|
||||
// 自动下落
|
||||
dropTimer += deltaTime;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
// 调试日志:检查currentPiece状态
|
||||
if (currentPiece) {
|
||||
console.log(`[游戏循环] 当前方块: ${currentPiece.type}, 位置: (${currentPiece.x}, ${currentPiece.y}), dropTimer: ${dropTimer.toFixed(3)}, dropInterval: ${dropInterval.toFixed(3)}`);
|
||||
} else {
|
||||
console.log(`[游戏循环] currentPiece为null或undefined`);
|
||||
}
|
||||
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
|
||||
// ==================== 游戏控制 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
console.log('🎮 开始游戏...');
|
||||
|
||||
// 隐藏菜单
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 重置游戏状态
|
||||
resetBoard();
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成方块
|
||||
spawnNewPiece();
|
||||
generateNextPiece();
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
lastTime = performance.now();
|
||||
|
||||
updateUI();
|
||||
renderGame();
|
||||
|
||||
// 启动游戏循环
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = '⏸️ 暂停';
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
console.log(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
document.getElementById('pause-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
}
|
||||
|
||||
window.restartGame = function() {
|
||||
console.log('🔄 重新开始游戏...');
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('game-over').style.display = 'none';
|
||||
|
||||
// 停止当前游戏循环
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
// 重新开始游戏
|
||||
startGame();
|
||||
};
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
document.getElementById('final-score').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('game-over').style.display = 'block';
|
||||
|
||||
console.log(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// ==================== 事件监听器 ====================
|
||||
function setupEventListeners() {
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
console.log(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// 按钮控制
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('pause-btn').addEventListener('click', togglePause);
|
||||
document.getElementById('restart-btn').addEventListener('click', restartGame);
|
||||
|
||||
// 移动端虚拟按钮
|
||||
document.getElementById('mobile-left').addEventListener('click', () => movePiece(-1, 0));
|
||||
document.getElementById('mobile-right').addEventListener('click', () => movePiece(1, 0));
|
||||
document.getElementById('mobile-down').addEventListener('click', () => movePiece(0, 1));
|
||||
document.getElementById('mobile-rotate').addEventListener('click', rotatePiece);
|
||||
|
||||
// 触摸事件(移动端)
|
||||
let touchStartX = 0;
|
||||
let touchStartY = 0;
|
||||
|
||||
canvas.addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
const touch = e.touches[0];
|
||||
touchStartX = touch.clientX;
|
||||
touchStartY = touch.clientY;
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchmove', (e) => {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchend', (e) => {
|
||||
e.preventDefault();
|
||||
const touch = e.changedTouches[0];
|
||||
const deltaX = touch.clientX - touchStartX;
|
||||
const deltaY = touch.clientY - touchStartY;
|
||||
|
||||
// 滑动控制
|
||||
if (Math.abs(deltaX) > Math.abs(deltaY)) {
|
||||
// 水平滑动
|
||||
if (deltaX > 30) movePiece(1, 0); // 右滑
|
||||
else if (deltaX < -30) movePiece(-1, 0); // 左滑
|
||||
} else {
|
||||
// 垂直滑动
|
||||
if (deltaY > 30) movePiece(0, 1); // 下滑
|
||||
else if (deltaY < -30) rotatePiece(); // 上滑(旋转)
|
||||
}
|
||||
});
|
||||
|
||||
// 窗口大小改变时调整Canvas
|
||||
window.addEventListener('resize', () => {
|
||||
renderGame();
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
console.log('页面加载完成');
|
||||
console.log(`浏览器: ${navigator.userAgent}`);
|
||||
console.log(`平台: ${navigator.platform}`);
|
||||
|
||||
init();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,871 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 最终Canvas 2D版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
#game-container {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
border: 2px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 10px;
|
||||
background: #111827;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
width: 540px;
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 10px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 14px;
|
||||
color: #aaa;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #00d4ff;
|
||||
}
|
||||
|
||||
#controls {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
padding: 12px 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.control-btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
.control-btn:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
#pause-btn {
|
||||
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
#menu p {
|
||||
color: #ccc;
|
||||
margin-bottom: 30px;
|
||||
max-width: 400px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
#game-over {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#game-over h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#final-score {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 移动端虚拟按钮 */
|
||||
#mobile-controls {
|
||||
display: none;
|
||||
position: absolute;
|
||||
bottom: 50px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.mobile-btn {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 28px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.mobile-btn:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
canvas {
|
||||
width: 300px;
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
width: 300px;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
flex: 1;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
#controls {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#mobile-controls {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
canvas {
|
||||
width: 280px;
|
||||
height: 380px;
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
#menu, #game-over {
|
||||
width: 90%;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
font-size: 36px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div id="info-panel">
|
||||
<div class="info-item">
|
||||
<div class="info-label">分数</div>
|
||||
<div class="info-value" id="score">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">等级</div>
|
||||
<div class="info-value" id="level">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">消行</div>
|
||||
<div class="info-value" id="lines">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">下一个</div>
|
||||
<div class="info-value" id="next-piece">?</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="controls">
|
||||
<button class="control-btn" id="start-btn">▶️ 开始</button>
|
||||
<button class="control-btn" id="pause-btn">⏸️ 暂停</button>
|
||||
<button class="control-btn" id="restart-btn">🔄 重来</button>
|
||||
</div>
|
||||
|
||||
<!-- 移动端虚拟按钮 -->
|
||||
<div id="mobile-controls">
|
||||
<div class="mobile-btn" id="mobile-left">←</div>
|
||||
<div class="mobile-btn" id="mobile-down">↓</div>
|
||||
<div class="mobile-btn" id="mobile-right">→</div>
|
||||
<div class="mobile-btn" id="mobile-rotate">↻</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 开始菜单 -->
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<p>经典的下落式方块游戏。使用方向键移动和旋转方块,填满整行消除得分!</p>
|
||||
<button class="control-btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; color: #888; font-size: 14px;">
|
||||
<p>🎮 控制:键盘方向键或虚拟按钮</p>
|
||||
<p>⬆️ 旋转:上箭头或旋转按钮</p>
|
||||
<p>⏸️ 暂停:P键或暂停按钮</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏结束界面 -->
|
||||
<div id="game-over">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="final-score">最终分数: 0</div>
|
||||
<button class="control-btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 游戏配置 ====================
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff', name: '长条' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff', name: 'J形' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000', name: 'L形' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00', name: '方块' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00', name: 'S形' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff', name: 'T形' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000', name: 'Z形' }
|
||||
];
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let canvas, ctx;
|
||||
let board = [];
|
||||
let currentPiece = null;
|
||||
let nextPiece = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
let gameLoopId = null;
|
||||
let lastTime = 0;
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
function init() {
|
||||
console.log('🎮 初始化俄罗斯方块游戏...');
|
||||
|
||||
// 获取Canvas和上下文
|
||||
canvas = document.getElementById('game-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
console.error('❌ 无法获取Canvas 2D上下文!');
|
||||
alert('游戏初始化失败:无法获取Canvas上下文');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ Canvas 2D上下文获取成功');
|
||||
console.log(`Canvas尺寸: ${canvas.width}x${canvas.height}`);
|
||||
|
||||
// 初始化游戏板
|
||||
resetBoard();
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
generateNextPiece();
|
||||
|
||||
// 设置事件监听器
|
||||
setupEventListeners();
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
|
||||
console.log('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
function resetBoard() {
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
}
|
||||
|
||||
function spawnNewPiece() {
|
||||
if (nextPiece) {
|
||||
// 使用预览方块 - 直接复制所有属性
|
||||
currentPiece = {
|
||||
type: nextPiece.type,
|
||||
shape: nextPiece.shape,
|
||||
color: nextPiece.color,
|
||||
name: nextPiece.name,
|
||||
x: nextPiece.x, // 直接使用nextPiece的x
|
||||
y: nextPiece.y // 直接使用nextPiece的y
|
||||
};
|
||||
} else {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
}
|
||||
|
||||
generateNextPiece();
|
||||
console.log(`生成新方块: ${currentPiece.type} (${currentPiece.name}) 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
}
|
||||
|
||||
function generateNextPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
nextPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
|
||||
document.getElementById('next-piece').textContent = nextPiece.name;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
console.log(`移动方块到: (${newX}, ${newY})`);
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
renderGame();
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
|
||||
// 计算得分:一次消除多行得分更高
|
||||
const lineScores = [0, 100, 300, 500, 800]; // 0-4行的得分
|
||||
score += lineScores[Math.min(linesCleared, 4)] * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
console.log(`消除 ${linesCleared} 行,得分: ${lineScores[Math.min(linesCleared, 4)] * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
console.log('旋转方块');
|
||||
renderGame();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvas.width - gameWidth) / 2;
|
||||
const offsetY = (canvas.height - gameHeight) / 2;
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制预览(下一个方块)
|
||||
if (nextPiece) {
|
||||
const previewX = offsetX + GRID_WIDTH * CELL_SIZE + 20;
|
||||
const previewY = offsetY;
|
||||
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
||||
ctx.fillRect(previewX, previewY, 100, 100);
|
||||
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.font = '14px Arial';
|
||||
ctx.fillText('下一个:', previewX + 10, previewY + 20);
|
||||
|
||||
// 绘制预览方块
|
||||
const previewShape = nextPiece.shape;
|
||||
const shapeWidth = previewShape[0].length;
|
||||
const shapeHeight = previewShape.length;
|
||||
const cellSize = 20;
|
||||
const shapeOffsetX = previewX + 50 - (shapeWidth * cellSize) / 2;
|
||||
const shapeOffsetY = previewY + 60 - (shapeHeight * cellSize) / 2;
|
||||
|
||||
for (let row = 0; row < shapeHeight; row++) {
|
||||
for (let col = 0; col < shapeWidth; col++) {
|
||||
if (previewShape[row][col]) {
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.fillRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameLoop(currentTime) {
|
||||
if (!gameRunning || gameOver) return;
|
||||
|
||||
// 计算时间增量
|
||||
const deltaTime = (currentTime - lastTime) / 1000; // 转换为秒
|
||||
lastTime = currentTime;
|
||||
|
||||
if (!gamePaused) {
|
||||
// 自动下落
|
||||
dropTimer += deltaTime;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
|
||||
// ==================== 游戏控制 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
console.log('🎮 开始游戏...');
|
||||
|
||||
// 隐藏菜单
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 重置游戏状态
|
||||
resetBoard();
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成方块
|
||||
spawnNewPiece();
|
||||
generateNextPiece();
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
lastTime = performance.now();
|
||||
|
||||
updateUI();
|
||||
renderGame();
|
||||
|
||||
// 启动游戏循环
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = '⏸️ 暂停';
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
console.log(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
document.getElementById('pause-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
}
|
||||
|
||||
window.restartGame = function() {
|
||||
console.log('🔄 重新开始游戏...');
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('game-over').style.display = 'none';
|
||||
|
||||
// 停止当前游戏循环
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
// 重新开始游戏
|
||||
startGame();
|
||||
};
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
document.getElementById('final-score').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('game-over').style.display = 'block';
|
||||
|
||||
console.log(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// ==================== 事件监听器 ====================
|
||||
function setupEventListeners() {
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
console.log(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// 按钮控制
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('pause-btn').addEventListener('click', togglePause);
|
||||
document.getElementById('restart-btn').addEventListener('click', restartGame);
|
||||
|
||||
// 移动端虚拟按钮
|
||||
document.getElementById('mobile-left').addEventListener('click', () => movePiece(-1, 0));
|
||||
document.getElementById('mobile-right').addEventListener('click', () => movePiece(1, 0));
|
||||
document.getElementById('mobile-down').addEventListener('click', () => movePiece(0, 1));
|
||||
document.getElementById('mobile-rotate').addEventListener('click', rotatePiece);
|
||||
|
||||
// 触摸事件(移动端)
|
||||
let touchStartX = 0;
|
||||
let touchStartY = 0;
|
||||
|
||||
canvas.addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
const touch = e.touches[0];
|
||||
touchStartX = touch.clientX;
|
||||
touchStartY = touch.clientY;
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchmove', (e) => {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchend', (e) => {
|
||||
e.preventDefault();
|
||||
const touch = e.changedTouches[0];
|
||||
const deltaX = touch.clientX - touchStartX;
|
||||
const deltaY = touch.clientY - touchStartY;
|
||||
|
||||
// 滑动控制
|
||||
if (Math.abs(deltaX) > Math.abs(deltaY)) {
|
||||
// 水平滑动
|
||||
if (deltaX > 30) movePiece(1, 0); // 右滑
|
||||
else if (deltaX < -30) movePiece(-1, 0); // 左滑
|
||||
} else {
|
||||
// 垂直滑动
|
||||
if (deltaY > 30) movePiece(0, 1); // 下滑
|
||||
else if (deltaY < -30) rotatePiece(); // 上滑(旋转)
|
||||
}
|
||||
});
|
||||
|
||||
// 窗口大小改变时调整Canvas
|
||||
window.addEventListener('resize', () => {
|
||||
renderGame();
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
console.log('页面加载完成');
|
||||
console.log(`浏览器: ${navigator.userAgent}`);
|
||||
console.log(`平台: ${navigator.platform}`);
|
||||
|
||||
init();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,877 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 最终Canvas 2D版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
#game-container {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
border: 2px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 10px;
|
||||
background: #111827;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
width: 540px;
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 10px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 14px;
|
||||
color: #aaa;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #00d4ff;
|
||||
}
|
||||
|
||||
#controls {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
padding: 12px 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.control-btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
.control-btn:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
#pause-btn {
|
||||
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
#menu p {
|
||||
color: #ccc;
|
||||
margin-bottom: 30px;
|
||||
max-width: 400px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
#game-over {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#game-over h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#final-score {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 移动端虚拟按钮 */
|
||||
#mobile-controls {
|
||||
display: none;
|
||||
position: absolute;
|
||||
bottom: 50px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.mobile-btn {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 28px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.mobile-btn:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
canvas {
|
||||
width: 300px;
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
width: 300px;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
flex: 1;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
#controls {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#mobile-controls {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
canvas {
|
||||
width: 280px;
|
||||
height: 380px;
|
||||
}
|
||||
|
||||
#info-panel {
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
#menu, #game-over {
|
||||
width: 90%;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
font-size: 36px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div id="info-panel">
|
||||
<div class="info-item">
|
||||
<div class="info-label">分数</div>
|
||||
<div class="info-value" id="score">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">等级</div>
|
||||
<div class="info-value" id="level">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">消行</div>
|
||||
<div class="info-value" id="lines">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">下一个</div>
|
||||
<div class="info-value" id="next-piece">?</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="controls">
|
||||
<button class="control-btn" id="start-btn">▶️ 开始</button>
|
||||
<button class="control-btn" id="pause-btn">⏸️ 暂停</button>
|
||||
<button class="control-btn" id="restart-btn">🔄 重来</button>
|
||||
</div>
|
||||
|
||||
<!-- 移动端虚拟按钮 -->
|
||||
<div id="mobile-controls">
|
||||
<div class="mobile-btn" id="mobile-left">←</div>
|
||||
<div class="mobile-btn" id="mobile-down">↓</div>
|
||||
<div class="mobile-btn" id="mobile-right">→</div>
|
||||
<div class="mobile-btn" id="mobile-rotate">↻</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 开始菜单 -->
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<p>经典的下落式方块游戏。使用方向键移动和旋转方块,填满整行消除得分!</p>
|
||||
<button class="control-btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; color: #888; font-size: 14px;">
|
||||
<p>🎮 控制:键盘方向键或虚拟按钮</p>
|
||||
<p>⬆️ 旋转:上箭头或旋转按钮</p>
|
||||
<p>⏸️ 暂停:P键或暂停按钮</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏结束界面 -->
|
||||
<div id="game-over">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="final-score">最终分数: 0</div>
|
||||
<button class="control-btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 游戏配置 ====================
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff', name: '长条' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff', name: 'J形' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000', name: 'L形' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00', name: '方块' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00', name: 'S形' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff', name: 'T形' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000', name: 'Z形' }
|
||||
];
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let canvas, ctx;
|
||||
let board = [];
|
||||
let currentPiece = null;
|
||||
let nextPiece = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
let gameLoopId = null;
|
||||
let lastTime = 0;
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
function init() {
|
||||
console.log('🎮 初始化俄罗斯方块游戏...');
|
||||
|
||||
// 获取Canvas和上下文
|
||||
canvas = document.getElementById('game-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
console.error('❌ 无法获取Canvas 2D上下文!');
|
||||
alert('游戏初始化失败:无法获取Canvas上下文');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ Canvas 2D上下文获取成功');
|
||||
console.log(`Canvas尺寸: ${canvas.width}x${canvas.height}`);
|
||||
|
||||
// 初始化游戏板
|
||||
resetBoard();
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
generateNextPiece();
|
||||
|
||||
// 设置事件监听器
|
||||
setupEventListeners();
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
|
||||
console.log('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
function resetBoard() {
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
}
|
||||
|
||||
function spawnNewPiece() {
|
||||
if (nextPiece) {
|
||||
currentPiece = {
|
||||
type: nextPiece.type,
|
||||
shape: nextPiece.shape,
|
||||
color: nextPiece.color,
|
||||
name: nextPiece.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(nextPiece.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
} else {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
}
|
||||
|
||||
generateNextPiece();
|
||||
console.log(`生成新方块: ${currentPiece.type} (${currentPiece.name}) 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
}
|
||||
|
||||
function generateNextPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
nextPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
|
||||
document.getElementById('next-piece').textContent = nextPiece.name;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
console.log(`移动方块到: (${newX}, ${newY})`);
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
renderGame();
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
|
||||
// 计算得分:一次消除多行得分更高
|
||||
const lineScores = [0, 100, 300, 500, 800]; // 0-4行的得分
|
||||
score += lineScores[Math.min(linesCleared, 4)] * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
console.log(`消除 ${linesCleared} 行,得分: ${lineScores[Math.min(linesCleared, 4)] * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
console.log('旋转方块');
|
||||
renderGame();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvas.width - gameWidth) / 2;
|
||||
const offsetY = (canvas.height - gameHeight) / 2;
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制预览(下一个方块)
|
||||
if (nextPiece) {
|
||||
const previewX = offsetX + GRID_WIDTH * CELL_SIZE + 20;
|
||||
const previewY = offsetY;
|
||||
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
||||
ctx.fillRect(previewX, previewY, 100, 100);
|
||||
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.font = '14px Arial';
|
||||
ctx.fillText('下一个:', previewX + 10, previewY + 20);
|
||||
|
||||
// 绘制预览方块
|
||||
const previewShape = nextPiece.shape;
|
||||
const shapeWidth = previewShape[0].length;
|
||||
const shapeHeight = previewShape.length;
|
||||
const cellSize = 20;
|
||||
const shapeOffsetX = previewX + 50 - (shapeWidth * cellSize) / 2;
|
||||
const shapeOffsetY = previewY + 60 - (shapeHeight * cellSize) / 2;
|
||||
|
||||
for (let row = 0; row < shapeHeight; row++) {
|
||||
for (let col = 0; col < shapeWidth; col++) {
|
||||
if (previewShape[row][col]) {
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.fillRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameLoop(currentTime) {
|
||||
if (!gameRunning || gameOver) return;
|
||||
|
||||
// 计算时间增量
|
||||
const deltaTime = (currentTime - lastTime) / 1000; // 转换为秒
|
||||
lastTime = currentTime;
|
||||
|
||||
if (!gamePaused) {
|
||||
// 自动下落
|
||||
dropTimer += deltaTime;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
// 调试日志:检查currentPiece状态
|
||||
if (currentPiece) {
|
||||
console.log(`[游戏循环] 当前方块: ${currentPiece.type}, 位置: (${currentPiece.x}, ${currentPiece.y}), dropTimer: ${dropTimer.toFixed(3)}, dropInterval: ${dropInterval.toFixed(3)}`);
|
||||
} else {
|
||||
console.log(`[游戏循环] currentPiece为null或undefined`);
|
||||
}
|
||||
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
|
||||
// ==================== 游戏控制 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
console.log('🎮 开始游戏...');
|
||||
|
||||
// 隐藏菜单
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 重置游戏状态
|
||||
resetBoard();
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成方块
|
||||
spawnNewPiece();
|
||||
generateNextPiece();
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
lastTime = performance.now();
|
||||
|
||||
updateUI();
|
||||
renderGame();
|
||||
|
||||
// 启动游戏循环
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = '⏸️ 暂停';
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
console.log(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
document.getElementById('pause-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
}
|
||||
|
||||
window.restartGame = function() {
|
||||
console.log('🔄 重新开始游戏...');
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('game-over').style.display = 'none';
|
||||
|
||||
// 停止当前游戏循环
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
// 重新开始游戏
|
||||
startGame();
|
||||
};
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
document.getElementById('final-score').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('game-over').style.display = 'block';
|
||||
|
||||
console.log(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// ==================== 事件监听器 ====================
|
||||
function setupEventListeners() {
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
console.log(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// 按钮控制
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('pause-btn').addEventListener('click', togglePause);
|
||||
document.getElementById('restart-btn').addEventListener('click', restartGame);
|
||||
|
||||
// 移动端虚拟按钮
|
||||
document.getElementById('mobile-left').addEventListener('click', () => movePiece(-1, 0));
|
||||
document.getElementById('mobile-right').addEventListener('click', () => movePiece(1, 0));
|
||||
document.getElementById('mobile-down').addEventListener('click', () => movePiece(0, 1));
|
||||
document.getElementById('mobile-rotate').addEventListener('click', rotatePiece);
|
||||
|
||||
// 触摸事件(移动端)
|
||||
let touchStartX = 0;
|
||||
let touchStartY = 0;
|
||||
|
||||
canvas.addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
const touch = e.touches[0];
|
||||
touchStartX = touch.clientX;
|
||||
touchStartY = touch.clientY;
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchmove', (e) => {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchend', (e) => {
|
||||
e.preventDefault();
|
||||
const touch = e.changedTouches[0];
|
||||
const deltaX = touch.clientX - touchStartX;
|
||||
const deltaY = touch.clientY - touchStartY;
|
||||
|
||||
// 滑动控制
|
||||
if (Math.abs(deltaX) > Math.abs(deltaY)) {
|
||||
// 水平滑动
|
||||
if (deltaX > 30) movePiece(1, 0); // 右滑
|
||||
else if (deltaX < -30) movePiece(-1, 0); // 左滑
|
||||
} else {
|
||||
// 垂直滑动
|
||||
if (deltaY > 30) movePiece(0, 1); // 下滑
|
||||
else if (deltaY < -30) rotatePiece(); // 上滑(旋转)
|
||||
}
|
||||
});
|
||||
|
||||
// 窗口大小改变时调整Canvas
|
||||
window.addEventListener('resize', () => {
|
||||
renderGame();
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
console.log('页面加载完成');
|
||||
console.log(`浏览器: ${navigator.userAgent}`);
|
||||
console.log(`平台: ${navigator.platform}`);
|
||||
|
||||
init();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,972 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 最终修复完整版</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎮</text></svg>">
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Arial', 'Microsoft YaHei', sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 10px;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 1.2rem;
|
||||
opacity: 0.9;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.game-area {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.game-board {
|
||||
position: relative;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
canvas {
|
||||
display: block;
|
||||
border-radius: 5px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
min-width: 200px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
.info-item {
|
||||
margin-bottom: 15px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.7;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.next-piece {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
button {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 50px;
|
||||
padding: 12px 24px;
|
||||
font-size: 1.1rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.direction-buttons {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.dir-btn {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 50%;
|
||||
font-size: 1.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.rotate-btn {
|
||||
background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
|
||||
}
|
||||
|
||||
.instructions {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
margin-top: 30px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.instructions h3 {
|
||||
margin-bottom: 10px;
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.instructions ul {
|
||||
list-style: none;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.instructions li {
|
||||
margin-bottom: 8px;
|
||||
padding-left: 10px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.instructions li:before {
|
||||
content: "•";
|
||||
color: #667eea;
|
||||
position: absolute;
|
||||
left: -10px;
|
||||
}
|
||||
|
||||
.game-over {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
z-index: 100;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.menu {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.menu h2 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 30px;
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.menu-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.game-area {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
font-size: 1rem;
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.dir-btn {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
body {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 8px 16px;
|
||||
font-size: 0.9rem;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
.dir-btn {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<div class="subtitle">最终修复完整版 | Windows完美兼容 | 无NaN问题</div>
|
||||
</div>
|
||||
|
||||
<div class="game-area">
|
||||
<div class="game-board">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div id="menu" class="menu">
|
||||
<h2>🎮 俄罗斯方块</h2>
|
||||
<div class="menu-buttons">
|
||||
<button id="start-btn" onclick="startGame()">▶️ 开始游戏</button>
|
||||
<button onclick="showInstructions()">📖 游戏说明</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="game-over" class="game-over">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="final-score" class="info-value" style="margin-bottom: 20px;">最终分数: 0</div>
|
||||
<button onclick="restartGame()">🔄 重新开始</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<div class="info-label">分数</div>
|
||||
<div id="score" class="info-value">0</div>
|
||||
</div>
|
||||
|
||||
<div class="info-item">
|
||||
<div class="info-label">等级</div>
|
||||
<div id="level" class="info-value">1</div>
|
||||
</div>
|
||||
|
||||
<div class="info-item">
|
||||
<div class="info-label">消行数</div>
|
||||
<div id="lines" class="info-value">0</div>
|
||||
</div>
|
||||
|
||||
<div class="next-piece">
|
||||
<div class="info-label">下一个方块</div>
|
||||
<div id="next-piece" class="info-value">?</div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<div class="control-row">
|
||||
<button id="pause-btn" onclick="togglePause()">⏸️ 暂停</button>
|
||||
<button onclick="restartGame()">🔄 重来</button>
|
||||
</div>
|
||||
|
||||
<div class="direction-buttons">
|
||||
<button class="dir-btn" onclick="moveLeft()">←</button>
|
||||
<button class="dir-btn rotate-btn" onclick="rotatePiece()">↻</button>
|
||||
<button class="dir-btn" onclick="moveRight()">→</button>
|
||||
</div>
|
||||
|
||||
<div class="control-row">
|
||||
<button class="dir-btn" onclick="moveDown()" style="width: 100%;">↓ 快速下落</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="instructions" id="instructions" style="display: none;">
|
||||
<h3>🎮 游戏说明</h3>
|
||||
<ul>
|
||||
<li><strong>目标</strong>: 消除完整的行来获得分数</li>
|
||||
<li><strong>控制</strong>:
|
||||
<br>← → : 左右移动
|
||||
<br>↓ : 加速下落
|
||||
<br>空格键 : 旋转方块
|
||||
<br>P键 : 暂停/继续
|
||||
</li>
|
||||
<li><strong>计分规则</strong>:
|
||||
<br>1行: 100 × 等级
|
||||
<br>2行: 300 × 等级
|
||||
<br>3行: 500 × 等级
|
||||
<br>4行: 800 × 等级
|
||||
</li>
|
||||
<li><strong>等级提升</strong>: 每消除10行提升1级,下落速度加快</li>
|
||||
<li><strong>游戏结束</strong>: 方块堆到顶部无法生成新方块</li>
|
||||
</ul>
|
||||
<button onclick="hideInstructions()" style="margin-top: 15px; width: 100%;">返回游戏</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 游戏配置 ====================
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 30;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff', name: '长条' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff', name: 'J形' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff7f00', name: 'L形' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00', name: '方块' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00', name: 'S形' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#800080', name: 'T形' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000', name: 'Z形' }
|
||||
];
|
||||
|
||||
// ==================== 游戏状态 ====================
|
||||
let canvas, ctx;
|
||||
let board = [];
|
||||
let currentPiece = null;
|
||||
let nextPiece = null;
|
||||
let score = 0;
|
||||
let level = 1;
|
||||
let lines = 0;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let dropTimer = 0;
|
||||
let lastUpdate = 0;
|
||||
let gameLoopId = null;
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
function initGame() {
|
||||
console.log('🎮 初始化俄罗斯方块游戏...');
|
||||
|
||||
// 获取Canvas上下文
|
||||
canvas = document.getElementById('game-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
console.error('❌ 无法获取Canvas 2D上下文');
|
||||
alert('您的浏览器不支持Canvas 2D,请使用现代浏览器');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ Canvas 2D上下文获取成功');
|
||||
console.log(`Canvas尺寸: ${canvas.width}x${canvas.height}`);
|
||||
|
||||
// 初始化游戏板
|
||||
initBoard();
|
||||
|
||||
// 生成第一个预览方块
|
||||
generateNextPiece();
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
|
||||
console.log('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
function initBoard() {
|
||||
board = [];
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
board[y] = [];
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
board[y][x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateNextPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
nextPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
|
||||
document.getElementById('next-piece').textContent = nextPiece.name;
|
||||
}
|
||||
|
||||
function spawnNewPiece() {
|
||||
if (nextPiece) {
|
||||
// 使用预览方块 - 直接复制所有属性
|
||||
currentPiece = {
|
||||
type: nextPiece.type,
|
||||
shape: nextPiece.shape,
|
||||
color: nextPiece.color,
|
||||
name: nextPiece.name,
|
||||
x: nextPiece.x, // 直接使用nextPiece的x
|
||||
y: nextPiece.y // 直接使用nextPiece的y
|
||||
};
|
||||
} else {
|
||||
// 随机生成新方块
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
}
|
||||
|
||||
// 生成下一个预览方块
|
||||
generateNextPiece();
|
||||
|
||||
console.log(`生成新方块: ${currentPiece.type} (${currentPiece.name}) 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
// 检查边界
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查碰撞
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return false;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
console.log(`尝试移动方块: 从(${currentPiece.x}, ${currentPiece.y}) 到(${newX}, ${newY})`);
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
console.log(`✅ 移动方块到: (${newX}, ${newY})`);
|
||||
renderGame();
|
||||
return true;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
console.log('🔒 固定方块');
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 创建旋转后的形状
|
||||
const shape = currentPiece.shape;
|
||||
const rows = shape.length;
|
||||
const cols = shape[0].length;
|
||||
const rotated = [];
|
||||
|
||||
for (let i = 0; i < cols; i++) {
|
||||
rotated[i] = [];
|
||||
for (let j = 0; j < rows; j++) {
|
||||
rotated[i][j] = shape[rows - 1 - j][i];
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试旋转
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
console.log('✅ 旋转方块成功');
|
||||
renderGame();
|
||||
} else {
|
||||
console.log('⚠️ 旋转被阻挡');
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
if (!currentPiece) return;
|
||||
|
||||
for (let row = 0; row < currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < currentPiece.shape[row].length; col++) {
|
||||
if (currentPiece.shape[row][col]) {
|
||||
const x = currentPiece.x + col;
|
||||
const y = currentPiece.y + row;
|
||||
|
||||
if (y >= 0) {
|
||||
board[y][x] = currentPiece.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🔒 方块已固定');
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
let lineFull = true;
|
||||
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (!board[y][x]) {
|
||||
lineFull = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lineFull) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(new Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置(因为行下移了)
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
// 更新分数
|
||||
const points = [0, 100, 300, 500, 800][linesCleared] * level;
|
||||
score += points;
|
||||
lines += linesCleared;
|
||||
level = Math.floor(lines / 10) + 1;
|
||||
|
||||
updateUI();
|
||||
|
||||
console.log(`🎉 消除 ${linesCleared} 行,获得 ${points} 分`);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameLoop() {
|
||||
if (!gameRunning || gameOver || gamePaused) return;
|
||||
|
||||
const now = Date.now();
|
||||
const deltaTime = (now - lastUpdate) / 1000;
|
||||
|
||||
// 自动下落
|
||||
dropTimer += deltaTime;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1);
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
console.log(`[游戏循环] 自动下落: dropTimer=${dropTimer.toFixed(3)}, interval=${dropInterval.toFixed(3)}`);
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
lastUpdate = now;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 渲染 ====================
|
||||
function renderGame() {
|
||||
if (!ctx) return;
|
||||
|
||||
// 清空Canvas
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 计算偏移量使游戏板居中
|
||||
const offsetX = (canvas.width - GRID_WIDTH * CELL_SIZE) / 2;
|
||||
const offsetY = (canvas.height - GRID_HEIGHT * CELL_SIZE) / 2;
|
||||
|
||||
// 绘制背景网格
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.05)';
|
||||
ctx.fillRect(offsetX, offsetY, GRID_WIDTH * CELL_SIZE, GRID_HEIGHT * CELL_SIZE);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX + x * CELL_SIZE, offsetY);
|
||||
ctx.lineTo(offsetX + x * CELL_SIZE, offsetY + GRID_HEIGHT * CELL_SIZE);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, offsetY + y * CELL_SIZE);
|
||||
ctx.lineTo(offsetX + GRID_WIDTH * CELL_SIZE, offsetY + y * CELL_SIZE);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillStyle = board[y][x];
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
ctx.fillStyle = currentPiece.color;
|
||||
|
||||
for (let row = 0; row < currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < currentPiece.shape[row].length; col++) {
|
||||
if (currentPiece.shape[row][col]) {
|
||||
const rectX = offsetX + (currentPiece.x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (currentPiece.y + row) * CELL_SIZE;
|
||||
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
|
||||
ctx.fillStyle = currentPiece.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制预览(下一个方块)
|
||||
if (nextPiece) {
|
||||
const previewX = offsetX + GRID_WIDTH * CELL_SIZE + 20;
|
||||
const previewY = offsetY;
|
||||
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
||||
ctx.fillRect(previewX, previewY, 100, 100);
|
||||
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.font = '14px Arial';
|
||||
ctx.fillText('下一个:', previewX + 10, previewY + 20);
|
||||
|
||||
// 绘制预览方块
|
||||
const previewShape = nextPiece.shape;
|
||||
const shapeWidth = previewShape[0].length;
|
||||
const shapeHeight = previewShape.length;
|
||||
const cellSize = 20;
|
||||
const shapeOffsetX = previewX + 50 - (shapeWidth * cellSize) / 2;
|
||||
const shapeOffsetY = previewY + 60 - (shapeHeight * cellSize) / 2;
|
||||
|
||||
for (let row = 0; row < shapeHeight; row++) {
|
||||
for (let col = 0; col < shapeWidth; col++) {
|
||||
if (previewShape[row][col]) {
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.fillRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏控制 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
console.log('🎮 开始游戏...');
|
||||
|
||||
// 隐藏菜单
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 重置游戏状态
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
gameOver = false;
|
||||
score = 0;
|
||||
level = 1;
|
||||
lines = 0;
|
||||
dropTimer = 0;
|
||||
lastUpdate = Date.now();
|
||||
|
||||
// 初始化游戏板
|
||||
initBoard();
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 更新UI
|
||||
updateUI();
|
||||
|
||||
// 启动游戏循环 - 使用setInterval确保Windows兼容性
|
||||
if (gameLoopId) clearInterval(gameLoopId);
|
||||
gameLoopId = setInterval(gameLoop, 100); // 每100ms运行一次
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = '⏸️ 暂停';
|
||||
document.getElementById('pause-btn').textContent = '⏸️ 暂停';
|
||||
|
||||
console.log('✅ 游戏已启动,使用setInterval游戏循环');
|
||||
};
|
||||
|
||||
window.togglePause = function() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
console.log(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
document.getElementById('pause-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
};
|
||||
|
||||
window.restartGame = function() {
|
||||
console.log('🔄 重新开始游戏...');
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('game-over').style.display = 'none';
|
||||
|
||||
// 停止当前游戏循环
|
||||
if (gameLoopId) {
|
||||
clearInterval(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
// 重新开始游戏
|
||||
startGame();
|
||||
};
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (gameLoopId) {
|
||||
clearInterval(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
document.getElementById('final-score').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('game-over').style.display = 'flex';
|
||||
|
||||
console.log(`💀 游戏结束,最终分数: ${score}`);
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.moveLeft = function() { movePiece(-1, 0); };
|
||||
window.moveRight = function() { movePiece(1, 0); };
|
||||
window.moveDown = function() { movePiece(0, 1); };
|
||||
window.rotatePiece = function() { rotatePiece(); };
|
||||
|
||||
window.showInstructions = function() {
|
||||
document.getElementById('instructions').style.display = 'block';
|
||||
};
|
||||
|
||||
window.hideInstructions = function() {
|
||||
document.getElementById('instructions').style.display = 'none';
|
||||
};
|
||||
|
||||
// ==================== 键盘控制 ====================
|
||||
document.addEventListener('keydown', function(event) {
|
||||
if (!gameRunning || gameOver) return;
|
||||
|
||||
console.log(`键盘按键: ${event.key}`);
|
||||
|
||||
switch(event.key) {
|
||||
case 'ArrowLeft':
|
||||
event.preventDefault();
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
event.preventDefault();
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
event.preventDefault();
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case ' ':
|
||||
case 'ArrowUp':
|
||||
event.preventDefault();
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
event.preventDefault();
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 触摸控制 ====================
|
||||
let touchStartX = 0;
|
||||
let touchStartY = 0;
|
||||
|
||||
canvas.addEventListener('touchstart', function(event) {
|
||||
event.preventDefault();
|
||||
const touch = event.touches[0];
|
||||
touchStartX = touch.clientX;
|
||||
touchStartY = touch.clientY;
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchmove', function(event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchend', function(event) {
|
||||
event.preventDefault();
|
||||
const touch = event.changedTouches[0];
|
||||
const deltaX = touch.clientX - touchStartX;
|
||||
const deltaY = touch.clientY - touchStartY;
|
||||
|
||||
// 滑动阈值
|
||||
const threshold = 30;
|
||||
|
||||
if (Math.abs(deltaX) > Math.abs(deltaY)) {
|
||||
// 水平滑动
|
||||
if (deltaX > threshold) {
|
||||
movePiece(1, 0); // 右滑
|
||||
} else if (deltaX < -threshold) {
|
||||
movePiece(-1, 0); // 左滑
|
||||
}
|
||||
} else {
|
||||
// 垂直滑动
|
||||
if (deltaY > threshold) {
|
||||
movePiece(0, 1); // 下滑
|
||||
} else if (deltaY < -threshold) {
|
||||
rotatePiece(); // 上滑旋转
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 页面加载 ====================
|
||||
window.addEventListener('load', function() {
|
||||
console.log('📄 页面加载完成,开始初始化游戏...');
|
||||
initGame();
|
||||
|
||||
// 添加Windows兼容性提示
|
||||
console.log('🪟 Windows兼容性检查:');
|
||||
console.log('✅ Canvas 2D API: 支持');
|
||||
console.log('✅ 键盘事件: 支持');
|
||||
console.log('✅ 触摸事件: 支持');
|
||||
console.log('✅ 游戏循环: 使用setInterval确保兼容性');
|
||||
console.log('✅ 无NaN问题: nextPiece位置已修复');
|
||||
console.log('🎮 游戏已准备好,点击"开始游戏"按钮开始');
|
||||
});
|
||||
|
||||
// 防止页面滚动
|
||||
document.addEventListener('touchmove', function(event) {
|
||||
if (event.target === canvas) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}, { passive: false });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,769 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 手机版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- 纯Canvas 2D版本,手机优化 -->
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: manipulation;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
#game-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
box-shadow: 0 0 40px rgba(0, 100, 255, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #111827;
|
||||
max-width: 100%;
|
||||
max-height: 60vh;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮容器 */
|
||||
.controls-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 15px 30px;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-width: 120px;
|
||||
justify-content: center;
|
||||
touch-action: manipulation;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 32px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.control-button:active {
|
||||
transform: scale(0.9);
|
||||
background: linear-gradient(145deg, #0f172a 0%, #1e293b 100%);
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 12px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
/* 手机横屏适配 */
|
||||
@media (orientation: landscape) {
|
||||
#game-container {
|
||||
flex-direction: row;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
max-height: 80vh;
|
||||
max-width: 50vw;
|
||||
}
|
||||
|
||||
.controls-container {
|
||||
margin-top: 0;
|
||||
max-width: 40vw;
|
||||
}
|
||||
}
|
||||
|
||||
/* 小屏幕适配 */
|
||||
@media (max-width: 480px) {
|
||||
canvas {
|
||||
width: 300px;
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
font-size: 16px;
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="300" height="400"></canvas>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-info" id="debug-info">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug-info');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// ==================== 状态消息 ====================
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// ==================== 隐藏加载界面 ====================
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// ==================== 俄罗斯方块游戏 ====================
|
||||
class TetrisGame {
|
||||
constructor() {
|
||||
debugLog('🎮 创建TetrisGame实例');
|
||||
|
||||
// 获取画布
|
||||
this.canvas = document.getElementById('game-canvas');
|
||||
this.ctx = this.canvas.getContext('2d');
|
||||
|
||||
if (!this.canvas || !this.ctx) {
|
||||
debugLog('❌ Canvas元素或上下文未找到');
|
||||
showStatus('❌ Canvas初始化失败', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ Canvas初始化成功');
|
||||
|
||||
// 游戏配置
|
||||
this.gridWidth = 10; // 10列
|
||||
this.gridHeight = 20; // 20行
|
||||
this.cellSize = 20; // 每个格子大小(手机版更小)
|
||||
|
||||
// 游戏状态
|
||||
this.board = [];
|
||||
this.currentPiece = null;
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = true;
|
||||
this.isGameOver = false;
|
||||
this.gameLoop = null;
|
||||
this.dropTimer = 0;
|
||||
this.lastFrameTime = 0;
|
||||
|
||||
// 方块类型定义
|
||||
this.pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// 初始化游戏
|
||||
this.initGame();
|
||||
this.setupControls();
|
||||
this.setupUI();
|
||||
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
showStatus('✅ 俄罗斯方块已加载,点击开始按钮或按任意键开始游戏', 3000);
|
||||
hideLoading();
|
||||
}
|
||||
|
||||
initGame() {
|
||||
debugLog('初始化游戏逻辑');
|
||||
|
||||
// 清空游戏场地
|
||||
this.board = Array(this.gridHeight).fill().map(() => Array(this.gridWidth).fill(0));
|
||||
|
||||
// 重置游戏状态
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = false;
|
||||
this.isGameOver = false;
|
||||
this.dropTimer = 0;
|
||||
this.lastFrameTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
this.startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
this.updateUI();
|
||||
|
||||
debugLog('🎮 游戏开始!');
|
||||
}
|
||||
|
||||
spawnNewPiece() {
|
||||
const randomType = this.pieceTypes[Math.floor(Math.random() * this.pieceTypes.length)];
|
||||
this.currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(this.gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${this.currentPiece.type}`);
|
||||
}
|
||||
|
||||
startGameLoop() {
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
}
|
||||
|
||||
const gameLoop = (timestamp) => {
|
||||
if (!this.lastFrameTime) this.lastFrameTime = timestamp;
|
||||
|
||||
const deltaTime = timestamp - this.lastFrameTime;
|
||||
|
||||
// 自动下落
|
||||
if (!this.isPaused && !this.isGameOver) {
|
||||
this.dropTimer += deltaTime;
|
||||
|
||||
if (this.dropTimer > 1000 / this.gameSpeed) {
|
||||
this.movePiece(0, 1);
|
||||
this.dropTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染
|
||||
this.render();
|
||||
|
||||
// 继续循环
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
this.lastFrameTime = timestamp;
|
||||
};
|
||||
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
debugLog('✅ 游戏循环已启动');
|
||||
}
|
||||
|
||||
movePiece(dx, dy) {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
const newX = this.currentPiece.x + dx;
|
||||
const newY = this.currentPiece.y + dy;
|
||||
|
||||
if (this.isValidMove(this.currentPiece.shape, newX, newY)) {
|
||||
this.currentPiece.x = newX;
|
||||
this.currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
this.lockPiece();
|
||||
this.checkLines();
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!this.isValidMove(this.currentPiece.shape, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= this.gridWidth || newY >= this.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && this.board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
lockPiece() {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
this.board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = this.gridHeight - 1; y >= 0; y--) {
|
||||
if (this.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
this.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
this.board.unshift(Array(this.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
this.lines += linesCleared;
|
||||
this.score += linesCleared * 100 * (this.level + 1);
|
||||
this.level = Math.floor(this.lines / 10);
|
||||
this.gameSpeed = 1.0 + this.level * 0.1;
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (this.level + 1)}`);
|
||||
showStatus(`🎉 消除 ${linesCleared} 行!`, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
rotatePiece() {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(this.currentPiece.shape);
|
||||
if (this.isValidMove(rotated, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
gameOver() {
|
||||
this.isGameOver = true;
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
this.gameLoop = null;
|
||||
}
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${this.score}`);
|
||||
showStatus(`🎮 游戏结束!最终得分: ${this.score}`, 5000);
|
||||
}
|
||||
|
||||
togglePause() {
|
||||
this.isPaused = !this.isPaused;
|
||||
|
||||
if (this.isPaused) {
|
||||
debugLog('游戏暂停');
|
||||
showStatus('⏸️ 游戏暂停');
|
||||
} else {
|
||||
debugLog('游戏继续');
|
||||
showStatus('▶️ 游戏继续');
|
||||
this.lastFrameTime = performance.now();
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
render() {
|
||||
// 清空画布
|
||||
this.ctx.fillStyle = '#111827';
|
||||
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
this.ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
this.ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= this.gridWidth; x++) {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(x * this.cellSize, 0);
|
||||
this.ctx.lineTo(x * this.cellSize, this.canvas.height);
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= this.gridHeight; y++) {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(0, y * this.cellSize);
|
||||
this.ctx.lineTo(this.canvas.width, y * this.cellSize);
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < this.gridHeight; y++) {
|
||||
for (let x = 0; x < this.gridWidth; x++) {
|
||||
if (this.board[y][x]) {
|
||||
this.ctx.fillStyle = this.board[y][x];
|
||||
this.ctx.fillRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
this.ctx.strokeStyle = 'white';
|
||||
this.ctx.lineWidth = 2;
|
||||
this.ctx.strokeRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (this.currentPiece) {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
this.ctx.fillStyle = color;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
this.ctx.fillRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
this.ctx.strokeStyle = 'white';
|
||||
this.ctx.lineWidth = 2;
|
||||
this.ctx.strokeRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateUI() {
|
||||
document.getElementById('score').textContent = this.score;
|
||||
document.getElementById('level').textContent = this.level;
|
||||
document.getElementById('lines').textContent = this.lines;
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
debugLog('开始按钮点击');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
} else if (this.isPaused) {
|
||||
this.togglePause();
|
||||
} else if (this.isGameOver) {
|
||||
this.initGame();
|
||||
} else {
|
||||
this.togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
debugLog('重来按钮点击');
|
||||
this.initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
debugLog('左按钮点击');
|
||||
this.movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
debugLog('右按钮点击');
|
||||
this.movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
debugLog('下按钮点击');
|
||||
this.movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
debugLog('旋转按钮点击');
|
||||
this.rotatePiece();
|
||||
});
|
||||
|
||||
// 触摸事件
|
||||
document.getElementById('left-btn').addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
this.movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
this.movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
this.movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
this.rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPaused || this.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
this.movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
this.movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
this.movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
this.rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
this.togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
setupUI() {
|
||||
// 添加按钮按下效果
|
||||
document.querySelectorAll('.action-button, .control-button').forEach(btn => {
|
||||
btn.addEventListener('mousedown', () => {
|
||||
btn.style.transform = 'scale(0.95)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseup', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 创建游戏实例
|
||||
window.game = new TetrisGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
showStatus(`❌ JavaScript错误: ${e.message}`, 5000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,667 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 独立版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- 使用贪吃蛇相同的PlayCanvas版本 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#game-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
box-shadow: 0 0 40px rgba(0, 100, 255, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮容器 */
|
||||
.controls-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<canvas id="application" width="540" height="720"></canvas>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-info" id="debug-info">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 调试日志
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug-info');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// 显示状态消息
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// 隐藏加载界面
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// 游戏主类
|
||||
class TetrisGame {
|
||||
constructor() {
|
||||
debugLog('创建TetrisGame实例');
|
||||
|
||||
// 画布尺寸 (540x720 竖屏)
|
||||
this.width = 540;
|
||||
this.height = 720;
|
||||
|
||||
// 获取画布
|
||||
this.canvas = document.getElementById('application');
|
||||
if (!this.canvas) {
|
||||
debugLog('❌ Canvas元素未找到');
|
||||
showStatus('❌ Canvas元素未找到', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ Canvas元素找到');
|
||||
|
||||
// 初始化 PlayCanvas
|
||||
try {
|
||||
this.app = new pc.Application(this.canvas, {
|
||||
mouse: new pc.Mouse(this.canvas),
|
||||
touch: new pc.TouchDevice(this.canvas),
|
||||
elementInput: new pc.ElementInput(this.canvas)
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog(`❌ PlayCanvas 初始化失败: ${e.message}`);
|
||||
showStatus(`❌ 游戏引擎初始化失败: ${e.message}`, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
// 启动PlayCanvas
|
||||
try {
|
||||
this.app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
} catch (e) {
|
||||
debugLog(`❌ PlayCanvas 启动失败: ${e.message}`);
|
||||
showStatus(`❌ 游戏引擎启动失败: ${e.message}`, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置画布填充模式(使用贪吃蛇相同的设置)
|
||||
this.app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
this.app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
debugLog('✅ 画布设置完成');
|
||||
|
||||
// 游戏配置
|
||||
this.gridWidth = 10; // 10列
|
||||
this.gridHeight = 20; // 20行
|
||||
this.cellSize = 24; // 每个格子大小
|
||||
|
||||
// 游戏状态
|
||||
this.board = [];
|
||||
this.currentPiece = null;
|
||||
this.nextPiece = null;
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = true;
|
||||
this.isGameOver = false;
|
||||
this.gameLoop = null;
|
||||
this.lastDropTime = 0;
|
||||
|
||||
// 方块类型定义(简化版)
|
||||
this.pieceTypes = ['I', 'O', 'T', 'L', 'J', 'S', 'Z'];
|
||||
|
||||
// 延迟初始化游戏逻辑
|
||||
setTimeout(() => {
|
||||
this.initGame();
|
||||
this.setupControls();
|
||||
this.setupUI();
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
showStatus('✅ 俄罗斯方块已加载,点击开始按钮或按任意键开始游戏', 3000);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
initGame() {
|
||||
debugLog('初始化游戏逻辑');
|
||||
|
||||
// 清空游戏场地
|
||||
this.board = Array(this.gridHeight).fill().map(() => Array(this.gridWidth).fill(0));
|
||||
|
||||
// 重置游戏状态
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = false;
|
||||
this.isGameOver = false;
|
||||
this.lastDropTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
this.startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
this.updateUI();
|
||||
|
||||
debugLog('🎮 游戏开始!');
|
||||
}
|
||||
|
||||
spawnNewPiece() {
|
||||
const randomType = this.pieceTypes[Math.floor(Math.random() * this.pieceTypes.length)];
|
||||
this.currentPiece = {
|
||||
type: randomType,
|
||||
x: Math.floor(this.gridWidth / 2) - 1,
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${this.currentPiece.type}`);
|
||||
}
|
||||
|
||||
startGameLoop() {
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
}
|
||||
|
||||
const gameLoop = (timestamp) => {
|
||||
if (!this.lastDropTime) this.lastDropTime = timestamp;
|
||||
|
||||
const deltaTime = timestamp - this.lastDropTime;
|
||||
|
||||
// 自动下落
|
||||
if (!this.isPaused && !this.isGameOver && deltaTime > 1000 / this.gameSpeed) {
|
||||
this.movePiece(0, 1);
|
||||
this.lastDropTime = timestamp;
|
||||
}
|
||||
|
||||
// 渲染
|
||||
this.render();
|
||||
|
||||
// 继续循环
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
};
|
||||
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
debugLog('✅ 游戏循环已启动');
|
||||
}
|
||||
|
||||
movePiece(dx, dy) {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
const newX = this.currentPiece.x + dx;
|
||||
const newY = this.currentPiece.y + dy;
|
||||
|
||||
// 简单碰撞检测
|
||||
if (this.isValidMove(newX, newY)) {
|
||||
this.currentPiece.x = newX;
|
||||
this.currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
this.lockPiece();
|
||||
this.checkLines();
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!this.isValidMove(this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isValidMove(x, y) {
|
||||
// 简单边界检查
|
||||
if (x < 0 || x >= this.gridWidth || y >= this.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否与已有方块重叠
|
||||
if (y >= 0 && this.board[y] && this.board[y][x]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
lockPiece() {
|
||||
if (!this.currentPiece) return;
|
||||
|
||||
const { x, y, type } = this.currentPiece;
|
||||
|
||||
// 简单固定逻辑
|
||||
if (y >= 0) {
|
||||
this.board[y] = this.board[y] || [];
|
||||
this.board[y][x] = type;
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = this.gridHeight - 1; y >= 0; y--) {
|
||||
if (this.board[y] && this.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
this.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
this.board.unshift(Array(this.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
this.lines += linesCleared;
|
||||
this.score += linesCleared * 100 * (this.level + 1);
|
||||
this.level = Math.floor(this.lines / 10);
|
||||
this.gameSpeed = 1.0 + this.level * 0.1;
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (this.level + 1)}`);
|
||||
showStatus(`🎉 消除 ${linesCleared} 行!`, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
rotatePiece() {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
debugLog('旋转方块');
|
||||
// 简单旋转逻辑
|
||||
// 实际游戏中需要更复杂的旋转矩阵处理
|
||||
}
|
||||
|
||||
gameOver() {
|
||||
this.isGameOver = true;
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
this.gameLoop = null;
|
||||
}
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${this.score}`);
|
||||
showStatus(`🎮 游戏结束!最终得分: ${this.score}`, 5000);
|
||||
}
|
||||
|
||||
togglePause() {
|
||||
this.isPaused = !this.isPaused;
|
||||
|
||||
if (this.isPaused) {
|
||||
debugLog('游戏暂停');
|
||||
showStatus('⏸️ 游戏暂停');
|
||||
} else {
|
||||
debugLog('游戏继续');
|
||||
showStatus('▶️ 游戏继续');
|
||||
this.lastDropTime = performance.now();
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
render() {
|
||||
// 清空画布
|
||||
const ctx = this.app.graphicsDevice.gl;
|
||||
if (!ctx) return;
|
||||
|
||||
// 设置背景色
|
||||
ctx.clearColor(0.1, 0.1, 0.15, 1.0);
|
||||
ctx.clear(ctx.COLOR_BUFFER_BIT);
|
||||
|
||||
// 简单渲染逻辑
|
||||
// 实际游戏中需要更复杂的3D渲染
|
||||
}
|
||||
|
||||
updateUI() {
|
||||
document.getElementById('score').textContent = this.score;
|
||||
document.getElementById('level').textContent = this.level;
|
||||
document.getElementById('lines').textContent = this.lines;
|
||||
document.getElementById('speed').textContent = this.gameSpeed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
debugLog('开始按钮点击');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
} else if (this.isPaused) {
|
||||
this.togglePause();
|
||||
} else if (this.isGameOver) {
|
||||
this.initGame();
|
||||
} else {
|
||||
this.togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
debugLog('重来按钮点击');
|
||||
this.initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
debugLog('左按钮点击');
|
||||
this.movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
debugLog('右按钮点击');
|
||||
this.movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
debugLog('下按钮点击');
|
||||
this.movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
debugLog('旋转按钮点击');
|
||||
this.rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPaused || this.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
this.movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
this.movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
this.movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
this.rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
this.togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
setupUI() {
|
||||
// 添加按钮按下效果
|
||||
document.querySelectorAll('.action-button, .control-button').forEach(btn => {
|
||||
btn.addEventListener('mousedown', () => {
|
||||
btn.style.transform = 'scale(0.95)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseup', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 检查PlayCanvas是否加载
|
||||
if (typeof pc === 'undefined') {
|
||||
debugLog('❌ PlayCanvas 未加载');
|
||||
showStatus('❌ 游戏引擎加载失败,请刷新页面', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ PlayCanvas 已加载');
|
||||
|
||||
// 创建游戏实例
|
||||
window.game = new TetrisGame();
|
||||
|
||||
// 隐藏加载界面
|
||||
hideLoading();
|
||||
});
|
||||
|
||||
// 错误处理
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
showStatus(`❌ JavaScript错误: ${e.message}`, 5000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,698 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | PlayCanvas修复版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- PlayCanvas 1.66.0 - 和贪吃蛇完全一样 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* UI层 */
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#score {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#level {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#lines {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 15px 40px;
|
||||
font-size: 20px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#finalScore {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮 */
|
||||
.control-button {
|
||||
position: absolute;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 32px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
user-select: none;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
|
||||
.control-button:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 100px;
|
||||
left: 50px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 100px;
|
||||
right: 50px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 100px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 200px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
bottom: 300px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
bottom: 370px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
/* 移动端适配 */
|
||||
@media (max-width: 768px) {
|
||||
.control-button {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 80px;
|
||||
left: 30px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 80px;
|
||||
right: 30px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 80px;
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 170px;
|
||||
}
|
||||
|
||||
#start-btn, #restart-btn {
|
||||
width: 100px;
|
||||
height: 45px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="application" style="display:block;width:100%;height:100%;"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<div id="score">分数: 0</div>
|
||||
<div id="level">等级: 0</div>
|
||||
<div id="lines">消行: 0</div>
|
||||
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; padding: 20px; background: rgba(0,0,0,0.6); border-radius: 15px; max-width: 320px; text-align: left;">
|
||||
<h3 style="color: #00d4ff; margin-bottom: 15px; text-align: center;">📜 游戏规则</h3>
|
||||
<div style="color: #ccc; font-size: 14px; line-height: 1.8;">
|
||||
<p style="margin-bottom: 8px;"><span style="color: #4ecdc4;">🎮 控制:</span> 键盘方向键或虚拟按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ffeaa7;">⬆️ 旋转:</span> 上箭头或旋转按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ff6b6b;">⚠️ 目标:</span> 填满整行消除得分</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #fd79a8;">🎯 技巧:</span> 一次消除多行得分更高</p>
|
||||
<p style="margin-bottom: 0;"><span style="color: #a29bfe;">⭐ 提示:</span> 等级越高,方块下落越快!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="finalScore">最终分数: 0</div>
|
||||
<button class="btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<!-- 虚拟控制按钮 -->
|
||||
<div class="control-button" id="left-btn">←</div>
|
||||
<div class="control-button" id="right-btn">→</div>
|
||||
<div class="control-button" id="down-btn">↓</div>
|
||||
<div class="control-button" id="rotate-btn">↻ 旋转</div>
|
||||
<div class="control-button" id="start-btn">▶️ 开始</div>
|
||||
<div class="control-button" id="restart-btn">🔄 重来</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
console.log(`[${new Date().toLocaleTimeString()}] ${message}`);
|
||||
}
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let app = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
|
||||
// 游戏场地
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
let board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
let currentPiece = null;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = `分数: ${score}`;
|
||||
document.getElementById('level').textContent = `等级: ${level}`;
|
||||
document.getElementById('lines').textContent = `消行: ${lines}`;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type}`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
document.getElementById('finalScore').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
function restartGame() {
|
||||
// 重置游戏状态
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
updateUI();
|
||||
debugLog('🎮 游戏重新开始!');
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
if (!app || !gameRunning) return;
|
||||
|
||||
// 获取2D上下文
|
||||
const ctx = app.graphicsDevice.canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const canvasWidth = ctx.canvas.width;
|
||||
const canvasHeight = ctx.canvas.height;
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvasWidth - gameWidth) / 2;
|
||||
const offsetY = (canvasHeight - gameHeight) / 2;
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameUpdate(dt) {
|
||||
if (!gameRunning || gamePaused || gameOver) return;
|
||||
|
||||
// 自动下落
|
||||
dropTimer += dt;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
|
||||
// 渲染游戏
|
||||
renderGame();
|
||||
}
|
||||
|
||||
// ==================== 初始化游戏 ====================
|
||||
function initGame() {
|
||||
debugLog('🎮 初始化 PlayCanvas...');
|
||||
|
||||
const canvas = document.getElementById('application');
|
||||
if (!canvas) {
|
||||
debugLog('❌ Canvas 元素未找到!');
|
||||
alert('游戏加载失败:Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
app = new pc.Application(canvas, {
|
||||
mouse: new pc.Mouse(canvas),
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas), // 移动端支持
|
||||
elementInput: new pc.ElementInput(canvas)
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog('❌ PlayCanvas 初始化失败:', e);
|
||||
alert('游戏引擎初始化失败: ' + e.message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
window.addEventListener('resize', () => app.resizeCanvas());
|
||||
|
||||
// 设置游戏循环
|
||||
app.on('update', gameUpdate);
|
||||
|
||||
// 初始化游戏状态
|
||||
restartGame();
|
||||
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.startGame = function() {
|
||||
debugLog('🎮 开始游戏...');
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
debugLog(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
}
|
||||
|
||||
// ==================== 设置控件事件 ====================
|
||||
function setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 虚拟按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('restart-btn').addEventListener('click', restartGame);
|
||||
document.getElementById('left-btn').addEventListener('click', () => movePiece(-1, 0));
|
||||
document.getElementById('right-btn').addEventListener('click', () => movePiece(1, 0));
|
||||
document.getElementById('down-btn').addEventListener('click', () => movePiece(0, 1));
|
||||
document.getElementById('rotate-btn').addEventListener('click', rotatePiece);
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 设置控件
|
||||
setupControls();
|
||||
|
||||
// 初始化游戏
|
||||
initGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,747 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | PlayCanvas渲染修复版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- PlayCanvas 1.66.0 - 和贪吃蛇完全一样 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* UI层 */
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#score {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#level {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#lines {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 15px 40px;
|
||||
font-size: 20px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#finalScore {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮 */
|
||||
.control-button {
|
||||
position: absolute;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 32px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
user-select: none;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
|
||||
.control-button:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 100px;
|
||||
left: 50px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 100px;
|
||||
right: 50px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 100px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 200px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
bottom: 300px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
bottom: 370px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
/* 移动端适配 */
|
||||
@media (max-width: 768px) {
|
||||
.control-button {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 80px;
|
||||
left: 30px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 80px;
|
||||
right: 30px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 80px;
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 170px;
|
||||
}
|
||||
|
||||
#start-btn, #restart-btn {
|
||||
width: 100px;
|
||||
height: 45px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="application" style="display:block;width:100%;height:100%;"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<div id="score">分数: 0</div>
|
||||
<div id="level">等级: 0</div>
|
||||
<div id="lines">消行: 0</div>
|
||||
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; padding: 20px; background: rgba(0,0,0,0.6); border-radius: 15px; max-width: 320px; text-align: left;">
|
||||
<h3 style="color: #00d4ff; margin-bottom: 15px; text-align: center;">📜 游戏规则</h3>
|
||||
<div style="color: #ccc; font-size: 14px; line-height: 1.8;">
|
||||
<p style="margin-bottom: 8px;"><span style="color: #4ecdc4;">🎮 控制:</span> 键盘方向键或虚拟按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ffeaa7;">⬆️ 旋转:</span> 上箭头或旋转按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ff6b6b;">⚠️ 目标:</span> 填满整行消除得分</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #fd79a8;">🎯 技巧:</span> 一次消除多行得分更高</p>
|
||||
<p style="margin-bottom: 0;"><span style="color: #a29bfe;">⭐ 提示:</span> 等级越高,方块下落越快!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="finalScore">最终分数: 0</div>
|
||||
<button class="btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<!-- 虚拟控制按钮 -->
|
||||
<div class="control-button" id="left-btn">←</div>
|
||||
<div class="control-button" id="right-btn">→</div>
|
||||
<div class="control-button" id="down-btn">↓</div>
|
||||
<div class="control-button" id="rotate-btn">↻ 旋转</div>
|
||||
<div class="control-button" id="start-btn">▶️ 开始</div>
|
||||
<div class="control-button" id="restart-btn">🔄 重来</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
console.log(`[${new Date().toLocaleTimeString()}] ${message}`);
|
||||
}
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let app = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
|
||||
// 游戏场地
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
let board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
let currentPiece = null;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = `分数: ${score}`;
|
||||
document.getElementById('level').textContent = `等级: ${level}`;
|
||||
document.getElementById('lines').textContent = `消行: ${lines}`;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type} 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
debugLog(`移动方块到: (${newX}, ${newY})`);
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
document.getElementById('finalScore').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
function restartGame() {
|
||||
// 重置游戏状态
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
updateUI();
|
||||
debugLog('🎮 游戏重新开始!');
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
if (!app || !gameRunning) return;
|
||||
|
||||
// 获取2D上下文
|
||||
const canvas = app.graphicsDevice.canvas;
|
||||
if (!canvas) {
|
||||
debugLog('❌ Canvas 未找到!');
|
||||
return;
|
||||
}
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) {
|
||||
debugLog('❌ Canvas 2D上下文未找到!');
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog(`渲染游戏: canvas尺寸=${canvas.width}x${canvas.height}`);
|
||||
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const canvasWidth = canvas.width;
|
||||
const canvasHeight = canvas.height;
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvasWidth - gameWidth) / 2;
|
||||
const offsetY = (canvasHeight - gameHeight) / 2;
|
||||
|
||||
debugLog(`游戏区域: offsetX=${offsetX}, offsetY=${offsetY}, gameWidth=${gameWidth}, gameHeight=${gameHeight}`);
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
let fixedCount = 0;
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
fixedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`绘制了 ${fixedCount} 个固定方块`);
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
let currentCount = 0;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`绘制了 ${currentCount} 个当前方块单元,位置: (${x}, ${y})`);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameUpdate(dt) {
|
||||
if (!gameRunning || gamePaused || gameOver) return;
|
||||
|
||||
// 自动下落
|
||||
dropTimer += dt;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
|
||||
// 渲染游戏
|
||||
renderGame();
|
||||
}
|
||||
|
||||
// ==================== 初始化游戏 ====================
|
||||
function initGame() {
|
||||
debugLog('🎮 初始化 PlayCanvas...');
|
||||
|
||||
const canvas = document.getElementById('application');
|
||||
if (!canvas) {
|
||||
debugLog('❌ Canvas 元素未找到!');
|
||||
alert('游戏加载失败:Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 简化配置:只使用键盘和触摸,移除鼠标事件
|
||||
app = new pc.Application(canvas, {
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas) // 移动端支持
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog('❌ PlayCanvas 初始化失败:', e);
|
||||
alert('游戏引擎初始化失败: ' + e.message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
window.addEventListener('resize', () => app.resizeCanvas());
|
||||
|
||||
// 设置游戏循环
|
||||
app.on('update', gameUpdate);
|
||||
|
||||
// 初始化游戏状态(但不开始游戏)
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
updateUI();
|
||||
debugLog('✅ 游戏初始化完成(等待开始)');
|
||||
|
||||
// 立即渲染一次,显示初始状态
|
||||
setTimeout(() => {
|
||||
renderGame();
|
||||
debugLog('初始渲染完成');
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.startGame = function() {
|
||||
debugLog('🎮 开始游戏...');
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
debugLog(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
}
|
||||
|
||||
// ==================== 设置控件事件 ====================
|
||||
function setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 虚拟按钮 - 使用事件委托防止重复绑定
|
||||
const ui = document.getElementById('ui');
|
||||
|
||||
ui.addEventListener('click', (e) => {
|
||||
const target = e.target;
|
||||
|
||||
if (target.id === 'start-btn') {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
} else if (target.id === 'restart-btn') {
|
||||
restartGame();
|
||||
} else if (target.id === 'left-btn') {
|
||||
movePiece(-1, 0);
|
||||
} else if (target.id === 'right-btn') {
|
||||
movePiece(1, 0);
|
||||
} else if (target.id === 'down-btn') {
|
||||
movePiece(0, 1);
|
||||
} else if (target.id === 'rotate-btn') {
|
||||
rotatePiece();
|
||||
}
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 设置控件
|
||||
setupControls();
|
||||
|
||||
// 初始化游戏
|
||||
initGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,707 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | PlayCanvas简化版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- PlayCanvas 1.66.0 - 和贪吃蛇完全一样 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* UI层 */
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#score {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#level {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#lines {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 15px 40px;
|
||||
font-size: 20px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#finalScore {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮 */
|
||||
.control-button {
|
||||
position: absolute;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 32px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
user-select: none;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
|
||||
.control-button:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 100px;
|
||||
left: 50px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 100px;
|
||||
right: 50px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 100px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 200px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
bottom: 300px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
bottom: 370px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
/* 移动端适配 */
|
||||
@media (max-width: 768px) {
|
||||
.control-button {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 80px;
|
||||
left: 30px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 80px;
|
||||
right: 30px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 80px;
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 170px;
|
||||
}
|
||||
|
||||
#start-btn, #restart-btn {
|
||||
width: 100px;
|
||||
height: 45px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="application" style="display:block;width:100%;height:100%;"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<div id="score">分数: 0</div>
|
||||
<div id="level">等级: 0</div>
|
||||
<div id="lines">消行: 0</div>
|
||||
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; padding: 20px; background: rgba(0,0,0,0.6); border-radius: 15px; max-width: 320px; text-align: left;">
|
||||
<h3 style="color: #00d4ff; margin-bottom: 15px; text-align: center;">📜 游戏规则</h3>
|
||||
<div style="color: #ccc; font-size: 14px; line-height: 1.8;">
|
||||
<p style="margin-bottom: 8px;"><span style="color: #4ecdc4;">🎮 控制:</span> 键盘方向键或虚拟按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ffeaa7;">⬆️ 旋转:</span> 上箭头或旋转按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ff6b6b;">⚠️ 目标:</span> 填满整行消除得分</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #fd79a8;">🎯 技巧:</span> 一次消除多行得分更高</p>
|
||||
<p style="margin-bottom: 0;"><span style="color: #a29bfe;">⭐ 提示:</span> 等级越高,方块下落越快!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="finalScore">最终分数: 0</div>
|
||||
<button class="btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<!-- 虚拟控制按钮 -->
|
||||
<div class="control-button" id="left-btn">←</div>
|
||||
<div class="control-button" id="right-btn">→</div>
|
||||
<div class="control-button" id="down-btn">↓</div>
|
||||
<div class="control-button" id="rotate-btn">↻ 旋转</div>
|
||||
<div class="control-button" id="start-btn">▶️ 开始</div>
|
||||
<div class="control-button" id="restart-btn">🔄 重来</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
console.log(`[${new Date().toLocaleTimeString()}] ${message}`);
|
||||
}
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let app = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
|
||||
// 游戏场地
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
let board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
let currentPiece = null;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = `分数: ${score}`;
|
||||
document.getElementById('level').textContent = `等级: ${level}`;
|
||||
document.getElementById('lines').textContent = `消行: ${lines}`;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type}`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
document.getElementById('finalScore').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
function restartGame() {
|
||||
// 重置游戏状态
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
updateUI();
|
||||
debugLog('🎮 游戏重新开始!');
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
if (!app || !gameRunning) return;
|
||||
|
||||
// 获取2D上下文
|
||||
const ctx = app.graphicsDevice.canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const canvasWidth = ctx.canvas.width;
|
||||
const canvasHeight = ctx.canvas.height;
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvasWidth - gameWidth) / 2;
|
||||
const offsetY = (canvasHeight - gameHeight) / 2;
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameUpdate(dt) {
|
||||
if (!gameRunning || gamePaused || gameOver) return;
|
||||
|
||||
// 自动下落
|
||||
dropTimer += dt;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
|
||||
// 渲染游戏
|
||||
renderGame();
|
||||
}
|
||||
|
||||
// ==================== 初始化游戏 ====================
|
||||
function initGame() {
|
||||
debugLog('🎮 初始化 PlayCanvas...');
|
||||
|
||||
const canvas = document.getElementById('application');
|
||||
if (!canvas) {
|
||||
debugLog('❌ Canvas 元素未找到!');
|
||||
alert('游戏加载失败:Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 简化配置:只使用键盘和触摸,移除鼠标事件
|
||||
app = new pc.Application(canvas, {
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas) // 移动端支持
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog('❌ PlayCanvas 初始化失败:', e);
|
||||
alert('游戏引擎初始化失败: ' + e.message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
window.addEventListener('resize', () => app.resizeCanvas());
|
||||
|
||||
// 设置游戏循环
|
||||
app.on('update', gameUpdate);
|
||||
|
||||
// 初始化游戏状态
|
||||
restartGame();
|
||||
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.startGame = function() {
|
||||
debugLog('🎮 开始游戏...');
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
debugLog(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
}
|
||||
|
||||
// ==================== 设置控件事件 ====================
|
||||
function setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 虚拟按钮 - 使用事件委托防止重复绑定
|
||||
const ui = document.getElementById('ui');
|
||||
|
||||
ui.addEventListener('click', (e) => {
|
||||
const target = e.target;
|
||||
|
||||
if (target.id === 'start-btn') {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
} else if (target.id === 'restart-btn') {
|
||||
restartGame();
|
||||
} else if (target.id === 'left-btn') {
|
||||
movePiece(-1, 0);
|
||||
} else if (target.id === 'right-btn') {
|
||||
movePiece(1, 0);
|
||||
} else if (target.id === 'down-btn') {
|
||||
movePiece(0, 1);
|
||||
} else if (target.id === 'rotate-btn') {
|
||||
rotatePiece();
|
||||
}
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 设置控件
|
||||
setupControls();
|
||||
|
||||
// 初始化游戏
|
||||
initGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,829 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | PlayCanvas超级调试版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- PlayCanvas 1.66.0 - 和贪吃蛇完全一样 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
border: 2px solid red; /* 调试:显示Canvas边界 */
|
||||
}
|
||||
|
||||
/* UI层 */
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#score {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#level {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#lines {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 15px 40px;
|
||||
font-size: 20px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#finalScore {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮 */
|
||||
.control-button {
|
||||
position: absolute;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 32px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
user-select: none;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
|
||||
.control-button:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 100px;
|
||||
left: 50px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 100px;
|
||||
right: 50px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 100px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 200px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
bottom: 300px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
bottom: 370px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
/* 调试信息 */
|
||||
#debug {
|
||||
position: absolute;
|
||||
top: 100px;
|
||||
right: 20px;
|
||||
background: rgba(0,0,0,0.7);
|
||||
color: #00ff00;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
pointer-events: none;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
/* 移动端适配 */
|
||||
@media (max-width: 768px) {
|
||||
.control-button {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 80px;
|
||||
left: 30px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 80px;
|
||||
right: 30px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 80px;
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 170px;
|
||||
}
|
||||
|
||||
#start-btn, #restart-btn {
|
||||
width: 100px;
|
||||
height: 45px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="application" style="display:block;width:100%;height:100%;"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<div id="score">分数: 0</div>
|
||||
<div id="level">等级: 0</div>
|
||||
<div id="lines">消行: 0</div>
|
||||
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; padding: 20px; background: rgba(0,0,0,0.6); border-radius: 15px; max-width: 320px; text-align: left;">
|
||||
<h3 style="color: #00d4ff; margin-bottom: 15px; text-align: center;">📜 游戏规则</h3>
|
||||
<div style="color: #ccc; font-size: 14px; line-height: 1.8;">
|
||||
<p style="margin-bottom: 8px;"><span style="color: #4ecdc4;">🎮 控制:</span> 键盘方向键或虚拟按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ffeaa7;">⬆️ 旋转:</span> 上箭头或旋转按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ff6b6b;">⚠️ 目标:</span> 填满整行消除得分</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #fd79a8;">🎯 技巧:</span> 一次消除多行得分更高</p>
|
||||
<p style="margin-bottom: 0;"><span style="color: #a29bfe;">⭐ 提示:</span> 等级越高,方块下落越快!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="finalScore">最终分数: 0</div>
|
||||
<button class="btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<!-- 虚拟控制按钮 -->
|
||||
<div class="control-button" id="left-btn">←</div>
|
||||
<div class="control-button" id="right-btn">→</div>
|
||||
<div class="control-button" id="down-btn">↓</div>
|
||||
<div class="control-button" id="rotate-btn">↻ 旋转</div>
|
||||
<div class="control-button" id="start-btn">▶️ 开始</div>
|
||||
<div class="control-button" id="restart-btn">🔄 重来</div>
|
||||
|
||||
<!-- 调试信息 -->
|
||||
<div id="debug"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
const timestamp = new Date().toLocaleTimeString();
|
||||
console.log(`[${timestamp}] ${message}`);
|
||||
|
||||
// 同时显示在屏幕上
|
||||
const debugDiv = document.getElementById('debug');
|
||||
if (debugDiv) {
|
||||
const line = document.createElement('div');
|
||||
line.textContent = `[${timestamp}] ${message}`;
|
||||
debugDiv.appendChild(line);
|
||||
|
||||
// 限制显示行数
|
||||
while (debugDiv.children.length > 10) {
|
||||
debugDiv.removeChild(debugDiv.firstChild);
|
||||
}
|
||||
|
||||
// 自动滚动到底部
|
||||
debugDiv.scrollTop = debugDiv.scrollHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let app = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
|
||||
// 游戏场地
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
let board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
let currentPiece = null;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = `分数: ${score}`;
|
||||
document.getElementById('level').textContent = `等级: ${level}`;
|
||||
document.getElementById('lines').textContent = `消行: ${lines}`;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type} 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
debugLog(`移动方块到: (${newX}, ${newY})`);
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
document.getElementById('finalScore').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
function restartGame() {
|
||||
// 重置游戏状态
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
updateUI();
|
||||
debugLog('🎮 游戏重新开始!');
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
debugLog(`渲染游戏开始: app=${!!app}, gameRunning=${gameRunning}`);
|
||||
|
||||
if (!app) {
|
||||
debugLog('❌ 渲染失败: app 为 null');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gameRunning) {
|
||||
debugLog('❌ 渲染失败: gameRunning 为 false');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取Canvas元素
|
||||
const canvas = app.graphicsDevice.canvas;
|
||||
if (!canvas) {
|
||||
debugLog('❌ 渲染失败: Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog(`Canvas尺寸: ${canvas.width}x${canvas.height}`);
|
||||
|
||||
// 获取2D上下文
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) {
|
||||
debugLog('❌ 渲染失败: Canvas 2D上下文未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ 获取到Canvas 2D上下文');
|
||||
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const canvasWidth = canvas.width;
|
||||
const canvasHeight = canvas.height;
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvasWidth - gameWidth) / 2;
|
||||
const offsetY = (canvasHeight - gameHeight) / 2;
|
||||
|
||||
debugLog(`游戏区域: offsetX=${offsetX.toFixed(1)}, offsetY=${offsetY.toFixed(1)}, gameWidth=${gameWidth}, gameHeight=${gameHeight}`);
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
let fixedCount = 0;
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
fixedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`绘制了 ${fixedCount} 个固定方块`);
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
let currentCount = 0;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`绘制了 ${currentCount} 个当前方块单元,位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
debugLog('✅ 渲染完成');
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameUpdate(dt) {
|
||||
debugLog(`游戏循环开始: gameRunning=${gameRunning}, gamePaused=${gamePaused}, gameOver=${gameOver}`);
|
||||
|
||||
if (!gameRunning) {
|
||||
debugLog('❌ 游戏循环跳过: gameRunning 为 false');
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused) {
|
||||
debugLog('❌ 游戏循环跳过: gamePaused 为 true');
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameOver) {
|
||||
debugLog('❌ 游戏循环跳过: gameOver 为 true');
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog(`游戏循环 dt=${dt.toFixed(3)} 秒, dropTimer=${dropTimer.toFixed(3)}`);
|
||||
|
||||
// 自动下落
|
||||
dropTimer += dt;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
debugLog(`方块自动下落: dropTimer=${dropTimer.toFixed(3)} > dropInterval=${dropInterval.toFixed(3)}`);
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
|
||||
// 渲染游戏
|
||||
debugLog('开始渲染...');
|
||||
renderGame();
|
||||
debugLog('渲染完成');
|
||||
}
|
||||
|
||||
// ==================== 初始化游戏 ====================
|
||||
function initGame() {
|
||||
debugLog('🎮 初始化 PlayCanvas...');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
const canvas = document.getElementById('application');
|
||||
if (!canvas) {
|
||||
debugLog('❌ Canvas 元素未找到!');
|
||||
alert('游戏加载失败:Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog(`Canvas元素: ${canvas.tagName}, 尺寸: ${canvas.width}x${canvas.height}`);
|
||||
|
||||
try {
|
||||
// 简化配置:只使用键盘和触摸,移除鼠标事件
|
||||
app = new pc.Application(canvas, {
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas) // 移动端支持
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog('❌ PlayCanvas 初始化失败:', e);
|
||||
alert('游戏引擎初始化失败: ' + e.message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
debugLog('窗口大小改变');
|
||||
app.resizeCanvas();
|
||||
});
|
||||
|
||||
// 设置游戏循环
|
||||
app.on('update', gameUpdate);
|
||||
debugLog('✅ 游戏循环已设置');
|
||||
|
||||
// 初始化游戏状态(但不开始游戏)
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
updateUI();
|
||||
debugLog('✅ 游戏初始化完成(等待开始)');
|
||||
|
||||
// 立即渲染一次,显示初始状态
|
||||
setTimeout(() => {
|
||||
debugLog('执行初始渲染...');
|
||||
renderGame();
|
||||
debugLog('初始渲染完成');
|
||||
}, 500);
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.startGame = function() {
|
||||
debugLog('🎮 开始游戏...');
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
debugLog(`游戏状态: gameRunning=${gameRunning}, gamePaused=${gamePaused}`);
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
debugLog(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
}
|
||||
|
||||
// ==================== 设置控件事件 ====================
|
||||
function setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 虚拟按钮 - 使用事件委托防止重复绑定
|
||||
const ui = document.getElementById('ui');
|
||||
|
||||
ui.addEventListener('click', (e) => {
|
||||
const target = e.target;
|
||||
|
||||
if (target.id === 'start-btn') {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
} else if (target.id === 'restart-btn') {
|
||||
restartGame();
|
||||
} else if (target.id === 'left-btn') {
|
||||
movePiece(-1, 0);
|
||||
} else if (target.id === 'right-btn') {
|
||||
movePiece(1, 0);
|
||||
} else if (target.id === 'down-btn') {
|
||||
movePiece(0, 1);
|
||||
} else if (target.id === 'rotate-btn') {
|
||||
rotatePiece();
|
||||
}
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
|
||||
// 设置控件
|
||||
setupControls();
|
||||
|
||||
// 初始化游戏
|
||||
initGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,721 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | PlayCanvas工作版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- PlayCanvas 1.66.0 - 和贪吃蛇完全一样 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* UI层 */
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#score {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#level {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#lines {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 15px 40px;
|
||||
font-size: 20px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#finalScore {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮 */
|
||||
.control-button {
|
||||
position: absolute;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 32px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
user-select: none;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
|
||||
.control-button:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 100px;
|
||||
left: 50px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 100px;
|
||||
right: 50px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 100px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 200px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
bottom: 300px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
bottom: 370px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
/* 移动端适配 */
|
||||
@media (max-width: 768px) {
|
||||
.control-button {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 80px;
|
||||
left: 30px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 80px;
|
||||
right: 30px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 80px;
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 170px;
|
||||
}
|
||||
|
||||
#start-btn, #restart-btn {
|
||||
width: 100px;
|
||||
height: 45px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="application" style="display:block;width:100%;height:100%;"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<div id="score">分数: 0</div>
|
||||
<div id="level">等级: 0</div>
|
||||
<div id="lines">消行: 0</div>
|
||||
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; padding: 20px; background: rgba(0,0,0,0.6); border-radius: 15px; max-width: 320px; text-align: left;">
|
||||
<h3 style="color: #00d4ff; margin-bottom: 15px; text-align: center;">📜 游戏规则</h3>
|
||||
<div style="color: #ccc; font-size: 14px; line-height: 1.8;">
|
||||
<p style="margin-bottom: 8px;"><span style="color: #4ecdc4;">🎮 控制:</span> 键盘方向键或虚拟按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ffeaa7;">⬆️ 旋转:</span> 上箭头或旋转按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ff6b6b;">⚠️ 目标:</span> 填满整行消除得分</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #fd79a8;">🎯 技巧:</span> 一次消除多行得分更高</p>
|
||||
<p style="margin-bottom: 0;"><span style="color: #a29bfe;">⭐ 提示:</span> 等级越高,方块下落越快!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="finalScore">最终分数: 0</div>
|
||||
<button class="btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<!-- 虚拟控制按钮 -->
|
||||
<div class="control-button" id="left-btn">←</div>
|
||||
<div class="control-button" id="right-btn">→</div>
|
||||
<div class="control-button" id="down-btn">↓</div>
|
||||
<div class="control-button" id="rotate-btn">↻ 旋转</div>
|
||||
<div class="control-button" id="start-btn">▶️ 开始</div>
|
||||
<div class="control-button" id="restart-btn">🔄 重来</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
console.log(`[${new Date().toLocaleTimeString()}] ${message}`);
|
||||
}
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let app = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
|
||||
// 游戏场地
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
let board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
let currentPiece = null;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = `分数: ${score}`;
|
||||
document.getElementById('level').textContent = `等级: ${level}`;
|
||||
document.getElementById('lines').textContent = `消行: ${lines}`;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type}`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
debugLog(`移动方块到: (${newX}, ${newY})`);
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
document.getElementById('finalScore').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
function restartGame() {
|
||||
// 重置游戏状态
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
updateUI();
|
||||
debugLog('🎮 游戏重新开始!');
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
if (!app || !gameRunning) return;
|
||||
|
||||
// 获取2D上下文
|
||||
const ctx = app.graphicsDevice.canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const canvasWidth = ctx.canvas.width;
|
||||
const canvasHeight = ctx.canvas.height;
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvasWidth - gameWidth) / 2;
|
||||
const offsetY = (canvasHeight - gameHeight) / 2;
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, offsetY);
|
||||
ctx.lineTo(lineX, offsetY + gameHeight);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, lineY);
|
||||
ctx.lineTo(offsetX + gameWidth, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameUpdate(dt) {
|
||||
if (!gameRunning || gamePaused || gameOver) return;
|
||||
|
||||
debugLog(`游戏循环 dt=${dt.toFixed(3)} 秒, dropTimer=${dropTimer.toFixed(3)}`);
|
||||
|
||||
// 自动下落
|
||||
dropTimer += dt;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
debugLog(`方块自动下落: dropTimer=${dropTimer.toFixed(3)} > dropInterval=${dropInterval.toFixed(3)}`);
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
|
||||
// 渲染游戏
|
||||
renderGame();
|
||||
}
|
||||
|
||||
// ==================== 初始化游戏 ====================
|
||||
function initGame() {
|
||||
debugLog('🎮 初始化 PlayCanvas...');
|
||||
|
||||
const canvas = document.getElementById('application');
|
||||
if (!canvas) {
|
||||
debugLog('❌ Canvas 元素未找到!');
|
||||
alert('游戏加载失败:Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 简化配置:只使用键盘和触摸,移除鼠标事件
|
||||
app = new pc.Application(canvas, {
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas) // 移动端支持
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog('❌ PlayCanvas 初始化失败:', e);
|
||||
alert('游戏引擎初始化失败: ' + e.message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
window.addEventListener('resize', () => app.resizeCanvas());
|
||||
|
||||
// 设置游戏循环
|
||||
app.on('update', gameUpdate);
|
||||
|
||||
// 初始化游戏状态(但不开始游戏)
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
updateUI();
|
||||
debugLog('✅ 游戏初始化完成(等待开始)');
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.startGame = function() {
|
||||
debugLog('🎮 开始游戏...');
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
debugLog(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
}
|
||||
|
||||
// ==================== 设置控件事件 ====================
|
||||
function setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 虚拟按钮 - 使用事件委托防止重复绑定
|
||||
const ui = document.getElementById('ui');
|
||||
|
||||
ui.addEventListener('click', (e) => {
|
||||
const target = e.target;
|
||||
|
||||
if (target.id === 'start-btn') {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
} else if (target.id === 'restart-btn') {
|
||||
restartGame();
|
||||
} else if (target.id === 'left-btn') {
|
||||
movePiece(-1, 0);
|
||||
} else if (target.id === 'right-btn') {
|
||||
movePiece(1, 0);
|
||||
} else if (target.id === 'down-btn') {
|
||||
movePiece(0, 1);
|
||||
} else if (target.id === 'rotate-btn') {
|
||||
rotatePiece();
|
||||
}
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 设置控件
|
||||
setupControls();
|
||||
|
||||
// 初始化游戏
|
||||
initGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,690 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 纯PlayCanvas版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- PlayCanvas 1.66.0 - 和贪吃蛇完全一样 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#application {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* UI层 */
|
||||
#ui {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#score {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#level {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#lines {
|
||||
position: absolute;
|
||||
top: 70px;
|
||||
left: 20px;
|
||||
color: #aaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#menu h1 {
|
||||
color: #00d4ff;
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 0 0 20px rgba(0,212,255,0.5);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 15px 40px;
|
||||
font-size: 20px;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
margin: 10px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 10px 30px rgba(102,126,234,0.4);
|
||||
}
|
||||
|
||||
#gameOver {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: rgba(0,0,0,0.8);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#gameOver h2 {
|
||||
color: #ff6b6b;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#finalScore {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮 */
|
||||
.control-button {
|
||||
position: absolute;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
color: white;
|
||||
font-size: 32px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
user-select: none;
|
||||
transition: all 0.1s;
|
||||
}
|
||||
|
||||
.control-button:active {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 100px;
|
||||
left: 50px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 100px;
|
||||
right: 50px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 100px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 200px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
#start-btn {
|
||||
bottom: 300px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #10b981, #047857);
|
||||
}
|
||||
|
||||
#restart-btn {
|
||||
bottom: 370px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 120px;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||
}
|
||||
|
||||
/* 移动端适配 */
|
||||
@media (max-width: 768px) {
|
||||
.control-button {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
#left-btn {
|
||||
bottom: 80px;
|
||||
left: 30px;
|
||||
}
|
||||
|
||||
#right-btn {
|
||||
bottom: 80px;
|
||||
right: 30px;
|
||||
}
|
||||
|
||||
#down-btn {
|
||||
bottom: 80px;
|
||||
}
|
||||
|
||||
#rotate-btn {
|
||||
bottom: 170px;
|
||||
}
|
||||
|
||||
#start-btn, #restart-btn {
|
||||
width: 100px;
|
||||
height: 45px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="application" style="display:block;width:100%;height:100%;"></canvas>
|
||||
|
||||
<div id="ui">
|
||||
<div id="score">分数: 0</div>
|
||||
<div id="level">等级: 0</div>
|
||||
<div id="lines">消行: 0</div>
|
||||
|
||||
<div id="menu">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<button class="btn" onclick="startGame()">开始游戏</button>
|
||||
<div style="margin-top: 30px; padding: 20px; background: rgba(0,0,0,0.6); border-radius: 15px; max-width: 320px; text-align: left;">
|
||||
<h3 style="color: #00d4ff; margin-bottom: 15px; text-align: center;">📜 游戏规则</h3>
|
||||
<div style="color: #ccc; font-size: 14px; line-height: 1.8;">
|
||||
<p style="margin-bottom: 8px;"><span style="color: #4ecdc4;">🎮 控制:</span> 键盘方向键或虚拟按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ffeaa7;">⬆️ 旋转:</span> 上箭头或旋转按钮</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #ff6b6b;">⚠️ 目标:</span> 填满整行消除得分</p>
|
||||
<p style="margin-bottom: 8px;"><span style="color: #fd79a8;">🎯 技巧:</span> 一次消除多行得分更高</p>
|
||||
<p style="margin-bottom: 0;"><span style="color: #a29bfe;">⭐ 提示:</span> 等级越高,方块下落越快!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gameOver">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="finalScore">最终分数: 0</div>
|
||||
<button class="btn" onclick="restartGame()">重新开始</button>
|
||||
</div>
|
||||
|
||||
<!-- 虚拟控制按钮 -->
|
||||
<div class="control-button" id="left-btn">←</div>
|
||||
<div class="control-button" id="right-btn">→</div>
|
||||
<div class="control-button" id="down-btn">↓</div>
|
||||
<div class="control-button" id="rotate-btn">↻ 旋转</div>
|
||||
<div class="control-button" id="start-btn">▶️ 开始</div>
|
||||
<div class="control-button" id="restart-btn">🔄 重来</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
console.log(`[${new Date().toLocaleTimeString()}] ${message}`);
|
||||
}
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
let app = null;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
let dropTimer = 0;
|
||||
let lastFrameTime = 0;
|
||||
|
||||
// 游戏场地
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
let board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
let currentPiece = null;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: new pc.Color(0, 0.96, 1) }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: new pc.Color(0, 0, 1) }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: new pc.Color(1, 0.5, 0) }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: new pc.Color(1, 1, 0) }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: new pc.Color(0, 1, 0) }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: new pc.Color(0.5, 0, 1) }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: new pc.Color(1, 0, 0) } // 红色
|
||||
];
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = `分数: ${score}`;
|
||||
document.getElementById('level').textContent = `等级: ${level}`;
|
||||
document.getElementById('lines').textContent = `消行: ${lines}`;
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type}`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
document.getElementById('finalScore').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('gameOver').style.display = 'block';
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
function restartGame() {
|
||||
// 重置游戏状态
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
gameOver = false;
|
||||
gamePaused = false;
|
||||
dropTimer = 0;
|
||||
lastFrameTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('gameOver').style.display = 'none';
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
updateUI();
|
||||
debugLog('🎮 游戏重新开始!');
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
if (!app || !gameRunning) return;
|
||||
|
||||
// 清空画布
|
||||
app.graphicsDevice.clear({
|
||||
color: [0.04, 0.04, 0.1, 1], // 深蓝色背景
|
||||
depth: 1,
|
||||
flags: pc.CLEARFLAG_COLOR_DEPTH
|
||||
});
|
||||
|
||||
// 计算游戏区域位置(居中)
|
||||
const canvasWidth = app.graphicsDevice.width;
|
||||
const canvasHeight = app.graphicsDevice.height;
|
||||
const gameWidth = GRID_WIDTH * CELL_SIZE;
|
||||
const gameHeight = GRID_HEIGHT * CELL_SIZE;
|
||||
const offsetX = (canvasWidth - gameWidth) / 2;
|
||||
const offsetY = (canvasHeight - gameHeight) / 2;
|
||||
|
||||
// 绘制网格背景
|
||||
app.graphicsDevice.setColor(0.07, 0.07, 0.15); // 深灰色网格背景
|
||||
app.graphicsDevice.fillRect(offsetX, offsetY, gameWidth, gameHeight);
|
||||
|
||||
// 绘制网格线
|
||||
app.graphicsDevice.setColor(1, 1, 1, 0.1);
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = offsetX + x * CELL_SIZE;
|
||||
app.graphicsDevice.drawLine(lineX, offsetY, lineX, offsetY + gameHeight);
|
||||
}
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = offsetY + y * CELL_SIZE;
|
||||
app.graphicsDevice.drawLine(offsetX, lineY, offsetX + gameWidth, lineY);
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
const color = board[y][x];
|
||||
app.graphicsDevice.setColor(color.r, color.g, color.b);
|
||||
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
app.graphicsDevice.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
app.graphicsDevice.setColor(1, 1, 1, 0.5);
|
||||
app.graphicsDevice.drawRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
app.graphicsDevice.setColor(color.r, color.g, color.b);
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = offsetX + (x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
app.graphicsDevice.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
app.graphicsDevice.setColor(1, 1, 1, 0.8);
|
||||
app.graphicsDevice.drawRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameUpdate(dt) {
|
||||
if (!gameRunning || gamePaused || gameOver) return;
|
||||
|
||||
// 自动下落
|
||||
dropTimer += dt;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
|
||||
// 渲染游戏
|
||||
renderGame();
|
||||
}
|
||||
|
||||
// ==================== 初始化游戏 ====================
|
||||
function initGame() {
|
||||
debugLog('🎮 初始化 PlayCanvas...');
|
||||
|
||||
const canvas = document.getElementById('application');
|
||||
if (!canvas) {
|
||||
debugLog('❌ Canvas 元素未找到!');
|
||||
alert('游戏加载失败:Canvas 未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
app = new pc.Application(canvas, {
|
||||
mouse: new pc.Mouse(canvas),
|
||||
keyboard: new pc.Keyboard(window),
|
||||
touch: new pc.TouchDevice(canvas), // 移动端支持
|
||||
elementInput: new pc.ElementInput(canvas)
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog('❌ PlayCanvas 初始化失败:', e);
|
||||
alert('游戏引擎初始化失败: ' + e.message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
|
||||
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
window.addEventListener('resize', () => app.resizeCanvas());
|
||||
|
||||
// 设置游戏循环
|
||||
app.on('update', gameUpdate);
|
||||
|
||||
// 初始化游戏状态
|
||||
restartGame();
|
||||
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.startGame = function() {
|
||||
debugLog('🎮 开始游戏...');
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
};
|
||||
|
||||
function togglePause() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
debugLog(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
}
|
||||
|
||||
// ==================== 设置控件事件 ====================
|
||||
function setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 虚拟按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
if (!gameRunning) {
|
||||
startGame();
|
||||
} else {
|
||||
togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('restart-btn').addEventListener('click', restartGame);
|
||||
document.getElementById('left-btn').addEventListener('click', () => movePiece(-1, 0));
|
||||
document.getElementById('right-btn').addEventListener('click', () => movePiece(1, 0));
|
||||
document.getElementById('down-btn').addEventListener('click', () => movePiece(0, 1));
|
||||
document.getElementById('rotate-btn').addEventListener('click', rotatePiece);
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!gameRunning && !gameOver) {
|
||||
startGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamePaused || gameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 设置控件
|
||||
setupControls();
|
||||
|
||||
// 初始化游戏
|
||||
initGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
alert(`❌ JavaScript错误: ${e.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,673 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | Canvas 2D版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#game-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
box-shadow: 0 0 40px rgba(0, 100, 255, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮容器 */
|
||||
.controls-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 显示状态消息
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// 隐藏加载界面
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// 游戏主类
|
||||
class TetrisGame {
|
||||
constructor() {
|
||||
console.log('🎮 创建TetrisGame实例');
|
||||
|
||||
// 画布和上下文
|
||||
this.canvas = document.getElementById('game-canvas');
|
||||
this.ctx = this.canvas.getContext('2d');
|
||||
|
||||
// 游戏配置
|
||||
this.gridWidth = 10; // 10列
|
||||
this.gridHeight = 20; // 20行
|
||||
this.cellSize = 24; // 每个格子大小
|
||||
|
||||
// 游戏状态
|
||||
this.board = [];
|
||||
this.currentPiece = null;
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = true;
|
||||
this.isGameOver = false;
|
||||
this.gameLoop = null;
|
||||
this.lastDropTime = 0;
|
||||
|
||||
// 方块类型和颜色
|
||||
this.pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff7f00' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#800080' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' }
|
||||
];
|
||||
|
||||
// 初始化游戏
|
||||
this.initGame();
|
||||
this.setupControls();
|
||||
this.setupUI();
|
||||
|
||||
console.log('✅ 游戏初始化完成');
|
||||
showStatus('✅ 俄罗斯方块已加载,点击开始按钮或按任意键开始游戏', 3000);
|
||||
}
|
||||
|
||||
initGame() {
|
||||
console.log('初始化游戏逻辑');
|
||||
|
||||
// 清空游戏场地
|
||||
this.board = Array(this.gridHeight).fill().map(() => Array(this.gridWidth).fill(0));
|
||||
|
||||
// 重置游戏状态
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = false;
|
||||
this.isGameOver = false;
|
||||
this.lastDropTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
this.startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
this.updateUI();
|
||||
|
||||
// 初始渲染
|
||||
this.render();
|
||||
|
||||
console.log('🎮 游戏开始!');
|
||||
}
|
||||
|
||||
spawnNewPiece() {
|
||||
const randomType = this.pieceTypes[Math.floor(Math.random() * this.pieceTypes.length)];
|
||||
this.currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(this.gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
console.log(`生成新方块: ${this.currentPiece.type}`);
|
||||
}
|
||||
|
||||
startGameLoop() {
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
}
|
||||
|
||||
const gameLoop = (timestamp) => {
|
||||
if (!this.lastDropTime) this.lastDropTime = timestamp;
|
||||
|
||||
const deltaTime = timestamp - this.lastDropTime;
|
||||
|
||||
// 自动下落
|
||||
if (!this.isPaused && !this.isGameOver && deltaTime > 1000 / this.gameSpeed) {
|
||||
this.movePiece(0, 1);
|
||||
this.lastDropTime = timestamp;
|
||||
}
|
||||
|
||||
// 渲染
|
||||
this.render();
|
||||
|
||||
// 继续循环
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
};
|
||||
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
console.log('✅ 游戏循环已启动');
|
||||
}
|
||||
|
||||
movePiece(dx, dy) {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
const newX = this.currentPiece.x + dx;
|
||||
const newY = this.currentPiece.y + dy;
|
||||
|
||||
if (this.isValidMove(this.currentPiece.shape, newX, newY)) {
|
||||
this.currentPiece.x = newX;
|
||||
this.currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
this.lockPiece();
|
||||
this.checkLines();
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!this.isValidMove(this.currentPiece.shape, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= this.gridWidth || newY >= this.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && this.board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
lockPiece() {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
this.board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = this.gridHeight - 1; y >= 0; y--) {
|
||||
if (this.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
this.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
this.board.unshift(Array(this.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
this.lines += linesCleared;
|
||||
this.score += linesCleared * 100 * (this.level + 1);
|
||||
this.level = Math.floor(this.lines / 10);
|
||||
this.gameSpeed = 1.0 + this.level * 0.1;
|
||||
|
||||
console.log(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (this.level + 1)}`);
|
||||
showStatus(`🎉 消除 ${linesCleared} 行!`, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
rotatePiece() {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(this.currentPiece.shape);
|
||||
if (this.isValidMove(rotated, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.currentPiece.shape = rotated;
|
||||
console.log('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
gameOver() {
|
||||
this.isGameOver = true;
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
this.gameLoop = null;
|
||||
}
|
||||
|
||||
console.log(`游戏结束!最终得分: ${this.score}`);
|
||||
showStatus(`🎮 游戏结束!最终得分: ${this.score}`, 5000);
|
||||
}
|
||||
|
||||
togglePause() {
|
||||
this.isPaused = !this.isPaused;
|
||||
|
||||
if (this.isPaused) {
|
||||
console.log('游戏暂停');
|
||||
showStatus('⏸️ 游戏暂停');
|
||||
} else {
|
||||
console.log('游戏继续');
|
||||
showStatus('▶️ 游戏继续');
|
||||
this.lastDropTime = performance.now();
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
render() {
|
||||
const ctx = this.ctx;
|
||||
const canvas = this.canvas;
|
||||
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= this.gridWidth; x++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x * this.cellSize, 0);
|
||||
ctx.lineTo(x * this.cellSize, canvas.height);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= this.gridHeight; y++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, y * this.cellSize);
|
||||
ctx.lineTo(canvas.width, y * this.cellSize);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < this.gridHeight; y++) {
|
||||
for (let x = 0; x < this.gridWidth; x++) {
|
||||
if (this.board[y][x]) {
|
||||
ctx.fillStyle = this.board[y][x];
|
||||
ctx.fillRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (this.currentPiece) {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
ctx.fillRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateUI() {
|
||||
document.getElementById('score').textContent = this.score;
|
||||
document.getElementById('level').textContent = this.level;
|
||||
document.getElementById('lines').textContent = this.lines;
|
||||
document.getElementById('speed').textContent = this.gameSpeed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
setupControls() {
|
||||
console.log('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
console.log('开始按钮点击');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
} else if (this.isPaused) {
|
||||
this.togglePause();
|
||||
} else if (this.isGameOver) {
|
||||
this.initGame();
|
||||
} else {
|
||||
this.togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
console.log('重来按钮点击');
|
||||
this.initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
console.log('左按钮点击');
|
||||
this.movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
console.log('右按钮点击');
|
||||
this.movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
console.log('下按钮点击');
|
||||
this.movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
console.log('旋转按钮点击');
|
||||
this.rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
console.log(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPaused || this.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
this.movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
this.movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
this.movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
this.rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
this.togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
console.log('控件事件设置完成');
|
||||
}
|
||||
|
||||
setupUI() {
|
||||
// 添加按钮按下效果
|
||||
document.querySelectorAll('.action-button, .control-button').forEach(btn => {
|
||||
btn.addEventListener('mousedown', () => {
|
||||
btn.style.transform = 'scale(0.95)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseup', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成
|
||||
window.addEventListener('load', () => {
|
||||
console.log('页面加载完成');
|
||||
console.log(`浏览器: ${navigator.userAgent}`);
|
||||
console.log(`平台: ${navigator.platform}`);
|
||||
|
||||
// 检查Canvas支持
|
||||
const canvas = document.getElementById('game-canvas');
|
||||
if (!canvas || !canvas.getContext) {
|
||||
showStatus('❌ 浏览器不支持Canvas,请使用现代浏览器', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建游戏实例
|
||||
window.game = new TetrisGame();
|
||||
|
||||
// 隐藏加载界面
|
||||
hideLoading();
|
||||
});
|
||||
|
||||
// 错误处理
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
showStatus(`❌ JavaScript错误: ${e.message}`, 5000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,444 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>🎮 俄罗斯方块 | 简单下落测试</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
background: #0a0a1a;
|
||||
color: white;
|
||||
font-family: monospace;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
#game {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
border: 2px solid white;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
#controls {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #764ba2;
|
||||
}
|
||||
|
||||
#debug {
|
||||
background: rgba(0,0,0,0.7);
|
||||
color: #00ff00;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
max-width: 600px;
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
font-size: 12px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="game">
|
||||
<h1>🎮 俄罗斯方块 - 简单下落测试</h1>
|
||||
<canvas id="canvas" width="240" height="480"></canvas>
|
||||
|
||||
<div id="info">
|
||||
<div>分数: <span id="score">0</span></div>
|
||||
<div>等级: <span id="level">0</span></div>
|
||||
<div>消行: <span id="lines">0</span></div>
|
||||
</div>
|
||||
|
||||
<div id="controls">
|
||||
<button onclick="startGame()">开始游戏</button>
|
||||
<button onclick="moveLeft()">← 左移</button>
|
||||
<button onclick="moveRight()">→ 右移</button>
|
||||
<button onclick="moveDown()">↓ 下落</button>
|
||||
<button onclick="rotatePiece()">↻ 旋转</button>
|
||||
</div>
|
||||
|
||||
<div id="debug"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
const debugLog = (message) => {
|
||||
const timestamp = new Date().toLocaleTimeString();
|
||||
console.log(`[${timestamp}] ${message}`);
|
||||
|
||||
const debugDiv = document.getElementById('debug');
|
||||
if (debugDiv) {
|
||||
const line = document.createElement('div');
|
||||
line.textContent = `[${timestamp}] ${message}`;
|
||||
debugDiv.appendChild(line);
|
||||
|
||||
// 限制显示行数
|
||||
while (debugDiv.children.length > 20) {
|
||||
debugDiv.removeChild(debugDiv.firstChild);
|
||||
}
|
||||
|
||||
debugDiv.scrollTop = debugDiv.scrollHeight;
|
||||
}
|
||||
};
|
||||
|
||||
// ==================== 游戏变量 ====================
|
||||
const canvas = document.getElementById('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 24;
|
||||
|
||||
let board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
let currentPiece = null;
|
||||
let gameRunning = false;
|
||||
let gameLoopId = null;
|
||||
let dropTimer = 0;
|
||||
let score = 0;
|
||||
let level = 0;
|
||||
let lines = 0;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' }
|
||||
];
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function spawnNewPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${currentPiece.type} 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
}
|
||||
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || !gameRunning) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
debugLog(`尝试移动方块: (${currentPiece.x},${currentPiece.y}) -> (${newX},${newY})`);
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
debugLog(`移动成功: (${newX}, ${newY})`);
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
debugLog(`方块无法下落,准备固定`);
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
} else {
|
||||
debugLog(`移动失败: 位置无效`);
|
||||
}
|
||||
|
||||
renderGame();
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
if (board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
lines += linesCleared;
|
||||
score += linesCleared * 100 * (level + 1);
|
||||
level = Math.floor(lines / 10);
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (level + 1)}`);
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || !gameRunning) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(currentPiece.shape);
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
renderGame();
|
||||
}
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
gameRunning = false;
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
debugLog(`游戏结束!最终得分: ${score}`);
|
||||
}
|
||||
|
||||
// ==================== 渲染函数 ====================
|
||||
function renderGame() {
|
||||
// 清空画布
|
||||
ctx.fillStyle = '#0a0a1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 绘制网格背景
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.fillRect(0, 0, GRID_WIDTH * CELL_SIZE, GRID_HEIGHT * CELL_SIZE);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
const lineX = x * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineX, 0);
|
||||
ctx.lineTo(lineX, GRID_HEIGHT * CELL_SIZE);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
const lineY = y * CELL_SIZE;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, lineY);
|
||||
ctx.lineTo(GRID_WIDTH * CELL_SIZE, lineY);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
let fixedCount = 0;
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
const rectX = x * CELL_SIZE;
|
||||
const rectY = y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
fixedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
const { shape, x, y, color } = currentPiece;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
let currentCount = 0;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const rectX = (x + col) * CELL_SIZE;
|
||||
const rectY = (y + row) * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`渲染: 固定方块=${fixedCount}, 当前方块=${currentCount}, 位置=(${x},${y})`);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameLoop(timestamp) {
|
||||
if (!gameRunning) return;
|
||||
|
||||
// 自动下落
|
||||
dropTimer += 0.016; // 假设每帧16ms
|
||||
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1); // 等级越高,下落越快
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
debugLog(`自动下落: dropTimer=${dropTimer.toFixed(3)} > dropInterval=${dropInterval.toFixed(3)}`);
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
debugLog('🎮 开始游戏...');
|
||||
|
||||
// 重置游戏状态
|
||||
board = Array(GRID_HEIGHT).fill().map(() => Array(GRID_WIDTH).fill(0));
|
||||
score = 0;
|
||||
level = 0;
|
||||
lines = 0;
|
||||
dropTimer = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 开始游戏
|
||||
gameRunning = true;
|
||||
|
||||
updateUI();
|
||||
renderGame();
|
||||
|
||||
// 启动游戏循环
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
};
|
||||
|
||||
window.moveLeft = function() {
|
||||
movePiece(-1, 0);
|
||||
};
|
||||
|
||||
window.moveRight = function() {
|
||||
movePiece(1, 0);
|
||||
};
|
||||
|
||||
window.moveDown = function() {
|
||||
movePiece(0, 1);
|
||||
};
|
||||
|
||||
// ==================== UI更新 ====================
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// ==================== 键盘控制 ====================
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (!gameRunning) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
rotatePiece();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
debugLog('游戏初始化完成');
|
||||
debugLog('点击"开始游戏"按钮开始');
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,704 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 简单修复版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- 纯Canvas 2D版本,无PlayCanvas依赖 -->
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#game-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
box-shadow: 0 0 40px rgba(0, 100, 255, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮容器 */
|
||||
.controls-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-info" id="debug-info">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug-info');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// ==================== 状态消息 ====================
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// ==================== 隐藏加载界面 ====================
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// ==================== 俄罗斯方块游戏 ====================
|
||||
class TetrisGame {
|
||||
constructor() {
|
||||
debugLog('🎮 创建TetrisGame实例');
|
||||
|
||||
// 获取画布
|
||||
this.canvas = document.getElementById('game-canvas');
|
||||
this.ctx = this.canvas.getContext('2d');
|
||||
|
||||
if (!this.canvas || !this.ctx) {
|
||||
debugLog('❌ Canvas元素或上下文未找到');
|
||||
showStatus('❌ Canvas初始化失败', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ Canvas初始化成功');
|
||||
|
||||
// 游戏配置
|
||||
this.gridWidth = 10; // 10列
|
||||
this.gridHeight = 20; // 20行
|
||||
this.cellSize = 24; // 每个格子大小
|
||||
|
||||
// 游戏状态
|
||||
this.board = [];
|
||||
this.currentPiece = null;
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = true;
|
||||
this.isGameOver = false;
|
||||
this.gameLoop = null;
|
||||
this.dropTimer = 0;
|
||||
this.lastFrameTime = 0;
|
||||
|
||||
// 方块类型定义
|
||||
this.pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// 初始化游戏
|
||||
this.initGame();
|
||||
this.setupControls();
|
||||
this.setupUI();
|
||||
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
showStatus('✅ 俄罗斯方块已加载,点击开始按钮或按任意键开始游戏', 3000);
|
||||
hideLoading();
|
||||
}
|
||||
|
||||
initGame() {
|
||||
debugLog('初始化游戏逻辑');
|
||||
|
||||
// 清空游戏场地
|
||||
this.board = Array(this.gridHeight).fill().map(() => Array(this.gridWidth).fill(0));
|
||||
|
||||
// 重置游戏状态
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = false;
|
||||
this.isGameOver = false;
|
||||
this.dropTimer = 0;
|
||||
this.lastFrameTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
this.startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
this.updateUI();
|
||||
|
||||
debugLog('🎮 游戏开始!');
|
||||
}
|
||||
|
||||
spawnNewPiece() {
|
||||
const randomType = this.pieceTypes[Math.floor(Math.random() * this.pieceTypes.length)];
|
||||
this.currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(this.gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${this.currentPiece.type}`);
|
||||
}
|
||||
|
||||
startGameLoop() {
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
}
|
||||
|
||||
const gameLoop = (timestamp) => {
|
||||
if (!this.lastFrameTime) this.lastFrameTime = timestamp;
|
||||
|
||||
const deltaTime = timestamp - this.lastFrameTime;
|
||||
|
||||
// 自动下落
|
||||
if (!this.isPaused && !this.isGameOver) {
|
||||
this.dropTimer += deltaTime;
|
||||
|
||||
if (this.dropTimer > 1000 / this.gameSpeed) {
|
||||
this.movePiece(0, 1);
|
||||
this.dropTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染
|
||||
this.render();
|
||||
|
||||
// 继续循环
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
this.lastFrameTime = timestamp;
|
||||
};
|
||||
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
debugLog('✅ 游戏循环已启动');
|
||||
}
|
||||
|
||||
movePiece(dx, dy) {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
const newX = this.currentPiece.x + dx;
|
||||
const newY = this.currentPiece.y + dy;
|
||||
|
||||
if (this.isValidMove(this.currentPiece.shape, newX, newY)) {
|
||||
this.currentPiece.x = newX;
|
||||
this.currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
this.lockPiece();
|
||||
this.checkLines();
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!this.isValidMove(this.currentPiece.shape, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= this.gridWidth || newY >= this.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && this.board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
lockPiece() {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
this.board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = this.gridHeight - 1; y >= 0; y--) {
|
||||
if (this.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
this.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
this.board.unshift(Array(this.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
this.lines += linesCleared;
|
||||
this.score += linesCleared * 100 * (this.level + 1);
|
||||
this.level = Math.floor(this.lines / 10);
|
||||
this.gameSpeed = 1.0 + this.level * 0.1;
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (this.level + 1)}`);
|
||||
showStatus(`🎉 消除 ${linesCleared} 行!`, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
rotatePiece() {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(this.currentPiece.shape);
|
||||
if (this.isValidMove(rotated, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
gameOver() {
|
||||
this.isGameOver = true;
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
this.gameLoop = null;
|
||||
}
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${this.score}`);
|
||||
showStatus(`🎮 游戏结束!最终得分: ${this.score}`, 5000);
|
||||
}
|
||||
|
||||
togglePause() {
|
||||
this.isPaused = !this.isPaused;
|
||||
|
||||
if (this.isPaused) {
|
||||
debugLog('游戏暂停');
|
||||
showStatus('⏸️ 游戏暂停');
|
||||
} else {
|
||||
debugLog('游戏继续');
|
||||
showStatus('▶️ 游戏继续');
|
||||
this.lastFrameTime = performance.now();
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
render() {
|
||||
// 清空画布
|
||||
this.ctx.fillStyle = '#111827';
|
||||
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
this.ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
this.ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= this.gridWidth; x++) {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(x * this.cellSize, 0);
|
||||
this.ctx.lineTo(x * this.cellSize, this.canvas.height);
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= this.gridHeight; y++) {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(0, y * this.cellSize);
|
||||
this.ctx.lineTo(this.canvas.width, y * this.cellSize);
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < this.gridHeight; y++) {
|
||||
for (let x = 0; x < this.gridWidth; x++) {
|
||||
if (this.board[y][x]) {
|
||||
this.ctx.fillStyle = this.board[y][x];
|
||||
this.ctx.fillRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
this.ctx.strokeStyle = 'white';
|
||||
this.ctx.lineWidth = 2;
|
||||
this.ctx.strokeRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (this.currentPiece) {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
this.ctx.fillStyle = color;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
this.ctx.fillRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
this.ctx.strokeStyle = 'white';
|
||||
this.ctx.lineWidth = 2;
|
||||
this.ctx.strokeRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateUI() {
|
||||
document.getElementById('score').textContent = this.score;
|
||||
document.getElementById('level').textContent = this.level;
|
||||
document.getElementById('lines').textContent = this.lines;
|
||||
document.getElementById('speed').textContent = this.gameSpeed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
debugLog('开始按钮点击');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
} else if (this.isPaused) {
|
||||
this.togglePause();
|
||||
} else if (this.isGameOver) {
|
||||
this.initGame();
|
||||
} else {
|
||||
this.togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
debugLog('重来按钮点击');
|
||||
this.initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
debugLog('左按钮点击');
|
||||
this.movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
debugLog('右按钮点击');
|
||||
this.movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
debugLog('下按钮点击');
|
||||
this.movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
debugLog('旋转按钮点击');
|
||||
this.rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPaused || this.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
this.movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
this.movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
this.movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
this.rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
this.togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
setupUI() {
|
||||
// 添加按钮按下效果
|
||||
document.querySelectorAll('.action-button, .control-button').forEach(btn => {
|
||||
btn.addEventListener('mousedown', () => {
|
||||
btn.style.transform = 'scale(0.95)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseup', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 创建游戏实例
|
||||
window.game = new TetrisGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
showStatus(`❌ JavaScript错误: ${e.message}`, 5000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,422 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>🎮 俄罗斯方块 | 简单循环版</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: Arial; background: #333; color: white; display: flex; flex-direction: column; align-items: center; padding: 20px; }
|
||||
.container { max-width: 800px; width: 100%; text-align: center; }
|
||||
h1 { margin: 20px 0; color: #ffd700; }
|
||||
.game-area { display: flex; justify-content: center; gap: 20px; margin: 20px 0; }
|
||||
canvas { background: #000; border: 2px solid #666; }
|
||||
.info { background: #222; padding: 15px; border-radius: 10px; }
|
||||
.controls { margin: 20px 0; }
|
||||
button { background: #4CAF50; color: white; border: none; padding: 10px 20px; margin: 5px; border-radius: 5px; cursor: pointer; font-size: 16px; }
|
||||
button:hover { background: #45a049; }
|
||||
.log { background: #111; padding: 10px; border-radius: 5px; margin-top: 20px; max-height: 200px; overflow-y: auto; text-align: left; font-family: monospace; font-size: 12px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🎮 俄罗斯方块 - 简单循环版</h1>
|
||||
<div class="game-area">
|
||||
<canvas id="game-canvas" width="300" height="600"></canvas>
|
||||
<div class="info">
|
||||
<div>分数: <span id="score">0</span></div>
|
||||
<div>等级: <span id="level">1</span></div>
|
||||
<div>消行: <span id="lines">0</span></div>
|
||||
<div>下一个: <span id="next-piece">?</span></div>
|
||||
<div class="controls">
|
||||
<button id="start-btn" onclick="startGame()">开始游戏</button>
|
||||
<button onclick="togglePause()">暂停</button>
|
||||
<button onclick="restartGame()">重来</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="log" id="log"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 游戏配置
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 30;
|
||||
|
||||
// 方块类型
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff', name: '长条' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff', name: 'J形' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff7f00', name: 'L形' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00', name: '方块' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00', name: 'S形' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#800080', name: 'T形' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000', name: 'Z形' }
|
||||
];
|
||||
|
||||
// 游戏状态
|
||||
let canvas, ctx;
|
||||
let board = [];
|
||||
let currentPiece = null;
|
||||
let nextPiece = null;
|
||||
let score = 0;
|
||||
let level = 1;
|
||||
let lines = 0;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let lastUpdate = 0;
|
||||
let gameLoopId = null;
|
||||
|
||||
// 日志函数
|
||||
function log(msg) {
|
||||
const logDiv = document.getElementById('log');
|
||||
logDiv.innerHTML += `<div>[${new Date().toLocaleTimeString()}] ${msg}</div>`;
|
||||
logDiv.scrollTop = logDiv.scrollHeight;
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
// 初始化
|
||||
function initGame() {
|
||||
log('🎮 初始化游戏...');
|
||||
|
||||
canvas = document.getElementById('game-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
log('❌ 无法获取Canvas上下文');
|
||||
return;
|
||||
}
|
||||
|
||||
log('✅ Canvas上下文获取成功');
|
||||
|
||||
// 初始化游戏板
|
||||
initBoard();
|
||||
|
||||
// 生成预览方块
|
||||
generateNextPiece();
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
|
||||
log('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
function initBoard() {
|
||||
board = [];
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
board[y] = [];
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
board[y][x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateNextPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
nextPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
|
||||
document.getElementById('next-piece').textContent = nextPiece.name;
|
||||
}
|
||||
|
||||
function spawnNewPiece() {
|
||||
if (nextPiece) {
|
||||
currentPiece = {
|
||||
type: nextPiece.type,
|
||||
shape: nextPiece.shape,
|
||||
color: nextPiece.color,
|
||||
name: nextPiece.name,
|
||||
x: nextPiece.x,
|
||||
y: nextPiece.y
|
||||
};
|
||||
}
|
||||
|
||||
generateNextPiece();
|
||||
|
||||
log(`生成新方块: ${currentPiece.type} (${currentPiece.name}) 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
// 游戏逻辑
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
log(`移动方块到: (${newX}, ${newY})`);
|
||||
renderGame();
|
||||
return true;
|
||||
} else if (dy > 0) {
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
for (let row = 0; row < currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < currentPiece.shape[row].length; col++) {
|
||||
if (currentPiece.shape[row][col]) {
|
||||
const x = currentPiece.x + col;
|
||||
const y = currentPiece.y + row;
|
||||
|
||||
if (y >= 0) {
|
||||
board[y][x] = currentPiece.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
log('方块已固定');
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
let lineFull = true;
|
||||
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (!board[y][x]) {
|
||||
lineFull = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lineFull) {
|
||||
board.splice(y, 1);
|
||||
board.unshift(new Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
const points = [0, 100, 300, 500, 800][linesCleared] * level;
|
||||
score += points;
|
||||
lines += linesCleared;
|
||||
level = Math.floor(lines / 10) + 1;
|
||||
|
||||
updateUI();
|
||||
log(`消除 ${linesCleared} 行,获得 ${points} 分`);
|
||||
}
|
||||
}
|
||||
|
||||
// 游戏循环 - 使用setInterval确保兼容性
|
||||
function gameLoop() {
|
||||
if (!gameRunning || gameOver || gamePaused) return;
|
||||
|
||||
const now = Date.now();
|
||||
const deltaTime = (now - lastUpdate) / 1000;
|
||||
|
||||
// 每0.5秒下落一次(测试用)
|
||||
if (deltaTime > 0.5) {
|
||||
log(`[游戏循环] 自动下落,deltaTime: ${deltaTime.toFixed(3)}`);
|
||||
const moved = movePiece(0, 1);
|
||||
log(`移动结果: ${moved ? '成功' : '失败'}`);
|
||||
lastUpdate = now;
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染
|
||||
function renderGame() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
const offsetX = (canvas.width - GRID_WIDTH * CELL_SIZE) / 2;
|
||||
const offsetY = (canvas.height - GRID_HEIGHT * CELL_SIZE) / 2;
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
ctx.fillRect(
|
||||
offsetX + x * CELL_SIZE,
|
||||
offsetY + y * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.strokeRect(
|
||||
offsetX + x * CELL_SIZE,
|
||||
offsetY + y * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
ctx.fillStyle = currentPiece.color;
|
||||
|
||||
for (let row = 0; row < currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < currentPiece.shape[row].length; col++) {
|
||||
if (currentPiece.shape[row][col]) {
|
||||
ctx.fillRect(
|
||||
offsetX + (currentPiece.x + col) * CELL_SIZE,
|
||||
offsetY + (currentPiece.y + row) * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.strokeRect(
|
||||
offsetX + (currentPiece.x + col) * CELL_SIZE,
|
||||
offsetY + (currentPiece.y + row) * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 游戏控制
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
log('🎮 开始游戏...');
|
||||
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
gameOver = false;
|
||||
score = 0;
|
||||
level = 1;
|
||||
lines = 0;
|
||||
lastUpdate = Date.now();
|
||||
|
||||
initBoard();
|
||||
spawnNewPiece();
|
||||
updateUI();
|
||||
|
||||
// 使用setInterval确保兼容性
|
||||
if (gameLoopId) clearInterval(gameLoopId);
|
||||
gameLoopId = setInterval(gameLoop, 1000 / 60); // 60 FPS
|
||||
|
||||
document.getElementById('start-btn').textContent = '暂停';
|
||||
|
||||
log('✅ 游戏已启动,使用setInterval游戏循环');
|
||||
};
|
||||
|
||||
window.togglePause = function() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
log(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
|
||||
document.getElementById('start-btn').textContent = gamePaused ? '继续' : '暂停';
|
||||
};
|
||||
|
||||
window.restartGame = function() {
|
||||
log('🔄 重新开始游戏...');
|
||||
|
||||
if (gameLoopId) {
|
||||
clearInterval(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
startGame();
|
||||
};
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (gameLoopId) {
|
||||
clearInterval(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
log(`💀 游戏结束,最终分数: ${score}`);
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', function(event) {
|
||||
if (!gameRunning || gameOver) return;
|
||||
|
||||
switch(event.key) {
|
||||
case 'ArrowLeft': movePiece(-1, 0); break;
|
||||
case 'ArrowRight': movePiece(1, 0); break;
|
||||
case 'ArrowDown': movePiece(0, 1); break;
|
||||
case ' ':
|
||||
case 'ArrowUp':
|
||||
// 旋转
|
||||
if (!currentPiece) return;
|
||||
const shape = currentPiece.shape;
|
||||
const rows = shape.length;
|
||||
const cols = shape[0].length;
|
||||
const rotated = [];
|
||||
|
||||
for (let i = 0; i < cols; i++) {
|
||||
rotated[i] = [];
|
||||
for (let j = 0; j < rows; j++) {
|
||||
rotated[i][j] = shape[rows - 1 - j][i];
|
||||
}
|
||||
}
|
||||
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
log('旋转方块');
|
||||
renderGame();
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
case 'P': togglePause(); break;
|
||||
}
|
||||
});
|
||||
|
||||
// 页面加载
|
||||
window.addEventListener('load', function() {
|
||||
log('📄 页面加载完成');
|
||||
initGame();
|
||||
log('🪟 Windows兼容性: 使用setInterval确保兼容性');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,771 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 贪吃蛇风格</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- 使用贪吃蛇相同的PlayCanvas版本 -->
|
||||
<script src="https://code.playcanvas.com/playcanvas-1.66.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#game-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
box-shadow: 0 0 40px rgba(0, 100, 255, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮容器 */
|
||||
.controls-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<canvas id="application" width="540" height="720"></canvas>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-info" id="debug-info">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug-info');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// ==================== 状态消息 ====================
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// ==================== 隐藏加载界面 ====================
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// ==================== 俄罗斯方块游戏 ====================
|
||||
class TetrisGame {
|
||||
constructor() {
|
||||
debugLog('🎮 创建TetrisGame实例');
|
||||
|
||||
// 检查PlayCanvas是否加载
|
||||
if (typeof pc === 'undefined') {
|
||||
debugLog('❌ PlayCanvas 未加载');
|
||||
showStatus('❌ 游戏引擎加载失败,请刷新页面', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ PlayCanvas 已加载');
|
||||
|
||||
// 获取画布
|
||||
this.canvas = document.getElementById('application');
|
||||
if (!this.canvas) {
|
||||
debugLog('❌ Canvas元素未找到');
|
||||
showStatus('❌ Canvas元素未找到', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ Canvas元素找到');
|
||||
|
||||
// 初始化 PlayCanvas(使用贪吃蛇相同的模式)
|
||||
try {
|
||||
this.app = new pc.Application(this.canvas, {
|
||||
mouse: new pc.Mouse(this.canvas),
|
||||
touch: new pc.TouchDevice(this.canvas),
|
||||
elementInput: new pc.ElementInput(this.canvas)
|
||||
});
|
||||
debugLog('✅ PlayCanvas 应用创建成功');
|
||||
} catch (e) {
|
||||
debugLog(`❌ PlayCanvas 初始化失败: ${e.message}`);
|
||||
showStatus(`❌ 游戏引擎初始化失败: ${e.message}`, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
// 启动PlayCanvas
|
||||
try {
|
||||
this.app.start();
|
||||
debugLog('✅ PlayCanvas 已启动');
|
||||
} catch (e) {
|
||||
debugLog(`❌ PlayCanvas 启动失败: ${e.message}`);
|
||||
showStatus(`❌ 游戏引擎启动失败: ${e.message}`, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置画布填充模式(使用贪吃蛇相同的设置)
|
||||
this.app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
|
||||
this.app.setCanvasResolution(pc.RESOLUTION_AUTO);
|
||||
|
||||
// 窗口大小调整(使用贪吃蛇相同的方法)
|
||||
window.addEventListener('resize', () => {
|
||||
try {
|
||||
this.app.resizeCanvas();
|
||||
debugLog('✅ 画布大小已调整');
|
||||
} catch (e) {
|
||||
debugLog(`❌ 画布调整失败: ${e.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('✅ 画布设置完成');
|
||||
|
||||
// 游戏配置
|
||||
this.gridWidth = 10; // 10列
|
||||
this.gridHeight = 20; // 20行
|
||||
this.cellSize = 24; // 每个格子大小
|
||||
|
||||
// 游戏状态
|
||||
this.board = [];
|
||||
this.currentPiece = null;
|
||||
this.nextPiece = null;
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = true;
|
||||
this.isGameOver = false;
|
||||
this.gameLoop = null;
|
||||
this.lastDropTime = 0;
|
||||
|
||||
// 方块类型定义
|
||||
this.pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: new pc.Color(0, 0.96, 1) }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: new pc.Color(0, 0, 1) }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: new pc.Color(1, 0.5, 0) }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: new pc.Color(1, 1, 0) }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: new pc.Color(0, 1, 0) }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: new pc.Color(0.5, 0, 0.5) }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: new pc.Color(1, 0, 0) } // 红色
|
||||
];
|
||||
|
||||
// 延迟初始化游戏逻辑
|
||||
setTimeout(() => {
|
||||
this.initGame();
|
||||
this.setupControls();
|
||||
this.setupUI();
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
showStatus('✅ 俄罗斯方块已加载,点击开始按钮或按任意键开始游戏', 3000);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
initGame() {
|
||||
debugLog('初始化游戏逻辑');
|
||||
|
||||
// 清空游戏场地
|
||||
this.board = Array(this.gridHeight).fill().map(() => Array(this.gridWidth).fill(0));
|
||||
|
||||
// 重置游戏状态
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = false;
|
||||
this.isGameOver = false;
|
||||
this.lastDropTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
this.startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
this.updateUI();
|
||||
|
||||
debugLog('🎮 游戏开始!');
|
||||
}
|
||||
|
||||
spawnNewPiece() {
|
||||
const randomType = this.pieceTypes[Math.floor(Math.random() * this.pieceTypes.length)];
|
||||
this.currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(this.gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${this.currentPiece.type}`);
|
||||
}
|
||||
|
||||
startGameLoop() {
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
}
|
||||
|
||||
const gameLoop = (timestamp) => {
|
||||
if (!this.lastDropTime) this.lastDropTime = timestamp;
|
||||
|
||||
const deltaTime = timestamp - this.lastDropTime;
|
||||
|
||||
// 自动下落
|
||||
if (!this.isPaused && !this.isGameOver && deltaTime > 1000 / this.gameSpeed) {
|
||||
this.movePiece(0, 1);
|
||||
this.lastDropTime = timestamp;
|
||||
}
|
||||
|
||||
// 渲染
|
||||
this.render();
|
||||
|
||||
// 继续循环
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
};
|
||||
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
debugLog('✅ 游戏循环已启动');
|
||||
}
|
||||
|
||||
movePiece(dx, dy) {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
const newX = this.currentPiece.x + dx;
|
||||
const newY = this.currentPiece.y + dy;
|
||||
|
||||
if (this.isValidMove(this.currentPiece.shape, newX, newY)) {
|
||||
this.currentPiece.x = newX;
|
||||
this.currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
this.lockPiece();
|
||||
this.checkLines();
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!this.isValidMove(this.currentPiece.shape, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= this.gridWidth || newY >= this.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && this.board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
lockPiece() {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
this.board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = this.gridHeight - 1; y >= 0; y--) {
|
||||
if (this.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
this.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
this.board.unshift(Array(this.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
this.lines += linesCleared;
|
||||
this.score += linesCleared * 100 * (this.level + 1);
|
||||
this.level = Math.floor(this.lines / 10);
|
||||
this.gameSpeed = 1.0 + this.level * 0.1;
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (this.level + 1)}`);
|
||||
showStatus(`🎉 消除 ${linesCleared} 行!`, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
rotatePiece() {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(this.currentPiece.shape);
|
||||
if (this.isValidMove(rotated, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
gameOver() {
|
||||
this.isGameOver = true;
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
this.gameLoop = null;
|
||||
}
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${this.score}`);
|
||||
showStatus(`🎮 游戏结束!最终得分: ${this.score}`, 5000);
|
||||
}
|
||||
|
||||
togglePause() {
|
||||
this.isPaused = !this.isPaused;
|
||||
|
||||
if (this.isPaused) {
|
||||
debugLog('游戏暂停');
|
||||
showStatus('⏸️ 游戏暂停');
|
||||
} else {
|
||||
debugLog('游戏继续');
|
||||
showStatus('▶️ 游戏继续');
|
||||
this.lastDropTime = performance.now();
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
render() {
|
||||
// 清空画布
|
||||
const ctx = this.app.graphicsDevice.gl;
|
||||
if (!ctx) return;
|
||||
|
||||
// 设置背景色
|
||||
ctx.clearColor(0.1, 0.1, 0.15, 1.0);
|
||||
ctx.clear(ctx.COLOR_BUFFER_BIT);
|
||||
|
||||
// 绘制网格背景
|
||||
const gridColor = new pc.Color(0.2, 0.2, 0.3);
|
||||
const gridSize = this.cellSize;
|
||||
const gridWidth = this.gridWidth;
|
||||
const gridHeight = this.gridHeight;
|
||||
|
||||
// 简单绘制逻辑 - 实际游戏中需要更复杂的3D渲染
|
||||
// 这里使用2D绘制作为占位符
|
||||
const canvas = this.canvas;
|
||||
const canvasCtx = canvas.getContext('2d');
|
||||
if (!canvasCtx) return;
|
||||
|
||||
// 清空2D画布
|
||||
canvasCtx.fillStyle = '#111827';
|
||||
canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
canvasCtx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
canvasCtx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= gridWidth; x++) {
|
||||
canvasCtx.beginPath();
|
||||
canvasCtx.moveTo(x * gridSize, 0);
|
||||
canvasCtx.lineTo(x * gridSize, canvas.height);
|
||||
canvasCtx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= gridHeight; y++) {
|
||||
canvasCtx.beginPath();
|
||||
canvasCtx.moveTo(0, y * gridSize);
|
||||
canvasCtx.lineTo(canvas.width, y * gridSize);
|
||||
canvasCtx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < gridHeight; y++) {
|
||||
for (let x = 0; x < gridWidth; x++) {
|
||||
if (this.board[y][x]) {
|
||||
const color = this.board[y][x];
|
||||
canvasCtx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
|
||||
canvasCtx.fillRect(x * gridSize, y * gridSize, gridSize, gridSize);
|
||||
|
||||
canvasCtx.strokeStyle = 'white';
|
||||
canvasCtx.lineWidth = 2;
|
||||
canvasCtx.strokeRect(x * gridSize, y * gridSize, gridSize, gridSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (this.currentPiece) {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
canvasCtx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
canvasCtx.fillRect((x + col) * gridSize, (y + row) * gridSize, gridSize, gridSize);
|
||||
|
||||
canvasCtx.strokeStyle = 'white';
|
||||
canvasCtx.lineWidth = 2;
|
||||
canvasCtx.strokeRect((x + col) * gridSize, (y + row) * gridSize, gridSize, gridSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateUI() {
|
||||
document.getElementById('score').textContent = this.score;
|
||||
document.getElementById('level').textContent = this.level;
|
||||
document.getElementById('lines').textContent = this.lines;
|
||||
document.getElementById('speed').textContent = this.gameSpeed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
debugLog('开始按钮点击');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
} else if (this.isPaused) {
|
||||
this.togglePause();
|
||||
} else if (this.isGameOver) {
|
||||
this.initGame();
|
||||
} else {
|
||||
this.togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
debugLog('重来按钮点击');
|
||||
this.initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
debugLog('左按钮点击');
|
||||
this.movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
debugLog('右按钮点击');
|
||||
this.movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
debugLog('下按钮点击');
|
||||
this.movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
debugLog('旋转按钮点击');
|
||||
this.rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPaused || this.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
this.movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
this.movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
this.movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
this.rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
this.togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
setupUI() {
|
||||
// 添加按钮按下效果
|
||||
document.querySelectorAll('.action-button, .control-button').forEach(btn => {
|
||||
btn.addEventListener('mousedown', () => {
|
||||
btn.style.transform = 'scale(0.95)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseup', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 创建游戏实例
|
||||
window.game = new TetrisGame();
|
||||
|
||||
// 隐藏加载界面
|
||||
hideLoading();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
showStatus(`❌ JavaScript错误: ${e.message}`, 5000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,704 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 终极版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<!-- 纯Canvas 2D版本,无PlayCanvas依赖 -->
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#game-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
box-shadow: 0 0 40px rgba(0, 100, 255, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮容器 */
|
||||
.controls-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-info" id="debug-info">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug-info');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// ==================== 状态消息 ====================
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// ==================== 隐藏加载界面 ====================
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// ==================== 俄罗斯方块游戏 ====================
|
||||
class TetrisGame {
|
||||
constructor() {
|
||||
debugLog('🎮 创建TetrisGame实例');
|
||||
|
||||
// 获取画布
|
||||
this.canvas = document.getElementById('game-canvas');
|
||||
this.ctx = this.canvas.getContext('2d');
|
||||
|
||||
if (!this.canvas || !this.ctx) {
|
||||
debugLog('❌ Canvas元素或上下文未找到');
|
||||
showStatus('❌ Canvas初始化失败', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ Canvas初始化成功');
|
||||
|
||||
// 游戏配置
|
||||
this.gridWidth = 10; // 10列
|
||||
this.gridHeight = 20; // 20行
|
||||
this.cellSize = 24; // 每个格子大小
|
||||
|
||||
// 游戏状态
|
||||
this.board = [];
|
||||
this.currentPiece = null;
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = true;
|
||||
this.isGameOver = false;
|
||||
this.gameLoop = null;
|
||||
this.dropTimer = 0;
|
||||
this.lastFrameTime = 0;
|
||||
|
||||
// 方块类型定义
|
||||
this.pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// 初始化游戏
|
||||
this.initGame();
|
||||
this.setupControls();
|
||||
this.setupUI();
|
||||
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
showStatus('✅ 俄罗斯方块已加载,点击开始按钮或按任意键开始游戏', 3000);
|
||||
hideLoading();
|
||||
}
|
||||
|
||||
initGame() {
|
||||
debugLog('初始化游戏逻辑');
|
||||
|
||||
// 清空游戏场地
|
||||
this.board = Array(this.gridHeight).fill().map(() => Array(this.gridWidth).fill(0));
|
||||
|
||||
// 重置游戏状态
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = false;
|
||||
this.isGameOver = false;
|
||||
this.dropTimer = 0;
|
||||
this.lastFrameTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
this.startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
this.updateUI();
|
||||
|
||||
debugLog('🎮 游戏开始!');
|
||||
}
|
||||
|
||||
spawnNewPiece() {
|
||||
const randomType = this.pieceTypes[Math.floor(Math.random() * this.pieceTypes.length)];
|
||||
this.currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(this.gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${this.currentPiece.type}`);
|
||||
}
|
||||
|
||||
startGameLoop() {
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
}
|
||||
|
||||
const gameLoop = (timestamp) => {
|
||||
if (!this.lastFrameTime) this.lastFrameTime = timestamp;
|
||||
|
||||
const deltaTime = timestamp - this.lastFrameTime;
|
||||
|
||||
// 自动下落
|
||||
if (!this.isPaused && !this.isGameOver) {
|
||||
this.dropTimer += deltaTime;
|
||||
|
||||
if (this.dropTimer > 1000 / this.gameSpeed) {
|
||||
this.movePiece(0, 1);
|
||||
this.dropTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染
|
||||
this.render();
|
||||
|
||||
// 继续循环
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
this.lastFrameTime = timestamp;
|
||||
};
|
||||
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
debugLog('✅ 游戏循环已启动');
|
||||
}
|
||||
|
||||
movePiece(dx, dy) {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
const newX = this.currentPiece.x + dx;
|
||||
const newY = this.currentPiece.y + dy;
|
||||
|
||||
if (this.isValidMove(this.currentPiece.shape, newX, newY)) {
|
||||
this.currentPiece.x = newX;
|
||||
this.currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
this.lockPiece();
|
||||
this.checkLines();
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!this.isValidMove(this.currentPiece.shape, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= this.gridWidth || newY >= this.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && this.board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
lockPiece() {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
this.board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = this.gridHeight - 1; y >= 0; y--) {
|
||||
if (this.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
this.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
this.board.unshift(Array(this.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
this.lines += linesCleared;
|
||||
this.score += linesCleared * 100 * (this.level + 1);
|
||||
this.level = Math.floor(this.lines / 10);
|
||||
this.gameSpeed = 1.0 + this.level * 0.1;
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (this.level + 1)}`);
|
||||
showStatus(`🎉 消除 ${linesCleared} 行!`, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
rotatePiece() {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(this.currentPiece.shape);
|
||||
if (this.isValidMove(rotated, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
gameOver() {
|
||||
this.isGameOver = true;
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
this.gameLoop = null;
|
||||
}
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${this.score}`);
|
||||
showStatus(`🎮 游戏结束!最终得分: ${this.score}`, 5000);
|
||||
}
|
||||
|
||||
togglePause() {
|
||||
this.isPaused = !this.isPaused;
|
||||
|
||||
if (this.isPaused) {
|
||||
debugLog('游戏暂停');
|
||||
showStatus('⏸️ 游戏暂停');
|
||||
} else {
|
||||
debugLog('游戏继续');
|
||||
showStatus('▶️ 游戏继续');
|
||||
this.lastFrameTime = performance.now();
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
render() {
|
||||
// 清空画布
|
||||
this.ctx.fillStyle = '#111827';
|
||||
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
this.ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
this.ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= this.gridWidth; x++) {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(x * this.cellSize, 0);
|
||||
this.ctx.lineTo(x * this.cellSize, this.canvas.height);
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= this.gridHeight; y++) {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(0, y * this.cellSize);
|
||||
this.ctx.lineTo(this.canvas.width, y * this.cellSize);
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < this.gridHeight; y++) {
|
||||
for (let x = 0; x < this.gridWidth; x++) {
|
||||
if (this.board[y][x]) {
|
||||
this.ctx.fillStyle = this.board[y][x];
|
||||
this.ctx.fillRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
this.ctx.strokeStyle = 'white';
|
||||
this.ctx.lineWidth = 2;
|
||||
this.ctx.strokeRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (this.currentPiece) {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
this.ctx.fillStyle = color;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
this.ctx.fillRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
this.ctx.strokeStyle = 'white';
|
||||
this.ctx.lineWidth = 2;
|
||||
this.ctx.strokeRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateUI() {
|
||||
document.getElementById('score').textContent = this.score;
|
||||
document.getElementById('level').textContent = this.level;
|
||||
document.getElementById('lines').textContent = this.lines;
|
||||
document.getElementById('speed').textContent = this.gameSpeed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
debugLog('开始按钮点击');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
} else if (this.isPaused) {
|
||||
this.togglePause();
|
||||
} else if (this.isGameOver) {
|
||||
this.initGame();
|
||||
} else {
|
||||
this.togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
debugLog('重来按钮点击');
|
||||
this.initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
debugLog('左按钮点击');
|
||||
this.movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
debugLog('右按钮点击');
|
||||
this.movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
debugLog('下按钮点击');
|
||||
this.movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
debugLog('旋转按钮点击');
|
||||
this.rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPaused || this.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
this.movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
this.movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
this.movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
this.rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
this.togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
setupUI() {
|
||||
// 添加按钮按下效果
|
||||
document.querySelectorAll('.action-button, .control-button').forEach(btn => {
|
||||
btn.addEventListener('mousedown', () => {
|
||||
btn.style.transform = 'scale(0.95)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseup', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 创建游戏实例
|
||||
window.game = new TetrisGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
showStatus(`❌ JavaScript错误: ${e.message}`, 5000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,993 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | Windows完美兼容版</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎮</text></svg>">
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Arial', 'Microsoft YaHei', sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 10px;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 1.2rem;
|
||||
opacity: 0.9;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.game-area {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.game-board {
|
||||
position: relative;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
canvas {
|
||||
display: block;
|
||||
border-radius: 5px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
min-width: 200px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
.info-item {
|
||||
margin-bottom: 15px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.7;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.next-piece {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
button {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 50px;
|
||||
padding: 12px 24px;
|
||||
font-size: 1.1rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.direction-buttons {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.dir-btn {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 50%;
|
||||
font-size: 1.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.rotate-btn {
|
||||
background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
|
||||
}
|
||||
|
||||
.instructions {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
margin-top: 30px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.instructions h3 {
|
||||
margin-bottom: 10px;
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.instructions ul {
|
||||
list-style: none;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.instructions li {
|
||||
margin-bottom: 8px;
|
||||
padding-left: 10px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.instructions li:before {
|
||||
content: "•";
|
||||
color: #667eea;
|
||||
position: absolute;
|
||||
left: -10px;
|
||||
}
|
||||
|
||||
.game-over {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
z-index: 100;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.game-over h2 {
|
||||
font-size: 3rem;
|
||||
color: #ff4757;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.menu {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.menu h2 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 30px;
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.menu-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.game-area {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
font-size: 1rem;
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.dir-btn {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
body {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 8px 16px;
|
||||
font-size: 0.9rem;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
.dir-btn {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<div class="subtitle">Windows完美兼容版 | 纯Canvas 2D | 无外部依赖</div>
|
||||
</div>
|
||||
|
||||
<div class="game-area">
|
||||
<div class="game-board">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div id="menu" class="menu">
|
||||
<h2>🎮 俄罗斯方块</h2>
|
||||
<div class="menu-buttons">
|
||||
<button id="start-btn" onclick="startGame()">▶️ 开始游戏</button>
|
||||
<button onclick="showInstructions()">📖 游戏说明</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="game-over" class="game-over">
|
||||
<h2>游戏结束</h2>
|
||||
<div id="final-score" class="info-value" style="margin-bottom: 20px;">最终分数: 0</div>
|
||||
<button onclick="restartGame()">🔄 重新开始</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<div class="info-label">分数</div>
|
||||
<div id="score" class="info-value">0</div>
|
||||
</div>
|
||||
|
||||
<div class="info-item">
|
||||
<div class="info-label">等级</div>
|
||||
<div id="level" class="info-value">1</div>
|
||||
</div>
|
||||
|
||||
<div class="info-item">
|
||||
<div class="info-label">消行数</div>
|
||||
<div id="lines" class="info-value">0</div>
|
||||
</div>
|
||||
|
||||
<div class="next-piece">
|
||||
<div class="info-label">下一个方块</div>
|
||||
<div id="next-piece" class="info-value">?</div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<div class="control-row">
|
||||
<button id="pause-btn" onclick="togglePause()">⏸️ 暂停</button>
|
||||
<button onclick="restartGame()">🔄 重来</button>
|
||||
</div>
|
||||
|
||||
<div class="direction-buttons">
|
||||
<button class="dir-btn" onclick="moveLeft()">←</button>
|
||||
<button class="dir-btn rotate-btn" onclick="rotatePiece()">↻</button>
|
||||
<button class="dir-btn" onclick="moveRight()">→</button>
|
||||
</div>
|
||||
|
||||
<div class="control-row">
|
||||
<button class="dir-btn" onclick="moveDown()" style="width: 100%;">↓ 快速下落</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="instructions" id="instructions" style="display: none;">
|
||||
<h3>🎮 游戏说明</h3>
|
||||
<ul>
|
||||
<li><strong>目标</strong>: 消除完整的行来获得分数</li>
|
||||
<li><strong>控制</strong>:
|
||||
<br>← → : 左右移动
|
||||
<br>↓ : 加速下落
|
||||
<br>空格键 : 旋转方块
|
||||
<br>P键 : 暂停/继续
|
||||
</li>
|
||||
<li><strong>计分规则</strong>:
|
||||
<br>1行: 100 × 等级
|
||||
<br>2行: 300 × 等级
|
||||
<br>3行: 500 × 等级
|
||||
<br>4行: 800 × 等级
|
||||
</li>
|
||||
<li><strong>等级提升</strong>: 每消除10行提升1级,下落速度加快</li>
|
||||
<li><strong>游戏结束</strong>: 方块堆到顶部无法生成新方块</li>
|
||||
</ul>
|
||||
<button onclick="hideInstructions()" style="margin-top: 15px; width: 100%;">返回游戏</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 游戏配置 ====================
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 30;
|
||||
|
||||
// 方块类型定义
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff', name: '长条' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff', name: 'J形' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff7f00', name: 'L形' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00', name: '方块' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00', name: 'S形' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#800080', name: 'T形' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000', name: 'Z形' }
|
||||
];
|
||||
|
||||
// ==================== 游戏状态 ====================
|
||||
let canvas, ctx;
|
||||
let board = [];
|
||||
let currentPiece = null;
|
||||
let nextPiece = null;
|
||||
let score = 0;
|
||||
let level = 1;
|
||||
let lines = 0;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let dropTimer = 0;
|
||||
let lastTime = 0;
|
||||
let gameLoopId = null;
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
function initGame() {
|
||||
console.log('🎮 初始化俄罗斯方块游戏...');
|
||||
|
||||
// 获取Canvas上下文
|
||||
canvas = document.getElementById('game-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
console.error('❌ 无法获取Canvas 2D上下文');
|
||||
alert('您的浏览器不支持Canvas 2D,请使用现代浏览器');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ Canvas 2D上下文获取成功');
|
||||
console.log(`Canvas尺寸: ${canvas.width}x${canvas.height}`);
|
||||
|
||||
// 初始化游戏板
|
||||
initBoard();
|
||||
|
||||
// 生成第一个预览方块
|
||||
generateNextPiece();
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
|
||||
console.log('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
function initBoard() {
|
||||
board = [];
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
board[y] = [];
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
board[y][x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateNextPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
nextPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
|
||||
document.getElementById('next-piece').textContent = nextPiece.name;
|
||||
}
|
||||
|
||||
function spawnNewPiece() {
|
||||
if (nextPiece) {
|
||||
// 使用预览方块
|
||||
currentPiece = {
|
||||
type: nextPiece.type,
|
||||
shape: nextPiece.shape,
|
||||
color: nextPiece.color,
|
||||
name: nextPiece.name,
|
||||
x: nextPiece.x,
|
||||
y: nextPiece.y
|
||||
};
|
||||
} else {
|
||||
// 随机生成新方块
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
}
|
||||
|
||||
// 生成下一个预览方块
|
||||
generateNextPiece();
|
||||
|
||||
console.log(`生成新方块: ${currentPiece.type} (${currentPiece.name}) 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
// 检查边界
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查碰撞
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
console.log(`尝试移动方块: 从(${currentPiece.x}, ${currentPiece.y}) 到(${newX}, ${newY})`);
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
console.log(`✅ 移动方块到: (${newX}, ${newY})`);
|
||||
renderGame();
|
||||
return true;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 创建旋转后的形状
|
||||
const shape = currentPiece.shape;
|
||||
const rows = shape.length;
|
||||
const cols = shape[0].length;
|
||||
const rotated = [];
|
||||
|
||||
for (let i = 0; i < cols; i++) {
|
||||
rotated[i] = [];
|
||||
for (let j = 0; j < rows; j++) {
|
||||
rotated[i][j] = shape[rows - 1 - j][i];
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试旋转
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
console.log('✅ 旋转方块成功');
|
||||
renderGame();
|
||||
} else {
|
||||
console.log('⚠️ 旋转被阻挡');
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
if (!currentPiece) return;
|
||||
|
||||
for (let row = 0; row < currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < currentPiece.shape[row].length; col++) {
|
||||
if (currentPiece.shape[row][col]) {
|
||||
const x = currentPiece.x + col;
|
||||
const y = currentPiece.y + row;
|
||||
|
||||
if (y >= 0) {
|
||||
board[y][x] = currentPiece.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🔒 方块已固定');
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
let lineFull = true;
|
||||
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (!board[y][x]) {
|
||||
lineFull = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lineFull) {
|
||||
// 移除该行
|
||||
board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
board.unshift(new Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置(因为行下移了)
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
// 更新分数
|
||||
const points = [0, 100, 300, 500, 800][linesCleared] * level;
|
||||
score += points;
|
||||
lines += linesCleared;
|
||||
level = Math.floor(lines / 10) + 1;
|
||||
|
||||
updateUI();
|
||||
|
||||
console.log(`🎉 消除 ${linesCleared} 行,获得 ${points} 分`);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameLoop(currentTime) {
|
||||
console.log(`[游戏循环] 调用,currentTime: ${currentTime}, gameRunning: ${gameRunning}, gameOver: ${gameOver}`);
|
||||
|
||||
if (!gameRunning || gameOver) {
|
||||
console.log(`[游戏循环] 停止,gameRunning: ${gameRunning}, gameOver: ${gameOver}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算时间增量
|
||||
const deltaTime = (currentTime - lastTime) / 1000;
|
||||
console.log(`[游戏循环] deltaTime: ${deltaTime.toFixed(6)}秒`);
|
||||
lastTime = currentTime;
|
||||
|
||||
if (!gamePaused) {
|
||||
// 自动下落
|
||||
dropTimer += deltaTime;
|
||||
const dropInterval = 1.0 / (1.0 + level * 0.1);
|
||||
|
||||
console.log(`[游戏循环] dropTimer: ${dropTimer.toFixed(3)}, dropInterval: ${dropInterval.toFixed(3)}`);
|
||||
|
||||
if (dropTimer > dropInterval) {
|
||||
console.log(`[游戏循环] 执行自动下落`);
|
||||
movePiece(0, 1);
|
||||
dropTimer = 0;
|
||||
}
|
||||
} else {
|
||||
console.log(`[游戏循环] 游戏暂停中`);
|
||||
}
|
||||
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
console.log(`[游戏循环] 下一帧ID: ${gameLoopId}`);
|
||||
}
|
||||
|
||||
// ==================== 渲染 ====================
|
||||
function renderGame() {
|
||||
if (!ctx) return;
|
||||
|
||||
// 清空Canvas
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// 计算偏移量使游戏板居中
|
||||
const offsetX = (canvas.width - GRID_WIDTH * CELL_SIZE) / 2;
|
||||
const offsetY = (canvas.height - GRID_HEIGHT * CELL_SIZE) / 2;
|
||||
|
||||
// 绘制背景网格
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.05)';
|
||||
ctx.fillRect(offsetX, offsetY, GRID_WIDTH * CELL_SIZE, GRID_HEIGHT * CELL_SIZE);
|
||||
|
||||
// 绘制网格线
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= GRID_WIDTH; x++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX + x * CELL_SIZE, offsetY);
|
||||
ctx.lineTo(offsetX + x * CELL_SIZE, offsetY + GRID_HEIGHT * CELL_SIZE);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= GRID_HEIGHT; y++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offsetX, offsetY + y * CELL_SIZE);
|
||||
ctx.lineTo(offsetX + GRID_WIDTH * CELL_SIZE, offsetY + y * CELL_SIZE);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
const rectX = offsetX + x * CELL_SIZE;
|
||||
const rectY = offsetY + y * CELL_SIZE;
|
||||
|
||||
// 绘制方块
|
||||
ctx.fillStyle = board[y][x];
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制边框
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
// 绘制内部高光
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
ctx.fillStyle = currentPiece.color;
|
||||
|
||||
for (let row = 0; row < currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < currentPiece.shape[row].length; col++) {
|
||||
if (currentPiece.shape[row][col]) {
|
||||
const rectX = offsetX + (currentPiece.x + col) * CELL_SIZE;
|
||||
const rectY = offsetY + (currentPiece.y + row) * CELL_SIZE;
|
||||
|
||||
ctx.fillRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(rectX, rectY, CELL_SIZE, CELL_SIZE);
|
||||
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fillRect(rectX + 2, rectY + 2, CELL_SIZE - 4, CELL_SIZE - 4);
|
||||
|
||||
ctx.fillStyle = currentPiece.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制预览(下一个方块)
|
||||
if (nextPiece) {
|
||||
const previewX = offsetX + GRID_WIDTH * CELL_SIZE + 20;
|
||||
const previewY = offsetY;
|
||||
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
||||
ctx.fillRect(previewX, previewY, 100, 100);
|
||||
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.font = '14px Arial';
|
||||
ctx.fillText('下一个:', previewX + 10, previewY + 20);
|
||||
|
||||
// 绘制预览方块
|
||||
const previewShape = nextPiece.shape;
|
||||
const shapeWidth = previewShape[0].length;
|
||||
const shapeHeight = previewShape.length;
|
||||
const cellSize = 20;
|
||||
const shapeOffsetX = previewX + 50 - (shapeWidth * cellSize) / 2;
|
||||
const shapeOffsetY = previewY + 60 - (shapeHeight * cellSize) / 2;
|
||||
|
||||
for (let row = 0; row < shapeHeight; row++) {
|
||||
for (let col = 0; col < shapeWidth; col++) {
|
||||
if (previewShape[row][col]) {
|
||||
ctx.fillStyle = nextPiece.color;
|
||||
ctx.fillRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeRect(
|
||||
shapeOffsetX + col * cellSize,
|
||||
shapeOffsetY + row * cellSize,
|
||||
cellSize,
|
||||
cellSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏控制 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
console.log('🎮 开始游戏...');
|
||||
|
||||
// 隐藏菜单
|
||||
document.getElementById('menu').style.display = 'none';
|
||||
|
||||
// 重置游戏状态
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
gameOver = false;
|
||||
score = 0;
|
||||
level = 1;
|
||||
lines = 0;
|
||||
dropTimer = 0;
|
||||
|
||||
// 初始化游戏板
|
||||
initBoard();
|
||||
|
||||
// 生成第一个方块
|
||||
spawnNewPiece();
|
||||
|
||||
// 更新UI
|
||||
updateUI();
|
||||
|
||||
// 启动游戏循环
|
||||
lastTime = performance.now();
|
||||
console.log(`⏱️ 游戏循环启动,lastTime: ${lastTime}`);
|
||||
gameLoopId = requestAnimationFrame(gameLoop);
|
||||
console.log(`🔄 gameLoopId: ${gameLoopId}`);
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = '⏸️ 暂停';
|
||||
document.getElementById('pause-btn').textContent = '⏸️ 暂停';
|
||||
|
||||
console.log('✅ 游戏已启动,等待游戏循环...');
|
||||
};
|
||||
|
||||
window.togglePause = function() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
console.log(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
|
||||
// 更新按钮文本
|
||||
document.getElementById('start-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
document.getElementById('pause-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
};
|
||||
|
||||
window.restartGame = function() {
|
||||
console.log('🔄 重新开始游戏...');
|
||||
|
||||
// 隐藏游戏结束界面
|
||||
document.getElementById('game-over').style.display = 'none';
|
||||
|
||||
// 停止当前游戏循环
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
// 重新开始游戏
|
||||
startGame();
|
||||
};
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (gameLoopId) {
|
||||
cancelAnimationFrame(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
document.getElementById('final-score').textContent = `最终分数: ${score}`;
|
||||
document.getElementById('game-over').style.display = 'flex';
|
||||
|
||||
console.log('💀 游戏结束');
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.moveLeft = function() { movePiece(-1, 0); };
|
||||
window.moveRight = function() { movePiece(1, 0); };
|
||||
window.moveDown = function() { movePiece(0, 1); };
|
||||
window.rotatePiece = function() { rotatePiece(); };
|
||||
|
||||
window.showInstructions = function() {
|
||||
document.getElementById('instructions').style.display = 'block';
|
||||
};
|
||||
|
||||
window.hideInstructions = function() {
|
||||
document.getElementById('instructions').style.display = 'none';
|
||||
};
|
||||
|
||||
// ==================== 键盘控制 ====================
|
||||
document.addEventListener('keydown', function(event) {
|
||||
if (!gameRunning || gameOver) return;
|
||||
|
||||
console.log(`键盘按键: ${event.key}`);
|
||||
|
||||
switch(event.key) {
|
||||
case 'ArrowLeft':
|
||||
event.preventDefault();
|
||||
movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
event.preventDefault();
|
||||
movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
event.preventDefault();
|
||||
movePiece(0, 1);
|
||||
break;
|
||||
case ' ':
|
||||
case 'ArrowUp':
|
||||
event.preventDefault();
|
||||
rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
event.preventDefault();
|
||||
togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 触摸控制 ====================
|
||||
let touchStartX = 0;
|
||||
let touchStartY = 0;
|
||||
|
||||
canvas.addEventListener('touchstart', function(event) {
|
||||
event.preventDefault();
|
||||
const touch = event.touches[0];
|
||||
touchStartX = touch.clientX;
|
||||
touchStartY = touch.clientY;
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchmove', function(event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchend', function(event) {
|
||||
event.preventDefault();
|
||||
const touch = event.changedTouches[0];
|
||||
const deltaX = touch.clientX - touchStartX;
|
||||
const deltaY = touch.clientY - touchStartY;
|
||||
|
||||
// 滑动阈值
|
||||
const threshold = 30;
|
||||
|
||||
if (Math.abs(deltaX) > Math.abs(deltaY)) {
|
||||
// 水平滑动
|
||||
if (deltaX > threshold) {
|
||||
movePiece(1, 0); // 右滑
|
||||
} else if (deltaX < -threshold) {
|
||||
movePiece(-1, 0); // 左滑
|
||||
}
|
||||
} else {
|
||||
// 垂直滑动
|
||||
if (deltaY > threshold) {
|
||||
movePiece(0, 1); // 下滑
|
||||
} else if (deltaY < -threshold) {
|
||||
rotatePiece(); // 上滑旋转
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 页面加载 ====================
|
||||
window.addEventListener('load', function() {
|
||||
console.log('📄 页面加载完成,开始初始化游戏...');
|
||||
initGame();
|
||||
|
||||
// 添加Windows兼容性提示
|
||||
console.log('🪟 Windows兼容性检查:');
|
||||
console.log('✅ Canvas 2D API: 支持');
|
||||
console.log('✅ 键盘事件: 支持');
|
||||
console.log('✅ 触摸事件: 支持');
|
||||
console.log('✅ 游戏循环: 使用requestAnimationFrame');
|
||||
console.log('✅ 无外部依赖: 纯JavaScript + Canvas 2D');
|
||||
console.log('🎮 游戏已准备好,点击"开始游戏"按钮开始');
|
||||
});
|
||||
|
||||
// 防止页面滚动
|
||||
document.addEventListener('touchmove', function(event) {
|
||||
if (event.target === canvas) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}, { passive: false });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,703 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>🎮 俄罗斯方块 | 工作版</title>
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
touch-action: none;
|
||||
}
|
||||
#game-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
box-shadow: 0 0 40px rgba(0, 100, 255, 0.3);
|
||||
border-radius: 8px;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
/* 虚拟控制按钮容器 */
|
||||
.controls-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 100px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-button.start {
|
||||
background: linear-gradient(145deg, #10b981 0%, #047857 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-button.restart {
|
||||
background: linear-gradient(145deg, #f59e0b 0%, #d97706 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.control-button {
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
border: 2px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.1s ease;
|
||||
}
|
||||
|
||||
.control-row:nth-child(2) {
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #aaa;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
z-index: 1000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #68d391;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
max-width: 300px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading" id="loading">🎮 加载俄罗斯方块...</div>
|
||||
<div class="status-message" id="status-message"></div>
|
||||
|
||||
<div id="game-container">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div class="controls-container">
|
||||
<!-- 第一行:开始/旋转/重来按钮 -->
|
||||
<div class="control-row">
|
||||
<button class="action-button start" id="start-btn">
|
||||
<span>▶️</span> 开始
|
||||
</button>
|
||||
<div class="control-button rotate" id="rotate-btn">↻ 旋转</div>
|
||||
<button class="action-button restart" id="restart-btn">
|
||||
<span>🔄</span> 重来
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行:方向控制按钮 -->
|
||||
<div class="control-row">
|
||||
<div class="control-button left" id="left-btn">←</div>
|
||||
<div class="control-button down" id="down-btn">↓</div>
|
||||
<div class="control-button right" id="right-btn">→</div>
|
||||
</div>
|
||||
|
||||
<!-- 游戏信息面板 -->
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<span class="info-label">分数</span>
|
||||
<span class="info-value" id="score">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">等级</span>
|
||||
<span class="info-value" id="level">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">消行</span>
|
||||
<span class="info-value" id="lines">0</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">速度</span>
|
||||
<span class="info-value" id="speed">1.0x</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="debug-info" id="debug-info">
|
||||
<div>调试信息:</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 调试日志 ====================
|
||||
function debugLog(message) {
|
||||
const debugEl = document.getElementById('debug-info');
|
||||
const logEntry = document.createElement('div');
|
||||
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
||||
debugEl.appendChild(logEntry);
|
||||
debugEl.scrollTop = debugEl.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// ==================== 状态消息 ====================
|
||||
function showStatus(message, duration = 2000) {
|
||||
const statusEl = document.getElementById('status-message');
|
||||
statusEl.textContent = message;
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
statusEl.style.display = 'none';
|
||||
}, duration);
|
||||
}
|
||||
|
||||
// ==================== 隐藏加载界面 ====================
|
||||
function hideLoading() {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
|
||||
// ==================== 俄罗斯方块游戏 ====================
|
||||
class TetrisGame {
|
||||
constructor() {
|
||||
debugLog('🎮 创建TetrisGame实例');
|
||||
|
||||
// 获取画布
|
||||
this.canvas = document.getElementById('game-canvas');
|
||||
this.ctx = this.canvas.getContext('2d');
|
||||
|
||||
if (!this.canvas || !this.ctx) {
|
||||
debugLog('❌ Canvas元素或上下文未找到');
|
||||
showStatus('❌ Canvas初始化失败', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLog('✅ Canvas初始化成功');
|
||||
|
||||
// 游戏配置
|
||||
this.gridWidth = 10; // 10列
|
||||
this.gridHeight = 20; // 20行
|
||||
this.cellSize = 24; // 每个格子大小
|
||||
|
||||
// 游戏状态
|
||||
this.board = [];
|
||||
this.currentPiece = null;
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = true;
|
||||
this.isGameOver = false;
|
||||
this.gameLoop = null;
|
||||
this.dropTimer = 0;
|
||||
this.lastFrameTime = 0;
|
||||
|
||||
// 方块类型定义
|
||||
this.pieceTypes = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff' }, // 青色
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff' }, // 蓝色
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff8000' }, // 橙色
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00' }, // 黄色
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00' }, // 绿色
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#8000ff' }, // 紫色
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000' } // 红色
|
||||
];
|
||||
|
||||
// 初始化游戏
|
||||
this.initGame();
|
||||
this.setupControls();
|
||||
this.setupUI();
|
||||
|
||||
debugLog('✅ 游戏初始化完成');
|
||||
showStatus('✅ 俄罗斯方块已加载,点击开始按钮或按任意键开始游戏', 3000);
|
||||
hideLoading();
|
||||
}
|
||||
|
||||
initGame() {
|
||||
debugLog('初始化游戏逻辑');
|
||||
|
||||
// 清空游戏场地
|
||||
this.board = Array(this.gridHeight).fill().map(() => Array(this.gridWidth).fill(0));
|
||||
|
||||
// 重置游戏状态
|
||||
this.score = 0;
|
||||
this.level = 0;
|
||||
this.lines = 0;
|
||||
this.gameSpeed = 1.0;
|
||||
this.isPaused = false;
|
||||
this.isGameOver = false;
|
||||
this.dropTimer = 0;
|
||||
this.lastFrameTime = 0;
|
||||
|
||||
// 生成第一个方块
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 开始游戏循环
|
||||
this.startGameLoop();
|
||||
|
||||
// 更新UI
|
||||
this.updateUI();
|
||||
|
||||
debugLog('🎮 游戏开始!');
|
||||
}
|
||||
|
||||
spawnNewPiece() {
|
||||
const randomType = this.pieceTypes[Math.floor(Math.random() * this.pieceTypes.length)];
|
||||
this.currentPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
x: Math.floor(this.gridWidth / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
debugLog(`生成新方块: ${this.currentPiece.type}`);
|
||||
}
|
||||
|
||||
startGameLoop() {
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
}
|
||||
|
||||
const gameLoop = (timestamp) => {
|
||||
if (!this.lastFrameTime) this.lastFrameTime = timestamp;
|
||||
|
||||
const deltaTime = timestamp - this.lastFrameTime;
|
||||
|
||||
// 自动下落
|
||||
if (!this.isPaused && !this.isGameOver) {
|
||||
this.dropTimer += deltaTime;
|
||||
|
||||
if (this.dropTimer > 1000 / this.gameSpeed) {
|
||||
this.movePiece(0, 1);
|
||||
this.dropTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染
|
||||
this.render();
|
||||
|
||||
// 继续循环
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
this.lastFrameTime = timestamp;
|
||||
};
|
||||
|
||||
this.gameLoop = requestAnimationFrame(gameLoop);
|
||||
debugLog('✅ 游戏循环已启动');
|
||||
}
|
||||
|
||||
movePiece(dx, dy) {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
const newX = this.currentPiece.x + dx;
|
||||
const newY = this.currentPiece.y + dy;
|
||||
|
||||
if (this.isValidMove(this.currentPiece.shape, newX, newY)) {
|
||||
this.currentPiece.x = newX;
|
||||
this.currentPiece.y = newY;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
this.lockPiece();
|
||||
this.checkLines();
|
||||
this.spawnNewPiece();
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!this.isValidMove(this.currentPiece.shape, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.gameOver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
if (newX < 0 || newX >= this.gridWidth || newY >= this.gridHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newY >= 0 && this.board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
lockPiece() {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const boardX = x + col;
|
||||
const boardY = y + row;
|
||||
|
||||
if (boardY >= 0) {
|
||||
this.board[boardY][boardX] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog(`方块固定在位置: (${x}, ${y})`);
|
||||
}
|
||||
|
||||
checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = this.gridHeight - 1; y >= 0; y--) {
|
||||
if (this.board[y].every(cell => cell !== 0)) {
|
||||
// 移除该行
|
||||
this.board.splice(y, 1);
|
||||
// 在顶部添加新行
|
||||
this.board.unshift(Array(this.gridWidth).fill(0));
|
||||
linesCleared++;
|
||||
y++; // 重新检查同一位置
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
this.lines += linesCleared;
|
||||
this.score += linesCleared * 100 * (this.level + 1);
|
||||
this.level = Math.floor(this.lines / 10);
|
||||
this.gameSpeed = 1.0 + this.level * 0.1;
|
||||
|
||||
debugLog(`消除 ${linesCleared} 行,得分: ${linesCleared * 100 * (this.level + 1)}`);
|
||||
showStatus(`🎉 消除 ${linesCleared} 行!`, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
rotatePiece() {
|
||||
if (!this.currentPiece || this.isPaused || this.isGameOver) return;
|
||||
|
||||
// 旋转矩阵
|
||||
const rotateMatrix = (matrix) => {
|
||||
const result = [];
|
||||
for (let i = 0; i < matrix[0].length; i++) {
|
||||
result[i] = [];
|
||||
for (let j = 0; j < matrix.length; j++) {
|
||||
result[i][j] = matrix[matrix.length - 1 - j][i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const rotated = rotateMatrix(this.currentPiece.shape);
|
||||
if (this.isValidMove(rotated, this.currentPiece.x, this.currentPiece.y)) {
|
||||
this.currentPiece.shape = rotated;
|
||||
debugLog('旋转方块');
|
||||
}
|
||||
}
|
||||
|
||||
gameOver() {
|
||||
this.isGameOver = true;
|
||||
if (this.gameLoop) {
|
||||
cancelAnimationFrame(this.gameLoop);
|
||||
this.gameLoop = null;
|
||||
}
|
||||
|
||||
debugLog(`游戏结束!最终得分: ${this.score}`);
|
||||
showStatus(`🎮 游戏结束!最终得分: ${this.score}`, 5000);
|
||||
}
|
||||
|
||||
togglePause() {
|
||||
this.isPaused = !this.isPaused;
|
||||
|
||||
if (this.isPaused) {
|
||||
debugLog('游戏暂停');
|
||||
showStatus('⏸️ 游戏暂停');
|
||||
} else {
|
||||
debugLog('游戏继续');
|
||||
showStatus('▶️ 游戏继续');
|
||||
this.lastFrameTime = performance.now();
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
render() {
|
||||
// 清空画布
|
||||
this.ctx.fillStyle = '#111827';
|
||||
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
|
||||
// 绘制网格
|
||||
this.ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
this.ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x <= this.gridWidth; x++) {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(x * this.cellSize, 0);
|
||||
this.ctx.lineTo(x * this.cellSize, this.canvas.height);
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
for (let y = 0; y <= this.gridHeight; y++) {
|
||||
this.ctx.beginPath();
|
||||
this.ctx.moveTo(0, y * this.cellSize);
|
||||
this.ctx.lineTo(this.canvas.width, y * this.cellSize);
|
||||
this.ctx.stroke();
|
||||
}
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < this.gridHeight; y++) {
|
||||
for (let x = 0; x < this.gridWidth; x++) {
|
||||
if (this.board[y][x]) {
|
||||
this.ctx.fillStyle = this.board[y][x];
|
||||
this.ctx.fillRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
this.ctx.strokeStyle = 'white';
|
||||
this.ctx.lineWidth = 2;
|
||||
this.ctx.strokeRect(x * this.cellSize, y * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (this.currentPiece) {
|
||||
const { shape, x, y, color } = this.currentPiece;
|
||||
|
||||
this.ctx.fillStyle = color;
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
this.ctx.fillRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
|
||||
this.ctx.strokeStyle = 'white';
|
||||
this.ctx.lineWidth = 2;
|
||||
this.ctx.strokeRect((x + col) * this.cellSize, (y + row) * this.cellSize, this.cellSize, this.cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateUI() {
|
||||
document.getElementById('score').textContent = this.score;
|
||||
document.getElementById('level').textContent = this.level;
|
||||
document.getElementById('lines').textContent = this.lines;
|
||||
document.getElementById('speed').textContent = this.gameSpeed.toFixed(1) + 'x';
|
||||
|
||||
const startBtn = document.getElementById('start-btn');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 开始';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isPaused) {
|
||||
startBtn.innerHTML = '<span>▶️</span> 继续';
|
||||
startBtn.className = 'action-button start';
|
||||
} else if (this.isGameOver) {
|
||||
startBtn.innerHTML = '<span>🔄</span> 重新开始';
|
||||
startBtn.className = 'action-button restart';
|
||||
} else {
|
||||
startBtn.innerHTML = '<span>⏸️</span> 暂停';
|
||||
startBtn.className = 'action-button start';
|
||||
}
|
||||
}
|
||||
|
||||
setupControls() {
|
||||
debugLog('设置控件事件...');
|
||||
|
||||
// 开始按钮
|
||||
document.getElementById('start-btn').addEventListener('click', () => {
|
||||
debugLog('开始按钮点击');
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
} else if (this.isPaused) {
|
||||
this.togglePause();
|
||||
} else if (this.isGameOver) {
|
||||
this.initGame();
|
||||
} else {
|
||||
this.togglePause();
|
||||
}
|
||||
});
|
||||
|
||||
// 重来按钮
|
||||
document.getElementById('restart-btn').addEventListener('click', () => {
|
||||
debugLog('重来按钮点击');
|
||||
this.initGame();
|
||||
});
|
||||
|
||||
// 方向按钮
|
||||
document.getElementById('left-btn').addEventListener('click', () => {
|
||||
debugLog('左按钮点击');
|
||||
this.movePiece(-1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('right-btn').addEventListener('click', () => {
|
||||
debugLog('右按钮点击');
|
||||
this.movePiece(1, 0);
|
||||
});
|
||||
|
||||
document.getElementById('down-btn').addEventListener('click', () => {
|
||||
debugLog('下按钮点击');
|
||||
this.movePiece(0, 1);
|
||||
});
|
||||
|
||||
document.getElementById('rotate-btn').addEventListener('click', () => {
|
||||
debugLog('旋转按钮点击');
|
||||
this.rotatePiece();
|
||||
});
|
||||
|
||||
// 键盘控制
|
||||
document.addEventListener('keydown', (e) => {
|
||||
debugLog(`键盘按键: ${e.key}`);
|
||||
|
||||
// 如果游戏还没开始,按任意键开始游戏
|
||||
if (!this.currentPiece && !this.isGameOver) {
|
||||
this.initGame();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isPaused || this.isGameOver) return;
|
||||
|
||||
switch(e.key) {
|
||||
case 'ArrowLeft':
|
||||
this.movePiece(-1, 0);
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
this.movePiece(1, 0);
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
this.movePiece(0, 1);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
case ' ':
|
||||
this.rotatePiece();
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
this.togglePause();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
debugLog('控件事件设置完成');
|
||||
}
|
||||
|
||||
setupUI() {
|
||||
// 添加按钮按下效果
|
||||
document.querySelectorAll('.action-button, .control-button').forEach(btn => {
|
||||
btn.addEventListener('mousedown', () => {
|
||||
btn.style.transform = 'scale(0.95)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseup', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
btn.addEventListener('mouseleave', () => {
|
||||
btn.style.transform = 'scale(1)';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 页面加载完成 ====================
|
||||
window.addEventListener('load', () => {
|
||||
debugLog('页面加载完成');
|
||||
debugLog(`浏览器: ${navigator.userAgent}`);
|
||||
debugLog(`平台: ${navigator.platform}`);
|
||||
|
||||
// 创建游戏实例
|
||||
window.game = new TetrisGame();
|
||||
});
|
||||
|
||||
// ==================== 错误处理 ====================
|
||||
window.addEventListener('error', (e) => {
|
||||
console.error('全局错误:', e);
|
||||
debugLog(`错误: ${e.message}`);
|
||||
showStatus(`❌ JavaScript错误: ${e.message}`, 5000);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,541 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>🎮 俄罗斯方块 | 最终工作版</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
.container { max-width: 800px; width: 100%; text-align: center; }
|
||||
h1 { font-size: 2.5rem; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0,0,0,0.3); }
|
||||
.subtitle { font-size: 1.2rem; opacity: 0.9; margin-bottom: 20px; }
|
||||
.game-area { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; margin-bottom: 20px; }
|
||||
canvas {
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||
}
|
||||
.info-panel {
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
min-width: 200px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||
}
|
||||
.info-item { margin-bottom: 15px; text-align: left; }
|
||||
.info-label { font-size: 0.9rem; opacity: 0.7; margin-bottom: 5px; }
|
||||
.info-value { font-size: 1.5rem; font-weight: bold; color: #ffd700; }
|
||||
.controls { margin-top: 20px; }
|
||||
button {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 50px;
|
||||
padding: 12px 24px;
|
||||
font-size: 1.1rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
|
||||
margin: 5px;
|
||||
}
|
||||
button:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }
|
||||
button:active { transform: translateY(0); }
|
||||
.direction-buttons {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.dir-btn { width: 60px; height: 60px; border-radius: 50%; font-size: 1.5rem; }
|
||||
.rotate-btn { background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%); }
|
||||
.instructions {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
margin-top: 20px;
|
||||
text-align: left;
|
||||
display: none;
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.game-area { flex-direction: column; align-items: center; }
|
||||
.info-panel { width: 100%; max-width: 400px; }
|
||||
h1 { font-size: 2rem; }
|
||||
button { padding: 10px 20px; font-size: 1rem; }
|
||||
.dir-btn { width: 50px; height: 50px; font-size: 1.3rem; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🎮 俄罗斯方块</h1>
|
||||
<div class="subtitle">最终工作版 | Windows完美兼容 | 纯Canvas 2D</div>
|
||||
|
||||
<div class="game-area">
|
||||
<canvas id="game-canvas" width="540" height="720"></canvas>
|
||||
|
||||
<div class="info-panel">
|
||||
<div class="info-item">
|
||||
<div class="info-label">分数</div>
|
||||
<div id="score" class="info-value">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">等级</div>
|
||||
<div id="level" class="info-value">1</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">消行数</div>
|
||||
<div id="lines" class="info-value">0</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">下一个方块</div>
|
||||
<div id="next-piece" class="info-value">?</div>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<div>
|
||||
<button id="start-btn" onclick="startGame()">▶️ 开始游戏</button>
|
||||
<button onclick="togglePause()">⏸️ 暂停</button>
|
||||
<button onclick="restartGame()">🔄 重来</button>
|
||||
</div>
|
||||
|
||||
<div class="direction-buttons">
|
||||
<button class="dir-btn" onclick="moveLeft()">←</button>
|
||||
<button class="dir-btn rotate-btn" onclick="rotatePiece()">↻</button>
|
||||
<button class="dir-btn" onclick="moveRight()">→</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button class="dir-btn" onclick="moveDown()" style="width: 100%; margin-top: 10px;">↓ 快速下落</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="instructions" id="instructions">
|
||||
<h3>🎮 游戏说明</h3>
|
||||
<p><strong>控制</strong>: ← → 移动,空格键旋转,↓ 加速下落,P键暂停</p>
|
||||
<p><strong>目标</strong>: 消除完整的行来获得分数</p>
|
||||
<button onclick="hideInstructions()" style="margin-top: 10px; width: 100%;">返回游戏</button>
|
||||
</div>
|
||||
|
||||
<button onclick="showInstructions()" style="margin-top: 20px;">📖 显示说明</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ==================== 游戏配置 ====================
|
||||
const GRID_WIDTH = 10;
|
||||
const GRID_HEIGHT = 20;
|
||||
const CELL_SIZE = 30;
|
||||
|
||||
// 方块类型
|
||||
const PIECE_TYPES = [
|
||||
{ type: 'I', shape: [[1,1,1,1]], color: '#00f5ff', name: '长条' },
|
||||
{ type: 'J', shape: [[1,0,0],[1,1,1]], color: '#0000ff', name: 'J形' },
|
||||
{ type: 'L', shape: [[0,0,1],[1,1,1]], color: '#ff7f00', name: 'L形' },
|
||||
{ type: 'O', shape: [[1,1],[1,1]], color: '#ffff00', name: '方块' },
|
||||
{ type: 'S', shape: [[0,1,1],[1,1,0]], color: '#00ff00', name: 'S形' },
|
||||
{ type: 'T', shape: [[0,1,0],[1,1,1]], color: '#800080', name: 'T形' },
|
||||
{ type: 'Z', shape: [[1,1,0],[0,1,1]], color: '#ff0000', name: 'Z形' }
|
||||
];
|
||||
|
||||
// ==================== 游戏状态 ====================
|
||||
let canvas, ctx;
|
||||
let board = [];
|
||||
let currentPiece = null;
|
||||
let nextPiece = null;
|
||||
let score = 0;
|
||||
let level = 1;
|
||||
let lines = 0;
|
||||
let gameRunning = false;
|
||||
let gamePaused = false;
|
||||
let gameOver = false;
|
||||
let lastUpdate = 0;
|
||||
let gameLoopId = null;
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
function initGame() {
|
||||
console.log('🎮 初始化俄罗斯方块游戏...');
|
||||
|
||||
canvas = document.getElementById('game-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
console.error('❌ 无法获取Canvas 2D上下文');
|
||||
alert('您的浏览器不支持Canvas 2D');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ Canvas 2D上下文获取成功');
|
||||
|
||||
// 初始化游戏板
|
||||
initBoard();
|
||||
|
||||
// 生成预览方块
|
||||
generateNextPiece();
|
||||
|
||||
// 初始渲染
|
||||
renderGame();
|
||||
|
||||
console.log('✅ 游戏初始化完成');
|
||||
}
|
||||
|
||||
function initBoard() {
|
||||
board = [];
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
board[y] = [];
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
board[y][x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateNextPiece() {
|
||||
const randomType = PIECE_TYPES[Math.floor(Math.random() * PIECE_TYPES.length)];
|
||||
nextPiece = {
|
||||
type: randomType.type,
|
||||
shape: randomType.shape,
|
||||
color: randomType.color,
|
||||
name: randomType.name,
|
||||
x: Math.floor(GRID_WIDTH / 2) - Math.floor(randomType.shape[0].length / 2),
|
||||
y: 0
|
||||
};
|
||||
|
||||
document.getElementById('next-piece').textContent = nextPiece.name;
|
||||
}
|
||||
|
||||
function spawnNewPiece() {
|
||||
if (nextPiece) {
|
||||
currentPiece = {
|
||||
type: nextPiece.type,
|
||||
shape: nextPiece.shape,
|
||||
color: nextPiece.color,
|
||||
name: nextPiece.name,
|
||||
x: nextPiece.x,
|
||||
y: nextPiece.y
|
||||
};
|
||||
}
|
||||
|
||||
generateNextPiece();
|
||||
|
||||
console.log(`生成新方块: ${currentPiece.type} (${currentPiece.name}) 位置: (${currentPiece.x}, ${currentPiece.y})`);
|
||||
|
||||
// 检查游戏是否结束
|
||||
if (!isValidMove(currentPiece.shape, currentPiece.x, currentPiece.y)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏逻辑 ====================
|
||||
function isValidMove(shape, x, y) {
|
||||
for (let row = 0; row < shape.length; row++) {
|
||||
for (let col = 0; col < shape[row].length; col++) {
|
||||
if (shape[row][col]) {
|
||||
const newX = x + col;
|
||||
const newY = y + row;
|
||||
|
||||
// 检查边界
|
||||
if (newX < 0 || newX >= GRID_WIDTH || newY >= GRID_HEIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查碰撞
|
||||
if (newY >= 0 && board[newY][newX]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function movePiece(dx, dy) {
|
||||
if (!currentPiece || gamePaused || gameOver) return false;
|
||||
|
||||
const newX = currentPiece.x + dx;
|
||||
const newY = currentPiece.y + dy;
|
||||
|
||||
console.log(`尝试移动: 从(${currentPiece.x},${currentPiece.y}) 到(${newX},${newY})`);
|
||||
|
||||
if (isValidMove(currentPiece.shape, newX, newY)) {
|
||||
currentPiece.x = newX;
|
||||
currentPiece.y = newY;
|
||||
console.log(`✅ 移动成功: (${newX},${newY})`);
|
||||
renderGame();
|
||||
return true;
|
||||
} else if (dy > 0) {
|
||||
// 固定方块
|
||||
console.log('🔒 固定方块');
|
||||
lockPiece();
|
||||
checkLines();
|
||||
spawnNewPiece();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function rotatePiece() {
|
||||
if (!currentPiece || gamePaused || gameOver) return;
|
||||
|
||||
// 创建旋转后的形状
|
||||
const shape = currentPiece.shape;
|
||||
const rows = shape.length;
|
||||
const cols = shape[0].length;
|
||||
const rotated = [];
|
||||
|
||||
for (let i = 0; i < cols; i++) {
|
||||
rotated[i] = [];
|
||||
for (let j = 0; j < rows; j++) {
|
||||
rotated[i][j] = shape[rows - 1 - j][i];
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试旋转
|
||||
if (isValidMove(rotated, currentPiece.x, currentPiece.y)) {
|
||||
currentPiece.shape = rotated;
|
||||
console.log('✅ 旋转成功');
|
||||
renderGame();
|
||||
}
|
||||
}
|
||||
|
||||
function lockPiece() {
|
||||
for (let row = 0; row < currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < currentPiece.shape[row].length; col++) {
|
||||
if (currentPiece.shape[row][col]) {
|
||||
const x = currentPiece.x + col;
|
||||
const y = currentPiece.y + row;
|
||||
|
||||
if (y >= 0) {
|
||||
board[y][x] = currentPiece.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkLines() {
|
||||
let linesCleared = 0;
|
||||
|
||||
for (let y = GRID_HEIGHT - 1; y >= 0; y--) {
|
||||
let lineFull = true;
|
||||
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (!board[y][x]) {
|
||||
lineFull = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lineFull) {
|
||||
board.splice(y, 1);
|
||||
board.unshift(new Array(GRID_WIDTH).fill(0));
|
||||
linesCleared++;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
if (linesCleared > 0) {
|
||||
const points = [0, 100, 300, 500, 800][linesCleared] * level;
|
||||
score += points;
|
||||
lines += linesCleared;
|
||||
level = Math.floor(lines / 10) + 1;
|
||||
|
||||
updateUI();
|
||||
console.log(`🎉 消除 ${linesCleared} 行,获得 ${points} 分`);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏循环 ====================
|
||||
function gameLoop() {
|
||||
if (!gameRunning || gameOver || gamePaused) return;
|
||||
|
||||
const now = Date.now();
|
||||
const deltaTime = (now - lastUpdate) / 1000;
|
||||
|
||||
// 每1秒下落一次
|
||||
if (deltaTime > 1.0) {
|
||||
console.log(`[游戏循环] 自动下落,deltaTime: ${deltaTime.toFixed(2)}秒`);
|
||||
movePiece(0, 1);
|
||||
lastUpdate = now;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 渲染 ====================
|
||||
function renderGame() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
const offsetX = (canvas.width - GRID_WIDTH * CELL_SIZE) / 2;
|
||||
const offsetY = (canvas.height - GRID_HEIGHT * CELL_SIZE) / 2;
|
||||
|
||||
// 绘制背景
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.05)';
|
||||
ctx.fillRect(offsetX, offsetY, GRID_WIDTH * CELL_SIZE, GRID_HEIGHT * CELL_SIZE);
|
||||
|
||||
// 绘制已固定的方块
|
||||
for (let y = 0; y < GRID_HEIGHT; y++) {
|
||||
for (let x = 0; x < GRID_WIDTH; x++) {
|
||||
if (board[y][x]) {
|
||||
ctx.fillStyle = board[y][x];
|
||||
ctx.fillRect(
|
||||
offsetX + x * CELL_SIZE,
|
||||
offsetY + y * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(
|
||||
offsetX + x * CELL_SIZE,
|
||||
offsetY + y * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制当前方块
|
||||
if (currentPiece) {
|
||||
ctx.fillStyle = currentPiece.color;
|
||||
|
||||
for (let row = 0; row < currentPiece.shape.length; row++) {
|
||||
for (let col = 0; col < currentPiece.shape[row].length; col++) {
|
||||
if (currentPiece.shape[row][col]) {
|
||||
ctx.fillRect(
|
||||
offsetX + (currentPiece.x + col) * CELL_SIZE,
|
||||
offsetY + (currentPiece.y + row) * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE
|
||||
);
|
||||
|
||||
ctx.strokeStyle = 'white';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(
|
||||
offsetX + (currentPiece.x + col) * CELL_SIZE,
|
||||
offsetY + (currentPiece.y + row) * CELL_SIZE,
|
||||
CELL_SIZE,
|
||||
CELL_SIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 游戏控制 ====================
|
||||
window.startGame = function() {
|
||||
if (gameRunning) return;
|
||||
|
||||
console.log('🎮 开始游戏...');
|
||||
|
||||
gameRunning = true;
|
||||
gamePaused = false;
|
||||
gameOver = false;
|
||||
score = 0;
|
||||
level = 1;
|
||||
lines = 0;
|
||||
lastUpdate = Date.now();
|
||||
|
||||
initBoard();
|
||||
spawnNewPiece();
|
||||
updateUI();
|
||||
|
||||
// 使用setInterval确保Windows兼容性
|
||||
if (gameLoopId) clearInterval(gameLoopId);
|
||||
gameLoopId = setInterval(gameLoop, 100); // 每100ms检查一次
|
||||
|
||||
document.getElementById('start-btn').textContent = '⏸️ 暂停';
|
||||
|
||||
console.log('✅ 游戏已启动,使用setInterval游戏循环');
|
||||
};
|
||||
|
||||
window.togglePause = function() {
|
||||
if (gameOver) return;
|
||||
|
||||
gamePaused = !gamePaused;
|
||||
console.log(gamePaused ? '⏸️ 游戏暂停' : '▶️ 游戏继续');
|
||||
|
||||
document.getElementById('start-btn').textContent = gamePaused ? '▶️ 继续' : '⏸️ 暂停';
|
||||
};
|
||||
|
||||
window.restartGame = function() {
|
||||
console.log('🔄 重新开始游戏...');
|
||||
|
||||
if (gameLoopId) {
|
||||
clearInterval(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
startGame();
|
||||
};
|
||||
|
||||
function endGame() {
|
||||
gameOver = true;
|
||||
gameRunning = false;
|
||||
|
||||
if (gameLoopId) {
|
||||
clearInterval(gameLoopId);
|
||||
gameLoopId = null;
|
||||
}
|
||||
|
||||
console.log(`💀 游戏结束,最终分数: ${score}`);
|
||||
alert(`游戏结束!\n最终分数: ${score}\n消行数: ${lines}\n等级: ${level}`);
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
document.getElementById('score').textContent = score;
|
||||
document.getElementById('level').textContent = level;
|
||||
document.getElementById('lines').textContent = lines;
|
||||
}
|
||||
|
||||
// ==================== 控制函数 ====================
|
||||
window.moveLeft = function() { movePiece(-1, 0); };
|
||||
window.moveRight = function() { movePiece(1, 0); };
|
||||
window.moveDown = function() { movePiece(0, 1); };
|
||||
|
||||
window.showInstructions = function() {
|
||||
document.getElementById('instructions').style.display = 'block';
|
||||
};
|
||||
|
||||
window.hideInstructions = function() {
|
||||
document.getElementById('instructions').style.display = 'none';
|
||||
};
|
||||
|
||||
// ==================== 键盘控制 ====================
|
||||
document.addEventListener('keydown', function(event) {
|
||||
if (!gameRunning || gameOver) return;
|
||||
|
||||
console.log(`键盘按键: ${event.key}`);
|
||||
|
||||
switch(event.key) {
|
||||
case 'ArrowLeft': movePiece(-1, 0); break;
|
||||
case 'ArrowRight': movePiece(1, 0); break;
|
||||
case 'ArrowDown': movePiece(0, 1); break;
|
||||
case ' ':
|
||||
case 'ArrowUp': rotatePiece(); break;
|
||||
case 'p':
|
||||
case 'P': togglePause(); break;
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 页面加载 ====================
|
||||
window.addEventListener('load', function() {
|
||||
console.log('📄 页面加载完成');
|
||||
initGame();
|
||||
console.log('🪟 Windows兼容性: 使用setInterval确保兼容性');
|
||||
console.log('🎮 游戏已准备好,点击"开始游戏"按钮开始');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,447 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Windows兼容性测试脚本
|
||||
专门测试俄罗斯方块在Windows浏览器上的兼容性
|
||||
"""
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
# 测试配置
|
||||
BASE_URL = "http://129.211.173.87:8895/games/tetris/"
|
||||
OUTPUT_DIR = Path("/tmp/windows_compatibility_test")
|
||||
OUTPUT_DIR.mkdir(exist_ok=True)
|
||||
|
||||
# 测试版本 - 专门针对Windows兼容性
|
||||
WINDOWS_VERSIONS = [
|
||||
{"file": "index.html", "name": "默认版(修复后)", "description": "修复了位置计算问题的最终Canvas 2D版"},
|
||||
{"file": "tetris_final_canvas2d_fixed.html", "name": "最终Canvas 2D修复版", "description": "专门修复nextPiece位置问题的版本"},
|
||||
{"file": "tetris_simple_fall_test.html", "name": "简单下落测试版", "description": "最简单的Canvas 2D版本"},
|
||||
{"file": "tetris_playcanvas_working.html", "name": "PlayCanvas工作版", "description": "PlayCanvas版本,可能有兼容性问题"},
|
||||
]
|
||||
|
||||
def test_windows_compatibility(page, version):
|
||||
"""测试Windows兼容性"""
|
||||
print(f"\n🪟 Windows兼容性测试: {version['name']}")
|
||||
print("-" * 60)
|
||||
print(f"📝 描述: {version['description']}")
|
||||
|
||||
url = BASE_URL + version["file"]
|
||||
print(f"🌐 URL: {url}")
|
||||
|
||||
# 使用Windows用户代理
|
||||
page.set_extra_http_headers({
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
})
|
||||
|
||||
# 导航到页面
|
||||
start_time = time.time()
|
||||
page.goto(url, wait_until="networkidle", timeout=15000)
|
||||
load_time = time.time() - start_time
|
||||
print(f"⏱️ 页面加载时间: {load_time:.2f}秒")
|
||||
|
||||
# 等待页面初始化
|
||||
time.sleep(2)
|
||||
|
||||
# 收集所有日志
|
||||
all_logs = []
|
||||
page_errors = []
|
||||
|
||||
def on_console(msg):
|
||||
all_logs.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S.%f")[:-3],
|
||||
"type": msg.type,
|
||||
"text": msg.text
|
||||
})
|
||||
|
||||
def on_pageerror(error):
|
||||
page_errors.append({
|
||||
"time": datetime.now().strftime("%H:%M:%S.%f")[:-3],
|
||||
"error": str(error)
|
||||
})
|
||||
|
||||
page.on("console", on_console)
|
||||
page.on("pageerror", on_pageerror)
|
||||
|
||||
# 检查关键元素
|
||||
print("\n🔍 页面元素检查:")
|
||||
|
||||
# Canvas检查
|
||||
canvas_elements = page.query_selector_all("canvas")
|
||||
canvas_count = len(canvas_elements)
|
||||
print(f" 🎨 Canvas数量: {canvas_count}")
|
||||
|
||||
canvas_info = []
|
||||
for i, canvas in enumerate(canvas_elements):
|
||||
box = canvas.bounding_box()
|
||||
if box:
|
||||
info = f"Canvas{i+1}: {int(box['width'])}x{int(box['height'])}"
|
||||
canvas_info.append(info)
|
||||
print(f" {info}")
|
||||
|
||||
# 按钮检查
|
||||
print(" 🔘 按钮检查:")
|
||||
button_selectors = ["#start-btn", "#pause-btn", "#restart-btn",
|
||||
"#left-btn", "#right-btn", "#down-btn", "#rotate-btn"]
|
||||
|
||||
found_buttons = []
|
||||
for selector in button_selectors:
|
||||
elements = page.query_selector_all(selector)
|
||||
if elements:
|
||||
found_buttons.append(f"{selector}: {len(elements)}个")
|
||||
print(f" ✅ {selector}: {len(elements)}个")
|
||||
|
||||
# 测试游戏启动
|
||||
print("\n🎮 游戏启动测试:")
|
||||
|
||||
# 方法1: 点击开始按钮
|
||||
start_btn = page.query_selector("#start-btn")
|
||||
if start_btn:
|
||||
try:
|
||||
start_btn.click(timeout=3000)
|
||||
print(" ✅ 成功点击#start-btn按钮")
|
||||
except Exception as e:
|
||||
print(f" ❌ #start-btn点击失败: {e}")
|
||||
else:
|
||||
print(" ⚠️ 未找到#start-btn按钮")
|
||||
|
||||
# 方法2: 按空格键
|
||||
print(" ⌨️ 尝试按空格键启动...")
|
||||
page.keyboard.press(" ")
|
||||
|
||||
# 等待游戏运行
|
||||
print(" ⏳ 等待游戏运行10秒...")
|
||||
time.sleep(10)
|
||||
|
||||
# 分析日志
|
||||
print("\n📊 日志分析:")
|
||||
|
||||
# 分类日志
|
||||
init_logs = [log for log in all_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["初始化", "init", "canvas", "上下文", "context"])]
|
||||
spawn_logs = [log for log in all_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["生成", "spawn", "new piece", "方块", "piece"])]
|
||||
move_logs = [log for log in all_logs if any(keyword in log["text"].lower()
|
||||
for keyword in ["移动", "move", "下落", "drop", "位置", "x=", "y="])]
|
||||
error_logs = [log for log in all_logs if log["type"] == "error"]
|
||||
warning_logs = [log for log in all_logs if log["type"] == "warning"]
|
||||
|
||||
print(f" 总日志数: {len(all_logs)}条")
|
||||
print(f" 初始化日志: {len(init_logs)}条")
|
||||
print(f" 方块生成日志: {len(spawn_logs)}条")
|
||||
print(f" 方块移动日志: {len(move_logs)}条")
|
||||
print(f" 错误日志: {len(error_logs)}条")
|
||||
print(f" 警告日志: {len(warning_logs)}条")
|
||||
print(f" 页面错误: {len(page_errors)}条")
|
||||
|
||||
# 检查关键问题
|
||||
print("\n🔧 问题诊断:")
|
||||
|
||||
issues = []
|
||||
|
||||
# 检查NaN问题
|
||||
nan_logs = [log for log in all_logs if "NaN" in log["text"] or "undefined" in log["text"]]
|
||||
if nan_logs:
|
||||
issues.append(f"发现NaN/undefined问题: {len(nan_logs)}处")
|
||||
print(f" ❌ 发现NaN/undefined问题: {len(nan_logs)}处")
|
||||
for i, log in enumerate(nan_logs[:3]):
|
||||
print(f" {i+1}. {log['text'][:80]}...")
|
||||
else:
|
||||
print(" ✅ 未发现NaN/undefined问题")
|
||||
|
||||
# 检查位置计算
|
||||
position_logs = [log for log in all_logs if "位置" in log["text"] or "position" in log["text"].lower()]
|
||||
if position_logs:
|
||||
print(f" 📍 位置信息: {len(position_logs)}条")
|
||||
for i, log in enumerate(position_logs[-3:]):
|
||||
print(f" {i+1}. {log['text'][:60]}...")
|
||||
|
||||
# 检查方块生成
|
||||
if spawn_logs:
|
||||
print(f" 🧱 方块生成: {len(spawn_logs)}次")
|
||||
for i, log in enumerate(spawn_logs[-3:]):
|
||||
print(f" {i+1}. {log['text'][:60]}...")
|
||||
else:
|
||||
issues.append("方块未生成")
|
||||
print(" ❌ 方块未生成")
|
||||
|
||||
# 检查方块移动
|
||||
if move_logs:
|
||||
print(f" 🚀 方块移动: {len(move_logs)}次")
|
||||
move_positions = []
|
||||
for log in move_logs:
|
||||
if "x=" in log["text"] and "y=" in log["text"]:
|
||||
# 提取位置信息
|
||||
import re
|
||||
match = re.search(r'x=([\d.-]+).*y=([\d.-]+)', log["text"])
|
||||
if match:
|
||||
x, y = match.groups()
|
||||
if x != "NaN" and y != "NaN":
|
||||
move_positions.append((float(x), float(y)))
|
||||
|
||||
if move_positions:
|
||||
print(f" 📈 有效移动位置: {len(move_positions)}个")
|
||||
print(f" 最后位置: x={move_positions[-1][0]}, y={move_positions[-1][1]}")
|
||||
else:
|
||||
issues.append("方块位置无效(NaN)")
|
||||
print(" ❌ 方块位置无效(NaN)")
|
||||
else:
|
||||
issues.append("方块未移动")
|
||||
print(" ❌ 方块未移动")
|
||||
|
||||
# 截图
|
||||
screenshot_path = OUTPUT_DIR / f"windows_{version['name'].replace(' ', '_').replace('(', '').replace(')', '')}.png"
|
||||
page.screenshot(path=str(screenshot_path), full_page=True)
|
||||
print(f"\n📸 截图保存: {screenshot_path}")
|
||||
|
||||
# 保存详细日志
|
||||
log_file = OUTPUT_DIR / f"windows_{version['name'].replace(' ', '_').replace('(', '').replace(')', '')}_logs.json"
|
||||
with open(log_file, "w", encoding="utf-8") as f:
|
||||
json.dump({
|
||||
"version": version,
|
||||
"url": url,
|
||||
"load_time": load_time,
|
||||
"canvas_info": canvas_info,
|
||||
"found_buttons": found_buttons,
|
||||
"all_logs": all_logs[-100:], # 最后100条日志
|
||||
"page_errors": page_errors,
|
||||
"issues": issues,
|
||||
"summary": {
|
||||
"total_logs": len(all_logs),
|
||||
"init_logs": len(init_logs),
|
||||
"spawn_logs": len(spawn_logs),
|
||||
"move_logs": len(move_logs),
|
||||
"error_logs": len(error_logs),
|
||||
"warning_logs": len(warning_logs),
|
||||
"page_errors": len(page_errors),
|
||||
"nan_issues": len(nan_logs)
|
||||
}
|
||||
}, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"📄 详细日志保存: {log_file}")
|
||||
|
||||
# 评估兼容性
|
||||
print("\n📈 Windows兼容性评估:")
|
||||
|
||||
score = 100
|
||||
|
||||
# 扣分规则
|
||||
if len(page_errors) > 0:
|
||||
score -= 30
|
||||
print(f" ❌ 页面错误: -30分")
|
||||
|
||||
if len(nan_logs) > 0:
|
||||
score -= 40
|
||||
print(f" ❌ NaN问题: -40分")
|
||||
|
||||
if len(spawn_logs) == 0:
|
||||
score -= 50
|
||||
print(f" ❌ 方块未生成: -50分")
|
||||
elif len(move_logs) == 0:
|
||||
score -= 30
|
||||
print(f" ❌ 方块未移动: -30分")
|
||||
|
||||
if len(error_logs) > 5:
|
||||
score -= 20
|
||||
print(f" ❌ 过多错误日志: -20分")
|
||||
|
||||
# 加分规则
|
||||
if len(spawn_logs) > 0 and len(move_logs) > 0 and len(nan_logs) == 0:
|
||||
score += 20
|
||||
print(f" ✅ 游戏正常运行: +20分")
|
||||
|
||||
if len(page_errors) == 0:
|
||||
score += 10
|
||||
print(f" ✅ 无页面错误: +10分")
|
||||
|
||||
# 确保分数在0-100之间
|
||||
score = max(0, min(100, score))
|
||||
|
||||
# 评级
|
||||
if score >= 90:
|
||||
rating = "🏆 优秀"
|
||||
status = "🎉 完全兼容"
|
||||
elif score >= 70:
|
||||
rating = "✅ 良好"
|
||||
status = "👍 基本兼容"
|
||||
elif score >= 50:
|
||||
rating = "⚠️ 一般"
|
||||
status = "⚠️ 部分兼容"
|
||||
else:
|
||||
rating = "❌ 差"
|
||||
status = "❌ 不兼容"
|
||||
|
||||
print(f" 🏆 评分: {score}/100")
|
||||
print(f" 📊 评级: {rating}")
|
||||
print(f" 📋 状态: {status}")
|
||||
|
||||
if issues:
|
||||
print(f" 🔧 发现的问题: {', '.join(issues)}")
|
||||
|
||||
return {
|
||||
"version": version,
|
||||
"score": score,
|
||||
"rating": rating,
|
||||
"status": status,
|
||||
"issues": issues,
|
||||
"summary": {
|
||||
"spawn_logs": len(spawn_logs),
|
||||
"move_logs": len(move_logs),
|
||||
"nan_issues": len(nan_logs),
|
||||
"page_errors": len(page_errors),
|
||||
"error_logs": len(error_logs)
|
||||
},
|
||||
"screenshot": str(screenshot_path),
|
||||
"log_file": str(log_file),
|
||||
"url": url
|
||||
}
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print("=" * 80)
|
||||
print("🪟 Windows浏览器兼容性测试")
|
||||
print("=" * 80)
|
||||
print(f"测试时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print(f"测试版本: {len(WINDOWS_VERSIONS)}个")
|
||||
print(f"输出目录: {OUTPUT_DIR}")
|
||||
print("=" * 80)
|
||||
|
||||
results = []
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(
|
||||
headless=True,
|
||||
args=[
|
||||
"--no-sandbox",
|
||||
"--disable-setuid-sandbox",
|
||||
"--disable-dev-shm-usage",
|
||||
"--disable-accelerated-2d-canvas",
|
||||
"--disable-gpu"
|
||||
]
|
||||
)
|
||||
|
||||
try:
|
||||
for i, version in enumerate(WINDOWS_VERSIONS):
|
||||
print(f"\n{'#'*80}")
|
||||
print(f"测试进度: {i+1}/{len(WINDOWS_VERSIONS)}")
|
||||
|
||||
context = browser.new_context(
|
||||
viewport={"width": 1280, "height": 720}
|
||||
)
|
||||
page = context.new_page()
|
||||
|
||||
try:
|
||||
result = test_windows_compatibility(page, version)
|
||||
results.append(result)
|
||||
finally:
|
||||
page.close()
|
||||
context.close()
|
||||
|
||||
# 版本间间隔
|
||||
time.sleep(2)
|
||||
|
||||
finally:
|
||||
browser.close()
|
||||
|
||||
# 生成Windows兼容性报告
|
||||
generate_windows_report(results)
|
||||
|
||||
print(f"\n{'='*80}")
|
||||
print("✅ Windows兼容性测试完成!")
|
||||
print(f"📁 所有结果保存在: {OUTPUT_DIR}")
|
||||
print("=" * 80)
|
||||
|
||||
def generate_windows_report(results):
|
||||
"""生成Windows兼容性报告"""
|
||||
report_file = OUTPUT_DIR / "windows_compatibility_report.md"
|
||||
|
||||
with open(report_file, "w", encoding="utf-8") as f:
|
||||
f.write("# 🪟 Windows浏览器兼容性测试报告\n\n")
|
||||
f.write(f"**测试时间**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
|
||||
f.write(f"**测试环境**: Playwright + Chromium (模拟Windows Chrome 120)\n")
|
||||
f.write(f"**测试版本**: {len(results)}个\n\n")
|
||||
|
||||
f.write("## 📊 兼容性评分\n\n")
|
||||
f.write("| 排名 | 版本名称 | 评分 | 评级 | 状态 | 方块生成 | 方块移动 | NaN问题 | 页面错误 |\n")
|
||||
f.write("|------|----------|------|------|------|----------|----------|---------|----------|\n")
|
||||
|
||||
# 按评分排序
|
||||
sorted_results = sorted(results, key=lambda x: x["score"], reverse=True)
|
||||
|
||||
for i, result in enumerate(sorted_results):
|
||||
f.write(f"| {i+1} | {result['version']['name']} | ")
|
||||
f.write(f"{result['score']}/100 | {result['rating']} | {result['status']} | ")
|
||||
f.write(f"{result['summary']['spawn_logs']} | {result['summary']['move_logs']} | ")
|
||||
f.write(f"{result['summary']['nan_issues']} | {result['summary']['page_errors']} |\n")
|
||||
|
||||
f.write("\n## 🏆 推荐版本\n\n")
|
||||
|
||||
# 找出最佳版本
|
||||
if sorted_results:
|
||||
best_result = sorted_results[0]
|
||||
f.write(f"### 🥇 最佳Windows兼容版本: **{best_result['version']['name']}**\n")
|
||||
f.write(f"- **评分**: {best_result['score']}/100\n")
|
||||
f.write(f"- **状态**: {best_result['status']}\n")
|
||||
f.write(f"- **描述**: {best_result['version']['description']}\n")
|
||||
f.write(f"- **访问地址**: {best_result['url']}\n")
|
||||
f.write(f"- **截图**: {best_result['screenshot']}\n")
|
||||
f.write(f"- **日志**: {best_result['log_file']}\n")
|
||||
|
||||
if best_result["issues"]:
|
||||
f.write(f"- **已修复问题**: {', '.join(best_result['issues'])}\n")
|
||||
|
||||
f.write("\n## 🔧 问题分析\n\n")
|
||||
|
||||
# 分析所有问题
|
||||
f.write("### 发现的Windows兼容性问题:\n\n")
|
||||
|
||||
problem_categories = {}
|
||||
|
||||
for result in results:
|
||||
if result["issues"]:
|
||||
for issue in result["issues"]:
|
||||
if issue not in problem_categories:
|
||||
problem_categories[issue] = []
|
||||
problem_categories[issue].append(result["version"]["name"])
|
||||
|
||||
if problem_categories:
|
||||
for issue, versions in problem_categories.items():
|
||||
f.write(f"#### {issue}\n")
|
||||
f.write(f"- **影响版本**: {', '.join(versions)}\n")
|
||||
|
||||
# 提供解决方案
|
||||
if "NaN" in issue or "undefined" in issue:
|
||||
f.write("- **原因**: 位置计算错误,nextPiece对象缺少x/y属性\n")
|
||||
f.write("- **解决方案**: 在generateNextPiece()函数中添加x和y属性\n")
|
||||
elif "方块未生成" in issue:
|
||||
f.write("- **原因**: 游戏初始化失败或按钮事件未绑定\n")
|
||||
f.write("- **解决方案**: 检查游戏初始化代码和事件监听器\n")
|
||||
elif "方块未移动" in issue:
|
||||
f.write("- **原因**: 游戏循环未启动或时间计算错误\n")
|
||||
f.write("- **解决方案**: 检查游戏循环逻辑和dt时间计算\n")
|
||||
|
||||
f.write("\n")
|
||||
else:
|
||||
f.write("✅ 未发现严重兼容性问题\n")
|
||||
|
||||
f.write("\n## 🚀 Windows兼容性最佳实践\n\n")
|
||||
f.write("1. **避免NaN问题**: 确保所有游戏对象都有完整的属性\n")
|
||||
f.write("2. **位置计算**: 使用整数坐标,避免浮点数计算错误\n")
|
||||
f.write("3. **事件处理**: 使用标准事件API,避免浏览器特定API\n")
|
||||
f.write("4. **Canvas 2D**: 优先使用纯Canvas 2D API,兼容性最好\n")
|
||||
f.write("5. **错误处理**: 添加完整的try-catch错误处理\n")
|
||||
f.write("6. **日志调试**: 添加详细的调试日志,便于问题诊断\n")
|
||||
|
||||
f.write("\n## 📁 测试文件\n\n")
|
||||
f.write(f"- **报告文件**: {report_file}\n")
|
||||
f.write(f"- **截图目录**: {OUTPUT_DIR}/\n")
|
||||
f.write(f"- **日志文件**: {OUTPUT_DIR}/*_logs.json\n")
|
||||
f.write(f"- **测试脚本**: windows_compatibility_test.py\n")
|
||||
|
||||
print(f"📄 Windows兼容性报告生成: {report_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,134 @@
|
||||
# 经典俄罗斯方块(标准/复古版)规则
|
||||
以下为**经典俄罗斯方块(FC/Game Boy 标准规则)** 的完整、可直接用于开发的逐条规则,不含现代扩展(T-Spin、连击、全清等),确保兼容性与简洁性。
|
||||
|
||||
---
|
||||
|
||||
## 一、游戏场地(Playfield)
|
||||
1. 标准场地为 **10列 × 20行** 的矩形网格(单位:正方形格子)。
|
||||
2. 网格坐标:通常以 **左上角为 (0,0)**,向右x增加,向下y增加。
|
||||
3. 场地边界:
|
||||
- 左边界:x=0
|
||||
- 右边界:x=9
|
||||
- 下边界:y=19
|
||||
- 上边界:y=0(方块出生区)
|
||||
4. 场地状态:用二维数组/矩阵记录,`0=空`,`1~7=对应方块类型`(或布尔型`true=有方块`)。
|
||||
|
||||
---
|
||||
|
||||
## 二、方块类型(Tetrominoes)
|
||||
共 **7种标准四连方块**,每种由4个格子组成,固定形状与颜色:
|
||||
- **I型**(直线):`####`
|
||||
- **O型**(正方形):`## / ##`
|
||||
- **T型**:`### / # `
|
||||
- **L型**:`### / #`
|
||||
- **J型**:`### / # `
|
||||
- **S型**:` ## / ## `
|
||||
- **Z型**:`## / ##`
|
||||
|
||||
|
||||
|
||||
### 方块数据结构(开发要点)
|
||||
- 每个方块定义 **4种旋转状态(0°、90°、180°、270°)** 的形状矩阵。
|
||||
- 包含:**形状、颜色、中心点/锚点、旋转偏移**。
|
||||
|
||||
---
|
||||
|
||||
## 三、方块生成与出生规则
|
||||
1. 游戏开始后,从7种方块中 **随机选取一种** 作为当前下落方块。
|
||||
2. 方块出生位置:
|
||||
- 水平居中:I型出生在x=3、y=0;其余在x=4、y=0。
|
||||
- 完全位于场地顶部可见区域外(y<0)或顶部边缘。
|
||||
3. 经典规则:**无“下一个方块预览”**(部分版本可选)。
|
||||
4. 随机机制:**纯随机**(可重复连续同一种方块;现代为“7袋随机”)。
|
||||
|
||||
---
|
||||
|
||||
## 四、玩家操作(经典版)
|
||||
### 1. 左右移动
|
||||
- 按左/右键:方块 **水平移动1格**。
|
||||
- 移动限制:
|
||||
- 不能超出左/右边界(x<0 或 x>9)。
|
||||
- 不能与已固定方块重叠。
|
||||
- 移动后必须完全在有效网格内。
|
||||
|
||||
### 2. 旋转
|
||||
- 按旋转键:**顺时针90°旋转**(经典无逆时针/180°)。
|
||||
- 旋转规则:
|
||||
- 以方块自身中心点为轴旋转。
|
||||
- 旋转后必须 **完全在场地内**、**不与边界/固定方块重叠**。
|
||||
- 经典版 **无踢墙(Wall Kick)**:旋转后位置无效则**不执行旋转**。
|
||||
|
||||
### 3. 下落控制
|
||||
- **自然下落(重力)**:方块以固定速度自动向下1格。
|
||||
- **软降(Soft Drop)**:按住向下键,**加速下落**(得分较低)。
|
||||
- **硬降(Hard Drop)**:经典版**无硬降**(方块直接落地锁定为现代规则)。
|
||||
|
||||
---
|
||||
|
||||
## 五、下落、落地与锁定(Lock)
|
||||
1. 下落判定:每帧/每步检查 **下方一格是否为空**。
|
||||
- 下方为空 → 继续下落。
|
||||
- 下方为边界或固定方块 → **停止下落,进入锁定延迟**。
|
||||
2. 锁定延迟(Lock Delay):经典约 **0.5~1秒**。
|
||||
- 延迟内仍可移动、旋转。
|
||||
- 延迟结束 → 方块**永久固定**到场地,不可再操作。
|
||||
3. 锁定后:立即生成**下一个随机方块**,从顶部出生。
|
||||
|
||||
---
|
||||
|
||||
## 六、消行规则(Line Clear)
|
||||
1. 方块锁定后,**逐行检查**是否有**整行填满(10格全有方块)**。
|
||||
2. 消除规则:
|
||||
- 标记所有满行 → **删除这些行**。
|
||||
- 上方所有行 **整体向下移动**,填补被消除行的空位。
|
||||
- 多行同时消除:**从上到下依次消除、依次下落**。
|
||||
3. 消行类型(经典):
|
||||
- 1行:Single
|
||||
- 2行:Double
|
||||
- 3行:Triple
|
||||
- 4行:Tetris(I型专属,最高分)
|
||||
|
||||
---
|
||||
|
||||
## 七、得分规则(经典版,FC标准)
|
||||
基础分(等级0):
|
||||
- 1行:100分
|
||||
- 2行:300分
|
||||
- 3行:500分
|
||||
- 4行(Tetris):800分
|
||||
|
||||
- 软降:每下落1格 +1分。
|
||||
- **等级加成**:每升1级,得分 × 等级倍数(等级1×1,等级2×2…)。
|
||||
|
||||
---
|
||||
|
||||
## 八、等级与速度(Gravity)
|
||||
1. 初始等级:**Level 0**。
|
||||
2. 升级条件:每消除 **10行** 升1级。
|
||||
3. 速度变化:等级越高,**自然下落间隔越短**(速度越快)。
|
||||
- 经典最高:Level 17~20(速度极限)。
|
||||
|
||||
---
|
||||
|
||||
## 九、游戏结束(Game Over)
|
||||
1. 新方块出生时:**方块的任何一格与场地内已有方块重叠**。
|
||||
2. 方块出生后无法下落(出生即被顶死)。
|
||||
3. 满足任一条件 → 游戏结束,显示最终得分、等级、消行数。
|
||||
|
||||
---
|
||||
|
||||
## 十、其他经典规则(开发必知)
|
||||
1. 方块**不可穿透**已固定方块与边界。
|
||||
2. 消除行**无动画延迟**(或极短)。
|
||||
3. 无**连击(Combo)、T-Spin、全清(Perfect Clear)** 等现代奖励。
|
||||
4. 暂停:可暂停游戏,冻结所有下落与操作。
|
||||
5. 重新开始:游戏结束后可重置场地、分数、等级,重新开局。
|
||||
|
||||
---
|
||||
|
||||
## 开发关键数据结构建议
|
||||
- 场地:`int[20][10]`(y从0~19,x从0~9)。
|
||||
- 当前方块:`shape[4][4]`、`x, y`、`type`、`rotation`。
|
||||
- 计时器:下落计时器、锁定延迟计时器。
|
||||
- 状态机:`INIT`、`PLAYING`、`PAUSED`、`GAME_OVER`。
|
||||
|
||||
Reference in New Issue
Block a user