码迷,mamicode.com
首页 > 其他好文 > 详细

批处理写的俄罗斯方块

时间:2015-07-31 12:42:49      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

  1 @echo off&rem 俄罗斯方块游戏,由netbenton编写,在bathome首发,完成时间:2009年9月25日 ver 2.0
  2 if "%1" equ "para2" goto :para2
  3 
  4 set "d-v=for %%a in (!str!) do set/a one=0x%%a,x=one/4+n,y=one%%4+m&(for %%b in ("r!x!.!y!") do if "!%%~b!" equ " " (set r!x!.!y!=■) else (set err=1))"
  5 ::函数d-v,把str中的图标数据,放置到总坐标空间中,如果有覆盖,则err=1。调用方法:(%d-v%)
  6 ::变量使用:one  x  y
  7 
  8 set "d-e=set aec=!cr!!cr!        ┌───────────┐!cr!&(for /l %%a in (2,1,#) do for %%b in ("│!ebuf:@=%%a!│  !ebu%%a!") do set aec=!aec!        %%~b!cr!)&cls&echo;!aec!        └───────────┘"
  9 ::函数d-e,把总坐标空间显示出来,调用方法:(%d-e:#=行数%)
 10 set ebu4=第!guan!关
 11 set ebu6=总分:!fen!
 12 set cr=^
 13 
 14 
 15 ::各种图标定义
 16 set ga1=0 1 5 6
 17 set ga2=1 4 5 8
 18 ::■■
 19 ::  ■■
 20 set gb1=1 2 4 5
 21 set gb2=0 4 5 9
 22 ::  ■■
 23 ::■■
 24 
 25 set za1=4 5 6 7
 26 set za2=1 5 9 d
 27 ::■■■■
 28 
 29 set qa1=1 5 9 8
 30 set qa2=0 4 5 6
 31 set qa3=0 1 4 8
 32 set qa4=0 1 2 6
 33 ::■■
 34 ::
 35 ::
 36 
 37 set qb1=0 4 8 9
 38 set qb2=0 1 2 4
 39 set qb3=0 1 5 9
 40 set qb4=2 4 5 6
 41 ::■■
 42 ::
 43 ::
 44 
 45 set ta1=0 1 4 5
 46 ::■■
 47 ::■■
 48 
 49 set sa1=0 1 2 5
 50 set sa2=1 4 5 9
 51 set sa3=1 4 5 6
 52 set sa4=0 4 5 8
 53 ::
 54 ::■■■
 55 set tw1=0 1
 56 set tw2=0 4
 57 
 58 set on1=0
 59 set on2=0
 60 
 61 set sh1=1 4 5 6 9
 62 set sh2=1 4 5 6 9
 63 
 64 set ao1=0 1 2 4 6
 65 set ao2=0 1 4 8 9
 66 set ao3=0 4 5 6 2
 67 set ao4=0 1 5 8 9
 68 
 69 set tt1=0 1 2 5 9
 70 set tt2=0 4 8 5 6
 71 set tt3=1 5 8 9 a
 72 set tt4=2 4 5 6 a
 73 
 74 
 75 ::cdef
 76 ::89ab
 77 ::4567
 78 ::0123
 79 
 80 echo 0 2 >%~n0.tmp
 81 start "aswd" %0 para2
 82 ::起动控制窗口
 83 
 84 set k3=k%%=mx,k+
 85 set k4=down
 86 set k1=m-
 87 set k2=m+
 88 set k5=t+
 89 ::按键定义
 90 
 91 setlocal enabledelayedexpansion
 92 for /l %%a in (0,1,10) do (set "ebuf=!ebuf!^!r@.%%a^!")
 93 for %%a in (sa_4 ta_1 qb_4 qa_4 za_2 ga_2 gb_2 tw_2 on_2 sh_2 ao_4 tt_4) do (
 94 for /f "tokens=1,2 delims=_" %%b in ("%%a") do (
 95 set _%%b=%%c
 96 for /l %%d in (1,1,%%c) do set/a nx+=1&set ran!nx!=%%b%%d
 97 )
 98 )
 99 ::定义各种图型的可变型数,及单个图的随机号        
100 
101 :restart
102 for /l %%a in (0,1,18) do (for /l %%b in (0,1,10) do set r%%a.%%b= )
103 set/a fen=0,guan=1
104 ::初始化坐标空间18行,10列
105 
106 
107 :loop
108 set/a "m=4,t=2,n=1,down=450/(guan<<2),bti=0"
109 set/a r=!random!%%nx+1
110 set err=
111 
112 set ttr=!_ttr!
113 set _ttr=!ran%r%!
114 ::随机取一个图标,
115 
116 if not defined ttr goto :loop
117 
118 set mx=!_%ttr:~,2%!
119 set k=%ttr:~2%
120 set str=!%ttr%!
121 
122 set _str=!%_ttr%!
123 
124 
125 setlocal enabledelayedexpansion
126 for %%a in (!_str!) do set/a one=0x%%a,x=one/4+8,y=one%%4&set kk!x!.!y!=127 for /l %%a in (8,1,11) do for /l %%b in (0,1,3) do (
128 if defined kk%%a.%%b (set kk%%a=!kk%%a!!kk%%a.%%b!) else (set kk%%a=!kk%%a! )
129 )
130 endlocal&set ebu8=%kk8%&set ebu9=%kk9%&set ebu10=%kk10%&set ebu11=%kk11%
131 ::对预备图标的处理
132 
133 
134 :cont
135 for /f "tokens=1,2" %%a in (%~n0.tmp) do (
136 if %%b geq 6 (call :error %%b&exit)
137 if %%a neq !test! (
138 set bs=!str!&set/a bm=m,bk=k
139 set/a !k%%b!=1
140 if "%%b" equ "3" (for %%b in ("!ttr:~,2!!k!") do set str=!%%~b!)
141 setlocal enabledelayedexpansion
142 (%d-v:#=3%)
143                 rem 调用函数把图标点放置到总坐标空间
144 if defined err (
145 endlocal
146 set/a m=bm,k=bk
147 set str=!bs!
148 if "%%b" equ "4" goto :jmpout
149 ) else (
150 (%d-e:#=18%)
151                         rem 调用显示函数
152 endlocal
153 )
154 )
155 set test=%%a
156 )
157 
158 
159 set ti=1!time:~7,1!!time:~9,2!
160 if !ti! lss !bti! (set /a tn=ti-bti+1000) else (set /a tn=ti-bti)
161 if !tn! gtr !down! (
162 set/a bti=ti,n+=1
163 setlocal enabledelayedexpansion
164 (%d-v:#=3%)
165 if defined err (
166 endlocal
167 goto :jmpout
168 ) else (
169 (%d-e:#=18%)
170 endlocal
171 )
172 )
173 
174 goto :cont
175 
176 :jmpout
177 set/a n-=1
178 (%d-v:#=3%)
179 set m=18
180 
181 for /l %%a in (18,-1,2) do for %%b in ("!ebuf:@=%%a!") do if "%%~b" neq "■■■■■■■■■■■" (set e!m!=%%~b&set/a m-=1)
182 
183 if !m! neq 1 (
184 for /l %%a in (!m!,-1,2) do set "e%%a=           "
185 for /l %%a in (18,-1,2) do (
186 for /l %%b in (0,1,10) do set r%%a.%%b=!e%%a:~%%b,1!
187 )
188 set/a "fen=fen+(m-1)*10,guan=fen/150+1"
189 )
190 
191 if !n! leq 2 (
192 echo 游戏结束!
193 ping -n 3 127.1 >nul
194 goto :restart
195 )
196 goto :loop
197 
198 :para2
199 mode con: cols=30 lines=2
200 echo a左 d右 w转 s加速 q退出
201 :p_lp
202 set/a n=n%%10+1
203 choice /c adwsgq /n >nul
204 >%~n0.tmp echo;%n% %errorlevel%
205 if %errorlevel% geq 6 exit
206 goto :p_lp
207 
208 :error
209 if %1 equ 6 echo 谢谢使用,再见。。。
210 if %1 gtr 6 echo 对不起!choice.exe 文件不存在,不能运行。。。
211 ping -n 3 127.1 >nul
212 goto :eof

技术分享

批处理写的俄罗斯方块

标签:

原文地址:http://www.cnblogs.com/jwk000/p/4691465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!