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0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0)

aBox5_0=(0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0)

aBox6_0=(0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0)
aBox6_1=(0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0)
aBox6_2=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 -1)
aBox6_3=(0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0)

iSumType=7	#方块类型总数
aStyles=(4 4 2 2 2 1 4)	#各个种类方块样式数
iOrigoX=10	#显示起始位置x
iOrigoY=5	#显示起始位置y
iMapWidth=12	#方块宽10
iMapHeight=15   #方块高15
iBox_X=0	#方块位置x
iBox_Y=0	#方块位置y
iScore=0	#分数
iLevel=0	#级别
iScoreEachLevle=2	#每升一级需积累分数

#初始化所有背景方块
for((i = 0;i0;i--))
  do
    aBoxMove[$i]=${aBoxMove[$((i-1))]}
  done
  
  #重新显示方块
  Draw_Box_New
  iBox_X=$((iBox_X+1))
}
 
Move_Down()
#下落一格
{
  local i
  if ! IsBottom	#返回0则表示底部
  then
    Draw_Box_Clear
    iBox_Y=$((iBox_Y+1))
    #画新方块
    Draw_Box_New
  else
  #	把当前方块移到背景 (把方块位置的背景设置为颜色数)(注:0为空)
  for((i=0;i<${#aBoxMove[*]};i++))
  do
    if [ ${aBoxMove[$i]} -eq 1 ];then
      aBoxBg[$((iBox_Y*12+i))]=$iCurrentColor
    fi
  done
    Box_Delete
    Create_Box
  fi
}
  
Move_FallDown()
#直落到底
{
  local i
  Draw_Box_Clear
  for((i=0;i<15;i++))
  do
    if ! IsBottom
    then
      iBox_Y=$((iBox_Y+1))
    else
      break
    fi
  done
  Draw_Box_New
  Move_Down
}

Move_Rotate()
#当前style跳转到下一style ,x位移量根据iBox_X位置决定
{
  local i
  [ ${aStyles[$iCurrentType]} -eq 1 ] && return 0	#只有一种类型的不处理
  [ $iBox_Y -lt 0 ] && return 0 #iBox_Y<0不处理
  sRotateStyle=$(((iCurrentStyle+1)%${aStyles[$iCurrentType]}))
  aBoxRotate=( `eval 'echo ${aBox'$iCurrentType'_'$sRotateStyle'[*]}'` )
  #先根据iBox_X作左右移位处理,把重新赋值aBoxRotate/aBoxMove
  if [ $iBox_X -gt 0 ];then	#右移
    for((i=$((${#aBoxRotate[*]}-2));i>=iBox_X;i--)) #原数组末尾增加了一位数记录起始位置,所以这里要减2
    do
      aBoxRotate[$i]=${aBoxRotate[$((i-iBox_X))]}
    done
    
    for((i=0;i

 

 

 

你可能感兴趣的:(shell)