/**
* 俄罗斯方块核心逻辑
* 包含:游戏状态管理、方块生成、碰撞检测、行消除、渲染循环
*/
// --- 配置与常量 ---
const COLS = 10;
const ROWS = 20;
const BLOCK_SIZE = 30; // 像素大小,会根据Canvas动态调整,这里作为基准
const COLORS = {
neon: [
null,
'#00f0f0', // I - Cyan
'#0000f0', // J - Blue
'#f0a000', // L - Orange
'#f0f000', // O - Yellow
'#00f000', // S - Green
'#a000f0', // T - Purple
'#f00000' // Z - Red
],
classic: [
null,
'#00FFFF', '#0000FF', '#FFA500', '#FFFF00', '#00FF00', '#800080', '#FF0000'
],
pastel: [
null,
'#A0E7E5', '#B4F8C8', '#FBE7C6', '#FFAEBC', '#D4C4FB', '#F6C6EA', '#FFC3A0'
]
};
// 方块形状定义 (SRS标准)
const SHAPES = [
[],
[[0,0,0,0], [1,1,1,1], [0,0,0,0], [0,0,0,0]], // I
[[2,0,0], [2,2,2], [0,0,0]], // J
[[0,0,3], [3,3,3], [0,0,0]], // L
[[4,4], [4,4]], // O
[[0,5,5], [5,5,0], [0,0,0]], // S
[[0,6,0], [6,6,6], [0,0,0]], // T
[[7,7,0], [0,7,7], [0,0,0]] // Z
];
// --- 游戏状态类 ---
class Game {
constructor() {
this.canvas = document.getElementById('game-canvas');
this.ctx = this.canvas.getContext('2d');
this.nextCanvas = document.getElementById('next-canvas');
this.nextCtx = this.nextCanvas.getContext('2d');
}
// 启动游戏实例
window.onload = () => {
const game = new Game();
};