Chinaunix首页 | 论坛 | 博客
  • 博客访问: 618126
  • 博文数量: 104
  • 博客积分: 1968
  • 博客等级: 上尉
  • 技术积分: 1587
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-01 17:52
文章分类

全部博文(104)

文章存档

2013年(12)

2012年(50)

2011年(42)

分类: Python/Ruby

2011-12-09 08:53:15

今天在论坛上看见个高手用shell写的俄罗斯方块,很强大。贴出来和大家分享下……
 
 
  1. #!/bin/bash
  2. #
  3. # Tetris Game Version 3.0 Beta1
  4. # Developed by YongYe <expertshell@gmail.com>
  5. # 11/01/2011 BeiJing China [Updated 12/5/2011]

  6. box0=(4 30)
  7. box1=(4 30 5 30)
  8. box2=(4 28 4 30 4 32)
  9. box3=(4 28 4 30 5 30)
  10. box4=(4 30 4 32 5 28 5 30)
  11. box5=(4 30 5 28 5 30 5 32)
  12. box6=(4 32 5 28 5 30 5 32)
  13. box7=(4 30 5 30 6 30 7 30)
  14. box8=(4 28 5 28 5 30 5 32)
  15. box9=(4 28 4 30 5 30 5 32)
  16. box10=(4 28 4 30 5 28 5 30)
  17. box11=(4 28 4 32 5 26 5 30 5 34)
  18. box12=(4 30 4 32 5 30 6 28 6 30)
  19. box13=(4 30 5 28 5 30 5 32 6 30)
  20. box14=(4 28 4 32 5 30 6 28 6 32)
  21. box15=(4 28 4 30 5 30 6 30 6 32)
  22. box16=(4 28 4 32 5 28 5 30 5 32)
  23. box17=(4 28 5 28 6 28 6 30 6 32)
  24. box18=(4 28 4 30 5 30 5 32 6 32)
  25. box19=(4 26 4 34 5 28 5 30 5 32)
  26. box20=(4 26 4 34 5 28 5 32 6 30)
  27. box21=(4 26 5 28 6 30 7 32 8 34)
  28. box22=(4 26 4 28 4 30 4 32 4 34)
  29. box23=(4 28 4 34 5 30 5 32 6 30 6 32 7 28 7 34)
  30. box24=(4 30 5 28 5 32 6 26 6 30 6 34 7 28 7 32 8 30)
  31. box25=(4 30 5 28 5 30 5 32 6 26 6 28 6 30 6 32 6 34 7 28 7 30 7 32 8 30)
  32. box26=(4 26 4 28 4 30 4 34 5 30 5 34 6 26 6 28 6 30 6 32 6 34 7 26 7 30 8 26 8 30 8 32 8 34)
  33. box27=(4 26 4 30 4 32 4 34 5 26 5 30 6 26 6 28 6 30 6 32 6 34 7 30 7 34 8 26 8 28 8 30 8 34)

  34. mrx=[]
  35. modh=3
  36. modw=5
  37. score=0
  38. level=0
  39. width=25
  40. height=30
  41. sigExit=30
  42. sigLeft=26
  43. sigDown=28
  44. sigRight=27
  45. sigRotate=25
  46. sigAllDown=29
  47. ((hh=2*width+modw+6))
  48. coltab=(1\;{30..37}\;{40..47}m)

  49. corev(){ echo $?; }
  50. srann(){ box=(${!1}); }
  51. rotxy(){ kbox="${sup}"; }
  52. srbox(){ vor=($(ordxy ${1})); }
  53. rsmap(){ ((map[u/2-modh]=0)); }
  54. radom(){ echo -n $((RANDOM/1171)); }
  55. racol(){ echo -n ${coltab[RANDOM/512]}; }
  56. hmowh(){ echo -ne "\e[${i};$((modw+1))H"; }
  57. check(){ (( map[(i-modh-1)*width+j/2-modh] == 0 )) && break; }
  58. hdbox(){ echo -e "$(sed 's/\[\]/ /g' <(echo ${oldbox}))\e[0m"; }

  59. infra()
  60. {
  61.    stty ${STTY}
  62.    echo -e "\e[?25h\e[36;4H"
  63. }

  64. ptbox()
  65. {
  66.    oldbox="${cdn}"
  67.    echo -e "\e[${colbox}${cdn}\e[0m"
  68. }

  69. regxy()
  70. {
  71.    ptbox
  72.    locus="${sup}"
  73. }

  74. getxy()
  75. {
  76.    [[ ${cdx} ]] && ((y=cy+(ccy-cdy)${2}2))
  77.    eval ${1}+=\"${x} ${y} \"
  78. }

  79. pause()
  80. {
  81.    if (( ${2} == 0 )); then
  82.          kill -s STOP ${1}
  83.    else
  84.          kill -s CONT ${1}
  85.    fi
  86. }

  87. Quit()
  88. {
  89.    case $# in
  90.         0) echo -e "\e[?25h\e[36;25HGame Over!\e[0m" ;;
  91.         1) kill -${sigExit} ${pid}
  92.            infra ;;
  93.         2) infra ;;
  94.    esac
  95.            exit
  96. }

  97. rmaxy()
  98. {
  99.    awk '{
  100.           for(m=2; m<=NF; m+=2)
  101.              a[m/2-1]=$m
  102.         }
  103.    END {
  104.           for(i=0; i<=NF/2-1; ++i)
  105.           { for(j=i+1; j<=NF/2-1; ++j)
  106.              { if(a[i] > a[j])
  107.                 { v=a[i]
  108.                    a[i]=a[j]
  109.                    a[j]=v
  110.                 }
  111.              }
  112.           }
  113.           {
  114.              for(n in a)
  115.                 print a[n]
  116.           }
  117.         }' <(echo ${box[@]})
  118. }

  119. ordxy()
  120. {
  121.    awk '{
  122.           for(m=2; m<=NF; m+=2)
  123.           { y[m/2-1]=$m
  124.              x[m/2-1]=$(m-1)
  125.           }
  126.         }
  127.    END {
  128.           for(i=0; i<=NF/2-1; ++i)
  129.           { for(j=i+1; j<=NF/2-1; ++j)
  130.              { if(x[i] > x[j])
  131.                 { v=x[i]
  132.                    x[i]=x[j]
  133.                    x[j]=v
  134.                    k=y[i]
  135.                    y[i]=y[j]
  136.                    y[j]=k
  137.                 }
  138.              }
  139.           }
  140.           {
  141.              for(n in x)
  142.                 print x[n], y[n]
  143.           }
  144.         }' <(echo ${!1})
  145. }

  146. rmaxx()
  147. {
  148.    awk -v k=${i} '{
  149.           for(m=1; m<=NF; m+=2)
  150.           { if($(m+1)==k)
  151.              { if(q<$m)
  152.                  q=$m
  153.              }
  154.           }
  155.         }
  156.    END {
  157.              print q
  158.         }' <(echo ${box[@]})
  159. }

  160. initl()
  161. {
  162.    local rsyx
  163.    ((rsyx=(i-modh-1)*width+j/2-modh))
  164.    ((map[rsyx]=0))
  165.    ((pam[rsyx]=0))
  166. }

  167. rtmrx()
  168. {
  169.    local rsxy
  170.    ((rsxy=(i-modh-1)*width+j/2-modh))
  171.    if (( map[rsxy] == 0 )); then
  172.          echo -ne " "
  173.    else
  174.          echo -ne "\e[${pam[rsxy]}${mrx}\e[0m"
  175.    fi
  176. }

  177. srmap()
  178. {
  179.    local srx sry
  180.    ((srx=(j-modh)*width+u/2-modh))
  181.    ((sry=(j-modh-1)*width+u/2-modh))
  182.    ((map[srx]=map[sry]))
  183.    eval pam[srx]=\"${pam[sry]}\"
  184. }

  185. LOOP()
  186. {
  187.    local i j
  188.    for((i=modh+1; i<=height+modh; ++i))
  189.    do
  190.         ${1}
  191.         for((j=modw+1; j<=2*(width-1)+modw+1; j+=2))
  192.         do
  193.              ${2}
  194.         done
  195.         ${3}
  196.    done
  197. }

  198. Loop()
  199. {
  200.    local u
  201.    for((u=modw+1; u<=2*(width-1)+modw+1; u+=2))
  202.    do
  203.           ${1}
  204.    done
  205. }

  206. mapbox()
  207. {
  208.    (( j <= 2*(width-1)+modw+1 )) && continue
  209.    ((++line))
  210.    for((j=i-1; j>=modh+1; --j))
  211.    do
  212.          Loop srmap
  213.    done
  214.          Loop rsmap
  215. }

  216. rscbox()
  217. {
  218.    srbox ${1}
  219.    for((i=0; i<${#vor[@]}; i+=2))
  220.    do
  221.        (( ${3} >= 0 )) && ((clo=vor[i+1]+hh-${3})) || ((clo=vor[i+1]+hh+12))
  222.        smobox+="\e[$((vor[i]-1));${clo}H${mrx}"
  223.    done
  224.    echo -e "$(sed 's/\[\]/ /g' <(echo ${!2}))\e[${!4}${smobox}\e[0m"
  225. }

  226. mrbox()
  227. {
  228.    smobox=
  229.    (( ${5} != 0 )) && {
  230.    srann box$(radom)[@]
  231.    eval ${1}="(${box[@]})"
  232.    colbox="$(racol)"
  233.    eval ${6}=\"${colbox}\"
  234.    rscbox box[@] ${3} ${4} colbox
  235.    } || {
  236.    eval ${1}="(${!2})"
  237.    eval ${6}=\"${!7}\"
  238.    rscbox ${2} ${3} ${4} ${7}
  239.    }
  240.    eval ${3}=\"${smobox}\"
  241. }

  242. ranbox()
  243. {
  244.    local value smobox clo i j
  245.    colbox="${cnewbox}"
  246.    cLorbox="${cTorbox}"
  247.    olbox=(${newbox[@]})
  248.    Lorbox=(${Torbox[@]})
  249.    mrbox newbox Lorbox[@] srcbox 24 ${#} cnewbox cLorbox
  250.    mrbox Torbox rosbox[@] scrbox 12 ${#} cTorbox crosbox
  251.    mrbox rosbox rcsbox[@] csrbox 0 ${#} crosbox crcsbox
  252.    smobox=
  253.    srann box$(radom)[@]
  254.    rcsbox=(${box[@]})
  255.    crcsbox="$(racol)"
  256.    rscbox box[@] crsbox -12 crcsbox
  257.    crsbox="${smobox}"
  258.    box=(${olbox[@]})
  259. }

  260. danbox()
  261. {
  262.    (( $# == 1 )) && {
  263.         srann box$(radom)[@]
  264.         colbox="$(racol)"
  265.         concxy box[@] regxy
  266.    } || {
  267.    colbox="${cnewbox}"
  268.    concxy newbox[@] regxy
  269.    }
  270.    oldbox="${cdn}"
  271.    if ! movebox locus; then
  272.       kill -${sigExit} ${PPID}
  273.       Quit
  274.    fi
  275. }

  276. hrabox()
  277. {
  278.    local j x y p q yox line sum mus calcu scn
  279.    sbos="\040\040"
  280.    sum=$(awk '{print NF}' <(echo ${locus}))
  281.    calcu=(x y x y-2 x y-4 x y+2 x y+4 x+1 y x+1 y-2 x+1 y+2)
  282.    srbox locus
  283.    for((i=0; i<${#vor[@]}; i+=2))
  284.    do
  285.        ((x=vor[i]))
  286.        ((y=vor[i+1]))
  287.        ((yox=(x-modh-1)*width+y/2-modh))
  288.        if (( sum == 16 )); then
  289.              scn=
  290.              for((j=0; j<${#calcu[@]}; j+=2))
  291.              do
  292.                      ((p=calcu[j]))
  293.                      ((q=calcu[j+1]))
  294.                      ((mus=(p-modh-1)*width+q/2-modh))
  295.                   if (( p > modh && p <= height+modh && q <= 2*width+modw && q > modw )); then
  296.                      scn+="\e[${p};${q}H${sbos}"
  297.                      ((map[mus]=0))
  298.                      ((pam[mus]=0))
  299.                   fi
  300.              done
  301.              sleep 0.03
  302.              echo -e "${scn}"
  303.        else
  304.              ((map[yox]=1))
  305.              pam[yox]="${colbox}"
  306.        fi
  307.    done
  308.    line=0
  309.    LOOP "" check mapbox
  310.    (( line == 0 )) && return
  311.    echo -e "\e[1;34m\e[$((modh+6));${hh}H$((score+=line*200-100))"
  312.    (( score%5000 < line*200-100 && level < 20 )) && echo -e "\e[1;34m\e[$((modh+8));${hh}H$((++level))"
  313.    echo -e "\e[0m"
  314.    LOOP hmowh rtmrx
  315. }

  316. persig()
  317. {
  318.    local sigSwap
  319.    ranbox 0
  320.    danbox 0
  321.    for i in sigRotate sigLeft sigRight sigDown sigAllDown
  322.    do
  323.         trap "sig=${!i}" ${!i}
  324.    done
  325.    trap "Quit" ${sigExit}
  326.    while :
  327.    do
  328.        for ((i=0; i<20-level; ++i))
  329.        do
  330.             sleep 0.02
  331.             sigSwap=${sig}
  332.             sig=0
  333.             case ${sigSwap} in
  334.             ${sigRotate} ) transform ;;
  335.             ${sigLeft} ) transform 0 -2 ;;
  336.             ${sigRight} ) transform 0 2 ;;
  337.             ${sigDown} ) transform 1 0 ;;
  338.             ${sigAllDown})
  339.             transform $(corev $(dropa)) 0 ;;
  340.             esac
  341.        done
  342.        transform 1 0
  343.    done
  344. }

  345. getsig()
  346. {
  347.    local pid key arry pool STTY sig
  348.    pid=${1}
  349.    arry=(0 0 0)
  350.    pool=$(echo -ne "\e")
  351.    STTY=$(stty -g)
  352.    trap "Quit 0" INT TERM
  353.    trap "Quit 0 0" ${sigExit}
  354.    echo -ne "\e[?25l"
  355.    while :
  356.    do
  357.            read -s -n 1 key
  358.            arry[0]=${arry[1]}
  359.            arry[1]=${arry[2]}
  360.            arry[2]=${key}
  361.            sig=0
  362.            if [[ ${key} == ${pool} && ${arry[1]} == ${pool} ]];then Quit 0
  363.            elif [[ "[${key}]" == ${mrx} ]]; then sig=${sigAllDown}
  364.            elif [[ ${arry[0]} == ${pool} && ${arry[1]} == "[" ]]; then
  365.                      case ${key} in
  366.                      A) sig=${sigRotate} ;;
  367.                      B) sig=${sigDown} ;;
  368.                      D) sig=${sigLeft} ;;
  369.                      C) sig=${sigRight} ;;
  370.                      esac
  371.            else
  372.                     case ${key} in
  373.                      W|w) sig=${sigRotate} ;;
  374.                      S|s) sig=${sigDown} ;;
  375.                      A|a) sig=${sigLeft} ;;
  376.                      D|d) sig=${sigRight} ;;
  377.                      P|p) pause ${pid} 0 ;;
  378.                      R|r) pause ${pid} 1 ;;
  379.                      Q|q) Quit 0 ;;
  380.                      esac
  381.            fi
  382.                      (( sig != 0 )) && kill -${sig} ${pid}
  383.    done
  384. }

  385. dropa()
  386. {
  387.    local cmax cury i j k
  388.    cury=($(rmaxy))
  389.    for i in ${cury[@]}
  390.    do
  391.         cmax+="$(rmaxx) "
  392.    done
  393.    cmax=(${cmax})
  394.    for((i=0; i<height; ++i))
  395.    do
  396.        for((j=0; j<${#cmax[@]}; ++j))
  397.        do
  398.            (( map[(cmax[j]+i-modh)*width+cury[j]/2-modh] == 1 || cmax[j]+i == height+modh )) && return ${i}
  399.        done
  400.    done
  401. }

  402. movebox()
  403. {
  404.    local x y i j xoy
  405.    srbox ${1}
  406.    ((smu=${#vor[@]}))
  407.    for((i=0; i<${#vor[@]}; i+=2))
  408.    do
  409.         ((x=vor[i]+dx))
  410.         ((y=vor[i+1]+dy))
  411.         ((xoy=(x-modh-1)*width+y/2-modh))
  412.         (( xoy < 0 )) && return 1
  413.         (( x <= modh || x > height+modh || y > 2*width+modw || y <= modw )) && return 1
  414.             if (( map[xoy] == 1 )); then
  415.                if (( smu == 2 )); then
  416.                   for((j=height+modh; j>x; --j))
  417.                   do
  418.                         (( map[(j-modh-1)*width+y/2-modh] == 0 )) && return 0
  419.                   done
  420.                fi
  421.                return 1
  422.             fi
  423.    done
  424.    return 0
  425. }

  426. across()
  427. {
  428.    local i j m one
  429.    one=(${locus})
  430.    ((i=one[0]))
  431.    ((j=one[1]))
  432.    ((m=(i-modh-1)*width+j/2-modh))
  433.    (( map[m] == 1 )) && echo -e "\e[${i};${j}H\e[${pam[m]}${mrx}\e[0m"
  434. }

  435. concxy()
  436. {
  437.    local i sup
  438.    srbox ${1}
  439.    for((i=0; i<${#vor[@]}; i+=2))
  440.    do
  441.        cdn+="\e[${vor[i]};${vor[i+1]}H${mrx}"
  442.        sup+="${vor[i]} ${vor[i+1]} "
  443.    done
  444.    ${2}
  445. }

  446. move()
  447. {
  448.    if movebox locus; then
  449.         hdbox
  450.         (( smu == 2 )) && across
  451.         drbox
  452.    else
  453.         (( dx == 1 )) && {
  454.         hrabox
  455.         danbox
  456.         ranbox
  457.         }
  458.    fi
  459. }

  460. drbox()
  461. {
  462.    local v
  463.    for((v=0; v<${#box[@]}; v+=2))
  464.    do
  465.       ((box[v]+=dx))
  466.       ((box[v+1]+=dy))
  467.    done
  468.    nbox=(${box[@]})
  469.    concxy box[@] regxy
  470.    box=(${nbox[@]})
  471. }

  472. getmn()
  473. {
  474.    BOX=(${!1})
  475.    if (( ${#BOX[@]}%4 == 0 )); then
  476.         ((${2}=BOX[${#BOX[@]}/2]))
  477.         ((${3}=BOX[${#BOX[@]}/2+1]))
  478.    else
  479.         ((${3}=BOX[${#BOX[@]}/2]))
  480.         ((${2}=BOX[${#BOX[@]}/2-1]))
  481.    fi
  482. }

  483. loop()
  484. {
  485.    local x y cy ccx ccy cdx cdy
  486.    srbox ${1}
  487.    for((i=0; i<${#vor[@]}; i+=2))
  488.    do
  489.        ((x=vor[i]))
  490.        ((y=vor[i+1]))
  491.        ((ccx=x))
  492.        ((ccy=y))
  493.        ${2} ${3} "${4}"
  494.        ((cy=y))
  495.        ((cdx=ccx))
  496.        ((cdy=ccy))
  497.    done
  498. }

  499. algo()
  500. {
  501.    local row col
  502.    srbox ${1}
  503.    for((i=0; i<${#vor[@]}; i+=2))
  504.    do
  505.        ((col=m-vor[i]+n))
  506.        ((row=m+vor[i+1]-n))
  507.        mbox+="${row} ${col} "
  508.    done
  509. }

  510. sortxy()
  511. {
  512.    srbox ${1}
  513.    for((i=0; i<${#vor[@]}; i+=2))
  514.    do
  515.        pbox+="${vor[i]} ${vor[i+1]} "
  516.    done
  517. }

  518. plusxy()
  519. {
  520.    local i
  521.    for((i=0; i<${#pbox[@]}; i+=2))
  522.    do
  523.        ((pbox[i]+=mp-p))
  524.        ((pbox[i+1]+=nq-q))
  525.    done
  526. }

  527. rotate()
  528. {
  529.    local m n p q mp nq tbox mbox vbox kbox pbox
  530.    getmn box[@] mp nq
  531.    loop box[@] getxy vbox "/"
  532.    vbox=(${vbox})
  533.    getmn vbox[@] m n
  534.    algo vbox[@]
  535.    mbox=(${mbox})
  536.    loop mbox[@] getxy tbox "*"
  537.    tbox=(${tbox})
  538.    sortxy tbox[@]
  539.    pbox=(${pbox})
  540.    getmn pbox[@] p q
  541.    plusxy
  542.    concxy pbox[@] rotxy
  543.    if movebox kbox; then
  544.        hdbox
  545.        locus="${kbox}"
  546.        ptbox
  547.        box=(${kbox})
  548.    else
  549.        echo -e "\e[${colbox}${oldbox}\e[0m"
  550.    fi
  551. }

  552. transform()
  553. {
  554.    local dx dy cdn vor smu
  555.    dx=${1}
  556.    dy=${2}
  557.    (( $# != 0 )) && move || rotate
  558. }

  559. matrix()
  560. {
  561.    one=" "
  562.    sr="\e[0m"
  563.    two="${one}${one}"
  564.    tre="${one}${two}"
  565.    cps="${two}${tre}"
  566.    spc="${cps}${cps}"
  567.    colbon="\e[1;36;44m"
  568.    mcol="\e[32;40;1m"
  569.    trx="${mrx}${mrx}"
  570.    fk0="${colbon}${mrx}${sr}"
  571.    fk1="${colbon}${trx}${sr}"
  572.    fk2="${colbon}${mrx}${trx}${sr}"
  573.    fk3="${colbon}${trx}${trx}${sr}"
  574.    fk4="${mcol}${mrx}${sr}"
  575.    fk5="${spc}${spc}"
  576.    fk6="${mcol}${mrx}${trx}${sr}"
  577.    fk="${tre}${fk0}${two}${fk3}${two}${fk3}"
  578.    fk7="${fk1}${one}${fk1}${fk}${fk4}${two}${two}"
  579.    fk8="${fk0}${one}row${one}${fk0}${tre}${fk0}${two}${fk0}${one}(x-m)/zoomx${two}"
  580.    fk9="${one}=${one}${fk0}${two}${fk0}${spc}${tre}${one}${fk0}${tre}*${two}"
  581.    fk10="${spc}${cps}${two}${fk0}${two}${fk0}${one}+${one}${fk0}${cps}${fk0}"
  582.    fk11="${tre}${one}${fk0}${two}cos(a)${one}sin(a)${two}${fk0}${two}${fk0}${tre}${fk0}${two}m${two}${fk0}"
  583.    fk12="${one}col${one}${fk0}${tre}${fk0}${two}${fk0}${one}(y-n)/zoomy${two}${fk0}${cps}${one}"
  584.    fk13="${one}-sin(a)${one}cos(a)${two}${fk0}${two}${fk0}${tre}${fk0}${two}n${two}${fk0}"
  585.    fk14="${fk1}${one}${fk1}${fk}${cps}${one}"
  586.    fk15="${fk1}${two}${fk0}${tre}${fk1}${one}${fk1}"
  587.    echo -e "\e[$((modh+23));${hh}HAlgorithm:${two}${fk2}${one}${fk5}${fk5}${fk2}${fk4}"
  588.    echo -e "\e[$((modh+30));${hh}H${spc}${two}${fk0}${two}${two}${cps}${fk5}${fk5}${fk0}"
  589.    echo -e "\e[$((modh+25));${hh}H${fk7}${fk1}${spc}${tre}${fk1}${two}${fk0}${tre}${fk1}${one}${fk1}"
  590.    echo -e "\e[$((modh+26));${hh}H${fk8}${fk0}${fk4}${fk11}\e[$((modh+28));${hh}H${fk0}${fk12}${fk0}${fk13}"
  591.    echo -e "\e[$((modh+24));${hh}H${two}${spc}${fk0}${spc}${tre}${two}${tre}${fk6}${fk5}${cps}${fk0}${fk4}"
  592.    echo -e "\e[$((modh+22));${hh}H${tre}${fk5}${fk5}${fk5}${fk6}\e[$((modh+29));${hh}H${fk14}${fk1}${spc}${tre}${fk15}"
  593.    echo -e "\e[$((modh+27));${hh}H${fk0}${cps}${fk0}${fk9}${fk0}${fk10}\e[$((modh+31));${hh}H${spc}${two}${fk2}${fk5}${fk5} ${fk2}"
  594. }

  595. bondary()
  596. {
  597.    clear
  598.    boncol="\e[1;30;1;44m\e[7m"
  599.    for((i=modw+1; i<=2*width+modw; i+=2))
  600.    do
  601.         echo -e "${boncol}\e[${modh};${i}H==\e[$((height+modh+1));${i}H==\e[0m"
  602.    done
  603.    for((i=modh; i<=height+modh+1; ++i))
  604.    do
  605.         echo -e "${boncol}\e[${i};$((modw-1))H||\e[${i};$((2*width+modw+1))H||\e[0m"
  606.    done
  607. }

  608. rinfo()
  609. {
  610.    echo -e "\e[1;31m\e[$((modh+5));${hh}HScore\e[1;31m\e[$((modh+7));${hh}HLevel\e[0m"
  611.    echo -e "\e[1;34m\e[$((modh+6));${hh}H${score}\e[1;34m\e[$((modh+8));${hh}H${level}\e[0m"
  612.    echo -e "\e[$((modh+10));${hh}HQ|q|ESC === exit"
  613.    echo -e "\e[$((modh+11));${hh}HP|p === pause\e[$((modh+12));${hh}HR|r === resume"
  614.    echo -e "\e[$((modh+13));${hh}HW|w|up === rotate\e[$((modh+14));${hh}HS|s|down === one step down"
  615.    echo -e "\e[$((modh+15));${hh}HA|a|left === one step left\e[$((modh+16));${hh}HD|d|right === one step right"
  616.    echo -e "\e[$((modh+17));${hh}HSpace|enter === drop all down\e[1;36m\e[$((modh+19));${hh}HTetris Game Version 3.0 Beta1"
  617.    echo -e "\e[$((modh+20));${hh}HYongYe \e[$((modh+21));${hh}H11/01/2011 BeiJing China [Updated 12/5/2011]"
  618. }

  619.    [[ "[${1}]" != ${mrx} ]] && {
  620.        LOOP "" initl ""
  621.        bondary
  622.        rinfo
  623.        matrix
  624.        persig
  625.    } || {
  626.        bash $0 0 &
  627.        getsig $!
  628.    }
 
 
 
代码已经很健壮了!
特性:
1.支持炸弹特效(ID=23)!
2.支持方块暂停/恢复特效!
3.支持单方块夸区域移动(ID=0)!
4.支持方块的多颜色显示(64种颜色随机选择)!
5.支持方块按给定坐标区间设定值的任意定制!
6.支持方块的四级预览(可预览随机生成的下四个方块)!
Fedora-16-x86_64下Gnome终端截图:
1.jpg
2.jpg
3.jpg
核心算法的矩阵方程:
Matrix.jpg
郑重声明:该脚本为本人原创脚本,其算法、思想及所有代码均为本人独立设计、开发完成,你可以任意修改、拓展、发布,但请保留原作者出处(也即我,永夜),在此,我对你的支持表示感谢!
持续更新!


微分了忧伤,积分了希望,我要和你一起追逐黎曼最初的梦想……

                 ---永夜
 
 
原文地址:
阅读(2034) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

houisgod2013-10-17 00:39:31

这么长的代码写个注释会死啊