<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[shell版俄罗斯方块]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 05 Nov 2008 09:40:50 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<br/><div class="code">#!/bin/bash<br/># Tetris Game<br/># 10.21.2003 xhchen<br/><br/>#颜色定义<br/>cRed=1<br/>cGreen=2<br/>cYellow=3<br/>cBlue=4<br/>cFuchsia=5<br/>cCyan=6<br/>cWhite=7<br/>colorTable=($cRed $cGreen $cYellow $cBlue $cFuchsia $cCyan $cWhite)<br/><br/>#位置和大小<br/>iLeft=3<br/>iTop=2<br/>((iTrayLeft = iLeft + 2))<br/>((iTrayTop = iTop + 1))<br/>((iTrayWidth = 10))<br/>((iTrayHeight = 15))<br/><br/>#颜色设置<br/>cBorder=$cGreen<br/>cScore=$cFuchsia<br/>cScoreValue=$cCyan<br/><br/>#控制信号<br/>#改游戏使用两个进程，一个用于接收输入，一个用于游戏流程和显示界面;<br/>#当前者接收到上下左右等按键时，通过向后者发送signal的方式通知后者。<br/>sigRotate=25<br/>sigLeft=26<br/>sigRight=27<br/>sigDown=28<br/>sigAllDown=29<br/>sigExit=30<br/><br/>#七中不同的方块的定义<br/>#通过旋转，每种方块的显示的样式可能有几种<br/>box0=(0 0 0 1 1 0 1 1)<br/>box1=(0 2 1 2 2 2 3 2 1 0 1 1 1 2 1 3)<br/>box2=(0 0 0 1 1 1 1 2 0 1 1 0 1 1 2 0)<br/>box3=(0 1 0 2 1 0 1 1 0 0 1 0 1 1 2 1)<br/>box4=(0 1 0 2 1 1 2 1 1 0 1 1 1 2 2 2 0 1 1 1 2 0 2 1 0 0 1 0 1 1 1 2)<br/>box5=(0 1 1 1 2 1 2 2 1 0 1 1 1 2 2 0 0 0 0 1 1 1 2 1 0 2 1 0 1 1 1 2)<br/>box6=(0 1 1 1 1 2 2 1 1 0 1 1 1 2 2 1 0 1 1 0 1 1 2 1 0 1 1 0 1 1 1 2)<br/>#所有其中方块的定义都放到box变量中<br/>box=($&#123;box0&#91;@&#93;&#125; $&#123;box1&#91;@&#93;&#125; $&#123;box2&#91;@&#93;&#125; $&#123;box3&#91;@&#93;&#125; $&#123;box4&#91;@&#93;&#125; $&#123;box5&#91;@&#93;&#125; $&#123;box6&#91;@&#93;&#125;)<br/>#各种方块旋转后可能的样式数目<br/>countBox=(1 2 2 2 4 4 4)<br/>#各种方块再box数组中的偏移<br/>offsetBox=(0 1 3 5 7 11 15)<br/><br/>#每提高一个速度级需要积累的分数<br/>iScoreEachLevel=50 #be greater than 7<br/><br/>#运行时数据<br/>sig=0 #接收到的signal<br/>iScore=0 #总分<br/>iLevel=0 #速度级<br/>boxNew=() #新下落的方块的位置定义<br/>cBoxNew=0 #新下落的方块的颜色<br/>iBoxNewType=0 #新下落的方块的种类<br/>iBoxNewRotate=0 #新下落的方块的旋转角度<br/>boxCur=() #当前方块的位置定义<br/>cBoxCur=0 #当前方块的颜色<br/>iBoxCurType=0 #当前方块的种类<br/>iBoxCurRotate=0 #当前方块的旋转角度<br/>boxCurX=-1 #当前方块的x坐标位置<br/>boxCurY=-1 #当前方块的y坐标位置<br/>iMap=() #背景方块图表<br/><br/>#初始化所有背景方块为-1, 表示没有方块<br/>for ((i = 0; i &lt; iTrayHeight * iTrayWidth; i++)); do iMap&#91;$i&#93;=-1; done<br/><br/><br/>#接收输入的进程的主函数<br/>function RunAsKeyReceiver()<br/>&#123;<br/>local pidDisplayer key aKey sig cESC sTTY<br/><br/>pidDisplayer=$1<br/>aKey=(0 0 0)<br/><br/>cESC=`echo -ne &quot;&#92;33&quot;`<br/>cSpace=`echo -ne &quot;&#92;40&quot;`<br/><br/>#保存终端属性。在read -s读取终端键时，终端的属性会被暂时改变。<br/>#如果在read -s时程序被不幸杀掉，可能会导致终端混乱，<br/>#需要在程序退出时恢复终端属性。<br/>sTTY=`stty -g`<br/><br/>#捕捉退出信号<br/>trap &quot;MyExit;&quot; INT TERM<br/>trap &quot;MyExitNoSub;&quot; $sigExit<br/><br/>#隐藏光标<br/>echo -ne &quot;&#92;33&#91;?25l&quot;<br/><br/><br/>while (( 1 ))<br/>do<br/>#读取输入。注-s不回显，-n读到一个字符立即返回<br/>read -s -n 1 key<br/><br/>aKey&#91;0&#93;=$&#123;aKey&#91;1&#93;&#125;<br/>aKey&#91;1&#93;=$&#123;aKey&#91;2&#93;&#125;<br/>aKey&#91;2&#93;=$key<br/>sig=0<br/><br/>#判断输入了何种键<br/>if &#91;&#91; $key == $cESC &amp;&amp; $&#123;aKey&#91;1&#93;&#125; == $cESC &#93;&#93;<br/>then<br/>#ESC键<br/>MyExit<br/>elif &#91;&#91; $&#123;aKey&#91;0&#93;&#125; == $cESC &amp;&amp; $&#123;aKey&#91;1&#93;&#125; == &quot;&#91;&quot; &#93;&#93;<br/>then<br/>if &#91;&#91; $key == &quot;A&quot; &#93;&#93;; then sig=$sigRotate #&lt;向上键&gt;<br/>elif &#91;&#91; $key == &quot;B&quot; &#93;&#93;; then sig=$sigDown #&lt;向下键&gt;<br/>elif &#91;&#91; $key == &quot;D&quot; &#93;&#93;; then sig=$sigLeft #&lt;向左键&gt;<br/>elif &#91;&#91; $key == &quot;C&quot; &#93;&#93;; then sig=$sigRight #&lt;向右键&gt;<br/>fi<br/>elif &#91;&#91; $key == &quot;W&quot; &#124;&#124; $key == &quot;w&quot; &#93;&#93;; then sig=$sigRotate #W, w<br/>elif &#91;&#91; $key == &quot;S&quot; &#124;&#124; $key == &quot;s&quot; &#93;&#93;; then sig=$sigDown #S, s<br/>elif &#91;&#91; $key == &quot;A&quot; &#124;&#124; $key == &quot;a&quot; &#93;&#93;; then sig=$sigLeft #A, a<br/>elif &#91;&#91; $key == &quot;D&quot; &#124;&#124; $key == &quot;d&quot; &#93;&#93;; then sig=$sigRight #D, d<br/>elif &#91;&#91; &quot;&#91;$key&#93;&quot; == &quot;&#91;&#93;&quot; &#93;&#93;; then sig=$sigAllDown #空格键<br/>elif &#91;&#91; $key == &quot;Q&quot; &#124;&#124; $key == &quot;q&quot; &#93;&#93; #Q, q<br/>then<br/>MyExit<br/>fi<br/><br/>if &#91;&#91; $sig != 0 &#93;&#93;<br/>then<br/>#向另一进程发送消息<br/>kill -$sig $pidDisplayer<br/>fi<br/>done<br/>&#125;<br/><br/>#退出前的恢复<br/>function MyExitNoSub()<br/>&#123;<br/>local y<br/><br/>#恢复终端属性<br/>stty $sTTY<br/>((y = iTop + iTrayHeight + 4))<br/><br/>#显示光标<br/>echo -e &quot;&#92;33&#91;?25h&#92;33&#91;$&#123;y&#125;;0H&quot;<br/>exit<br/>&#125;<br/><br/><br/>function MyExit()<br/>&#123;<br/>#通知显示进程需要退出<br/>kill -$sigExit $pidDisplayer<br/><br/>MyExitNoSub<br/>&#125;<br/><br/><br/>#处理显示和游戏流程的主函数<br/>function RunAsDisplayer()<br/>&#123;<br/>local sigThis<br/>InitDraw<br/><br/>#挂载各种信号的处理函数<br/>trap &quot;sig=$sigRotate;&quot; $sigRotate<br/>trap &quot;sig=$sigLeft;&quot; $sigLeft<br/>trap &quot;sig=$sigRight;&quot; $sigRight<br/>trap &quot;sig=$sigDown;&quot; $sigDown<br/>trap &quot;sig=$sigAllDown;&quot; $sigAllDown<br/>trap &quot;ShowExit;&quot; $sigExit<br/><br/>while (( 1 ))<br/>do<br/>#根据当前的速度级iLevel不同，设定相应的循环的次数<br/>for ((i = 0; i &lt; 21 - iLevel; i++))<br/>do<br/>sleep 0.02<br/>sigThis=$sig<br/>sig=0<br/><br/>#根据sig变量判断是否接受到相应的信号<br/>if ((sigThis == sigRotate)); then BoxRotate; #旋转<br/>elif ((sigThis == sigLeft)); then BoxLeft; #左移一列<br/>elif ((sigThis == sigRight)); then BoxRight; #右移一列<br/>elif ((sigThis == sigDown)); then BoxDown; #下落一行<br/>elif ((sigThis == sigAllDown)); then BoxAllDown; #下落到底<br/>fi<br/>done<br/>#kill -$sigDown $$<br/>BoxDown #下落一行<br/>done<br/>&#125;<br/><br/><br/>#BoxMove(y, x), 测试是否可以把移动中的方块移到(x, y)的位置, 返回0则可以, 1不可以<br/>function BoxMove()<br/>&#123;<br/>local j i x y xTest yTest<br/>yTest=$1<br/>xTest=$2<br/>for ((j = 0; j &lt; 8; j += 2))<br/>do<br/>((i = j + 1))<br/>((y = $&#123;boxCur&#91;$j&#93;&#125; + yTest))<br/>((x = $&#123;boxCur&#91;$i&#93;&#125; + xTest))<br/>if (( y &lt; 0 &#124;&#124; y &gt;= iTrayHeight &#124;&#124; x &lt; 0 &#124;&#124; x &gt;= iTrayWidth))<br/>then<br/>#撞到墙壁了<br/>return 1<br/>fi<br/>if (($&#123;iMap&#91;y * iTrayWidth + x&#93;&#125; != -1 ))<br/>then<br/>#撞到其他已经存在的方块了<br/>return 1<br/>fi<br/>done<br/>return 0;<br/>&#125;<br/><br/><br/>#将当前移动中的方块放到背景方块中去,<br/>#并计算新的分数和速度级。(即一次方块落到底部)<br/>function Box2Map()<br/>&#123;<br/>local j i x y xp yp line<br/><br/>#将当前移动中的方块放到背景方块中去<br/>for ((j = 0; j &lt; 8; j += 2))<br/>do<br/>((i = j + 1))<br/>((y = $&#123;boxCur&#91;$j&#93;&#125; + boxCurY))<br/>((x = $&#123;boxCur&#91;$i&#93;&#125; + boxCurX))<br/>((i = y * iTrayWidth + x))<br/>iMap&#91;$i&#93;=$cBoxCur<br/>done<br/><br/>#消去可被消去的行<br/>line=0<br/>for ((j = 0; j &lt; iTrayWidth * iTrayHeight; j += iTrayWidth))<br/>do<br/>for ((i = j + iTrayWidth - 1; i &gt;= j; i--))<br/>do<br/>if (($&#123;iMap&#91;$i&#93;&#125; == -1)); then break; fi<br/>done<br/>if ((i &gt;= j)); then continue; fi<br/><br/>((line++))<br/>for ((i = j - 1; i &gt;= 0; i--))<br/>do<br/>((x = i + iTrayWidth))<br/>iMap&#91;$x&#93;=$&#123;iMap&#91;$i&#93;&#125;<br/>done<br/>for ((i = 0; i &lt; iTrayWidth; i++))<br/>do<br/>iMap&#91;$i&#93;=-1<br/>done<br/>done<br/><br/>if ((line == 0)); then return; fi<br/><br/>#根据消去的行数line计算分数和速度级<br/>((x = iLeft + iTrayWidth * 2 + 7))<br/>((y = iTop + 11))<br/>((iScore += line * 2 - 1))<br/>#显示新的分数<br/>echo -ne &quot;&#92;33&#91;1m&#92;33&#91;3$&#123;cScoreValue&#125;m&#92;33&#91;$&#123;y&#125;;$&#123;x&#125;H$&#123;iScore&#125; &quot;<br/>if ((iScore % iScoreEachLevel &lt; line * 2 - 1))<br/>then<br/>if ((iLevel &lt; 20))<br/>then<br/>((iLevel++))<br/>((y = iTop + 14))<br/>#显示新的速度级<br/>echo -ne &quot;&#92;33&#91;3$&#123;cScoreValue&#125;m&#92;33&#91;$&#123;y&#125;;$&#123;x&#125;H$&#123;iLevel&#125; &quot;<br/>fi<br/>fi<br/>echo -ne &quot;&#92;33&#91;0m&quot;<br/><br/><br/>#重新显示背景方块<br/>for ((y = 0; y &lt; iTrayHeight; y++))<br/>do<br/>((yp = y + iTrayTop + 1))<br/>((xp = iTrayLeft + 1))<br/>((i = y * iTrayWidth))<br/>echo -ne &quot;&#92;33&#91;$&#123;yp&#125;;$&#123;xp&#125;H&quot;<br/>for ((x = 0; x &lt; iTrayWidth; x++))<br/>do<br/>((j = i + x))<br/>if (($&#123;iMap&#91;$j&#93;&#125; == -1))<br/>then<br/>echo -ne &quot; &quot;<br/>else<br/>echo -ne &quot;&#92;33&#91;1m&#92;33&#91;7m&#92;33&#91;3$&#123;iMap&#91;$j&#93;&#125;m&#92;33&#91;4$&#123;iMap&#91;$j&#93;&#125;m&#91;&#93;&#92;33&#91;0m&quot;<br/>fi<br/>done<br/>done<br/>&#125;<br/><br/><br/>#下落一行<br/>function BoxDown()<br/>&#123;<br/>local y s<br/>((y = boxCurY + 1)) #新的y坐标<br/>if BoxMove $y $boxCurX #测试是否可以下落一行<br/>then<br/>s=&quot;`DrawCurBox 0`&quot; #将旧的方块抹去<br/>((boxCurY = y))<br/>s=&quot;$s`DrawCurBox 1`&quot; #显示新的下落后方块<br/>echo -ne $s<br/>else<br/>#走到这儿, 如果不能下落了<br/>Box2Map #将当前移动中的方块贴到背景方块中<br/>RandomBox #产生新的方块<br/>fi<br/>&#125;<br/><br/>#左移一列<br/>function BoxLeft()<br/>&#123;<br/>local x s<br/>((x = boxCurX - 1))<br/>if BoxMove $boxCurY $x<br/>then<br/>s=`DrawCurBox 0`<br/>((boxCurX = x))<br/>s=$s`DrawCurBox 1`<br/>echo -ne $s<br/>fi<br/>&#125;<br/><br/>#右移一列<br/>function BoxRight()<br/>&#123;<br/>local x s<br/>((x = boxCurX + 1))<br/>if BoxMove $boxCurY $x<br/>then<br/>s=`DrawCurBox 0`<br/>((boxCurX = x))<br/>s=$s`DrawCurBox 1`<br/>echo -ne $s<br/>fi<br/>&#125;<br/><br/><br/>#下落到底<br/>function BoxAllDown()<br/>&#123;<br/>local k j i x y iDown s<br/>iDown=$iTrayHeight<br/><br/>#计算一共需要下落多少行<br/>for ((j = 0; j &lt; 8; j += 2))<br/>do<br/>((i = j + 1))<br/>((y = $&#123;boxCur&#91;$j&#93;&#125; + boxCurY))<br/>((x = $&#123;boxCur&#91;$i&#93;&#125; + boxCurX))<br/>for ((k = y + 1; k &lt; iTrayHeight; k++))<br/>do<br/>((i = k * iTrayWidth + x))<br/>if (( $&#123;iMap&#91;$i&#93;&#125; != -1)); then break; fi<br/>done<br/>((k -= y + 1))<br/>if (( $iDown &gt; $k )); then iDown=$k; fi<br/>done<br/><br/>s=`DrawCurBox 0` #将旧的方块抹去<br/>((boxCurY += iDown))<br/>s=$s`DrawCurBox 1` #显示新的下落后的方块<br/>echo -ne $s<br/>Box2Map #将当前移动中的方块贴到背景方块中<br/>RandomBox #产生新的方块<br/>&#125;<br/><br/><br/>#旋转方块<br/>function BoxRotate()<br/>&#123;<br/>local iCount iTestRotate boxTest j i s<br/>iCount=$&#123;countBox&#91;$iBoxCurType&#93;&#125; #当前的方块经旋转可以产生的样式的数目<br/><br/>#计算旋转后的新的样式<br/>((iTestRotate = iBoxCurRotate + 1))<br/>if ((iTestRotate &gt;= iCount))<br/>then<br/>((iTestRotate = 0))<br/>fi<br/><br/>#更新到新的样式, 保存老的样式(但不显示)<br/>for ((j = 0, i = ($&#123;offsetBox&#91;$iBoxCurType&#93;&#125; + $iTestRotate) * 8; j &lt; 8; j++, i++))<br/>do<br/>boxTest&#91;$j&#93;=$&#123;boxCur&#91;$j&#93;&#125;<br/>boxCur&#91;$j&#93;=$&#123;box&#91;$i&#93;&#125;<br/>done<br/><br/>if BoxMove $boxCurY $boxCurX #测试旋转后是否有空间放的下<br/>then<br/>#抹去旧的方块<br/>for ((j = 0; j &lt; 8; j++))<br/>do<br/>boxCur&#91;$j&#93;=$&#123;boxTest&#91;$j&#93;&#125;<br/>done<br/>s=`DrawCurBox 0`<br/><br/>#画上新的方块<br/>for ((j = 0, i = ($&#123;offsetBox&#91;$iBoxCurType&#93;&#125; + $iTestRotate) * 8; j &lt; 8; j++, i++))<br/>do<br/>boxCur&#91;$j&#93;=$&#123;box&#91;$i&#93;&#125;<br/>done<br/>s=$s`DrawCurBox 1`<br/>echo -ne $s<br/>iBoxCurRotate=$iTestRotate<br/>else<br/>#不能旋转，还是继续使用老的样式<br/>for ((j = 0; j &lt; 8; j++))<br/>do<br/>boxCur&#91;$j&#93;=$&#123;boxTest&#91;$j&#93;&#125;<br/>done<br/>fi<br/>&#125;<br/><br/><br/>#DrawCurBox(bDraw), 绘制当前移动中的方块, bDraw为1, 画上, bDraw为0, 抹去方块。<br/>function DrawCurBox()<br/>&#123;<br/>local i j t bDraw sBox s<br/>bDraw=$1<br/><br/>s=&quot;&quot;<br/>if (( bDraw == 0 ))<br/>then<br/>sBox=&quot;&#92;40&#92;40&quot;<br/>else<br/>sBox=&quot;&#91;&#93;&quot;<br/>s=$s&quot;&#92;33&#91;1m&#92;33&#91;7m&#92;33&#91;3$&#123;cBoxCur&#125;m&#92;33&#91;4$&#123;cBoxCur&#125;m&quot;<br/>fi<br/><br/>for ((j = 0; j &lt; 8; j += 2))<br/>do<br/>((i = iTrayTop + 1 + $&#123;boxCur&#91;$j&#93;&#125; + boxCurY))<br/>((t = iTrayLeft + 1 + 2 * (boxCurX + $&#123;boxCur&#91;$j + 1&#93;&#125;)))<br/>#&#92;33&#91;y;xH, 光标到(x, y)处<br/>s=$s&quot;&#92;33&#91;$&#123;i&#125;;$&#123;t&#125;H$&#123;sBox&#125;&quot;<br/>done<br/>s=$s&quot;&#92;33&#91;0m&quot;<br/>echo -n $s<br/>&#125;<br/><br/><br/>#更新新的方块<br/>function RandomBox()<br/>&#123;<br/>local i j t<br/><br/>#更新当前移动的方块<br/>iBoxCurType=$&#123;iBoxNewType&#125;<br/>iBoxCurRotate=$&#123;iBoxNewRotate&#125;<br/>cBoxCur=$&#123;cBoxNew&#125;<br/>for ((j = 0; j &lt; $&#123;#boxNew&#91;@&#93;&#125;; j++))<br/>do<br/>boxCur&#91;$j&#93;=$&#123;boxNew&#91;$j&#93;&#125;<br/>done<br/><br/><br/>#显示当前移动的方块<br/>if (( $&#123;#boxCur&#91;@&#93;&#125; == 8 ))<br/>then<br/>#计算当前方块该从顶端哪一行&quot;冒&quot;出来<br/>for ((j = 0, t = 4; j &lt; 8; j += 2))<br/>do<br/>if (($&#123;boxCur&#91;$j&#93;&#125; &lt; t)); then t=$&#123;boxCur&#91;$j&#93;&#125;; fi<br/>done<br/>((boxCurY = -t))<br/>for ((j = 1, i = -4, t = 20; j &lt; 8; j += 2))<br/>do<br/>if (($&#123;boxCur&#91;$j&#93;&#125; &gt; i)); then i=$&#123;boxCur&#91;$j&#93;&#125;; fi<br/>if (($&#123;boxCur&#91;$j&#93;&#125; &lt; t)); then t=$&#123;boxCur&#91;$j&#93;&#125;; fi<br/>done<br/>((boxCurX = (iTrayWidth - 1 - i - t) / 2))<br/><br/>#显示当前移动的方块<br/>echo -ne `DrawCurBox 1`<br/><br/>#如果方块一出来就没处放，Game over!<br/>if ! BoxMove $boxCurY $boxCurX<br/>then<br/>kill -$sigExit $&#123;PPID&#125;<br/>ShowExit<br/>fi<br/>fi<br/><br/><br/><br/>#清除右边预显示的方块<br/>for ((j = 0; j &lt; 4; j++))<br/>do<br/>((i = iTop + 1 + j))<br/>((t = iLeft + 2 * iTrayWidth + 7))<br/>echo -ne &quot;&#92;33&#91;$&#123;i&#125;;$&#123;t&#125;H &quot;<br/>done<br/><br/>#随机产生新的方块<br/>((iBoxNewType = RANDOM % $&#123;#offsetBox&#91;@&#93;&#125;))<br/>((iBoxNewRotate = RANDOM % $&#123;countBox&#91;$iBoxNewType&#93;&#125;))<br/>for ((j = 0, i = ($&#123;offsetBox&#91;$iBoxNewType&#93;&#125; + $iBoxNewRotate) * 8; j &lt; 8; j++, i++))<br/>do<br/>boxNew&#91;$j&#93;=$&#123;box&#91;$i&#93;&#125;;<br/>done<br/><br/>((cBoxNew = $&#123;colorTable&#91;RANDOM % $&#123;#colorTable&#91;@&#93;&#125;&#93;&#125;))<br/><br/>#显示右边预显示的方块<br/>echo -ne &quot;&#92;33&#91;1m&#92;33&#91;7m&#92;33&#91;3$&#123;cBoxNew&#125;m&#92;33&#91;4$&#123;cBoxNew&#125;m&quot;<br/>for ((j = 0; j &lt; 8; j += 2))<br/>do<br/>((i = iTop + 1 + $&#123;boxNew&#91;$j&#93;&#125;))<br/>((t = iLeft + 2 * iTrayWidth + 7 + 2 * $&#123;boxNew&#91;$j + 1&#93;&#125;))<br/>echo -ne &quot;&#92;33&#91;$&#123;i&#125;;$&#123;t&#125;H&#91;&#93;&quot;<br/>done<br/>echo -ne &quot;&#92;33&#91;0m&quot;<br/>&#125;<br/><br/><br/>#初始绘制<br/>function InitDraw()<br/>&#123;<br/>clear<br/>RandomBox #随机产生方块，这时右边预显示窗口中有方快了<br/>RandomBox #再随机产生方块，右边预显示窗口中的方块被更新，原先的方块将开始下落<br/>local i t1 t2 t3<br/><br/>#显示边框<br/>echo -ne &quot;&#92;33&#91;1m&quot;<br/>echo -ne &quot;&#92;33&#91;3$&#123;cBorder&#125;m&#92;33&#91;4$&#123;cBorder&#125;m&quot;<br/><br/>((t2 = iLeft + 1))<br/>((t3 = iLeft + iTrayWidth * 2 + 3))<br/>for ((i = 0; i &lt; iTrayHeight; i++))<br/>do<br/>((t1 = i + iTop + 2))<br/>echo -ne &quot;&#92;33&#91;$&#123;t1&#125;;$&#123;t2&#125;H&#124;&#124;&quot;<br/>echo -ne &quot;&#92;33&#91;$&#123;t1&#125;;$&#123;t3&#125;H&#124;&#124;&quot;<br/>done<br/><br/>((t2 = iTop + iTrayHeight + 2))<br/>for ((i = 0; i &lt; iTrayWidth + 2; i++))<br/>do<br/>((t1 = i * 2 + iLeft + 1))<br/>echo -ne &quot;&#92;33&#91;$&#123;iTrayTop&#125;;$&#123;t1&#125;H==&quot;<br/>echo -ne &quot;&#92;33&#91;$&#123;t2&#125;;$&#123;t1&#125;H==&quot;<br/>done<br/>echo -ne &quot;&#92;33&#91;0m&quot;<br/><br/><br/>#显示&quot;Score&quot;和&quot;Level&quot;字样<br/>echo -ne &quot;&#92;33&#91;1m&quot;<br/>((t1 = iLeft + iTrayWidth * 2 + 7))<br/>((t2 = iTop + 10))<br/>echo -ne &quot;&#92;33&#91;3$&#123;cScore&#125;m&#92;33&#91;$&#123;t2&#125;;$&#123;t1&#125;HScore&quot;<br/>((t2 = iTop + 11))<br/>echo -ne &quot;&#92;33&#91;3$&#123;cScoreValue&#125;m&#92;33&#91;$&#123;t2&#125;;$&#123;t1&#125;H$&#123;iScore&#125;&quot;<br/>((t2 = iTop + 13))<br/>echo -ne &quot;&#92;33&#91;3$&#123;cScore&#125;m&#92;33&#91;$&#123;t2&#125;;$&#123;t1&#125;HLevel&quot;<br/>((t2 = iTop + 14))<br/>echo -ne &quot;&#92;33&#91;3$&#123;cScoreValue&#125;m&#92;33&#91;$&#123;t2&#125;;$&#123;t1&#125;H$&#123;iLevel&#125;&quot;<br/>echo -ne &quot;&#92;33&#91;0m&quot;<br/>&#125;<br/><br/><br/>#退出时显示GameOVer!<br/>function ShowExit()<br/>&#123;<br/>local y<br/>((y = iTrayHeight + iTrayTop + 3))<br/>echo -e &quot;&#92;33&#91;$&#123;y&#125;;0HGameOver!&#92;33&#91;0m&quot;<br/>exit<br/>&#125;<br/><br/><br/><br/>#游戏主程序在这儿开始.<br/>if &#91;&#91; $1 != &quot;--show&quot; &#93;&#93;<br/>then<br/>bash $0 --show&amp; #以参数--show将本程序再运行一遍<br/>RunAsKeyReceiver $! #以上一行产生的进程的进程号作为参数<br/>exit<br/>else<br/>#当发现具有参数--show时，运行显示函数<br/>RunAsDisplayer<br/>exit<br/>fi </div>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] shell版俄罗斯方块]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>