#!/bin/bash # 俄罗斯方块游戏 - Bash版本 # 使用终端控制序列进行绘制 # 设置终端 stty -echo # 关闭输入回显 tput civis # 隐藏光标 trap "game_over; exit" INT TERM EXIT # 游戏区域大小 width=10 height=20 score=0 level=1 lines_cleared=0 # 定义方块形状 (7种经典形状) # 每种形状有4个旋转状态,每个状态是一个4x4网格的字符串表示 declare -A shapes shapes[0]="0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0" # T形 shapes[1]="1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0" # O形 shapes[2]="0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0" # L形 shapes[3]="0,1,0,0,0,1,0,0,0,1,1,0,0,0,0,0" # J形 shapes[4]="1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0" # S形 shapes[5]="0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0" # Z形 shapes[6]="1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0" # I形 # 颜色定义 colors=("\033[37m" "\033[31m" "\033[32m" "\033[33m" "\033[34m" "\033[35m" "\033[36m") reset_color="\033[0m" # 游戏板 (二维数组模拟) declare -a board for ((i=0; i=0; row--)); do local full=1 for ((col=0; col0; r--)); do for ((c=0; c