俄罗斯方块
本代码非常牛,模拟俄罗斯方块游戏很成功。
@goto :` 俄罗斯方块游戏,由netbenton编写,在bathome首发,完成时间:2009年9月25日 ver 1.3
e100 EB 02 00 00 CD 1A 89 16 02 01 31 C0 CD 1A 3B 16 02 01 75 0E
e114 B4 01 CD 16 74 F0 B4 00 CD 16 88 E0 EB 02 B0 00 B4 4C CD 21
g
:`
@echo off
set "d-v=for /l %%a in (0,1,#) do set/a one=0x!str:~%%a,1!,x=one/4+n,y=one%%4+m&(for %%b in ("r!x!.!y!") do if "!%%~b!" equ " " (set %%~b=■) else (set err=1))"
::函数d-v,把str中的图标数据,放置到总坐标空间中,如果有覆盖,则err=1。调用方法:(%d-v:#=图标点数%)
::变量使用:one x y
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! └───────────┘"
::函数d-e,把总坐标空间显示出来,调用方法:(%d-e:#=行数%)
set ebu4=第!guan!关
set ebu6=总分:!fen!
set cr=^
::各种图标定义
set ga1=0156
set ga2=1458
set gb1=1245
set gb2=0459
set za1=4567
set za2=159d
set qa1=1598
set qa2=0456
set qa3=0148
set qa4=0126
set qb1=0489
set qb2=0124
set qb3=0159
set qb4=2456
set ta1=0145
set sa1=0125
set sa2=1459
set sa3=1456
set sa4=0458
chcp 437 >nul
graftabl 936>nul
setlocal enabledelayedexpansion
::按键定义
set 转=k%%=mx,k+
set 速=down
set 左=m-
set 右=m+
set 停=paus%%=2,paus+
set 退=quit
cls
echo 批处理俄罗斯方块,300分为一关
echo 一次消一行得10分
echo 一次消二行得30分
echo 一次消三行得50分
echo 一次消四行得70分
echo;
echo 请自定义操作按键
echo;
call :setkey 左 "左按键"
call :setkey 右 "右按键"
call :setkey 速 "加速键"
call :setkey 转 "转动键"
call :setkey 停 "暂停"
call :setkey 退 "退出"
set paus=1
mode con: rate=50 delay=0
for /l %%a in (0,1,10) do (set "ebuf=!ebuf!^!r@.%%a^!")
for %%a in (sa_4 ta_1 qb_4 qa_4 za_2 ga_2 gb_2) do (
for /f "tokens=1,2 delims=_" %%b in ("%%a") do (
set _%%b=%%c
for /l %%d in (1,1,%%c) do set/a nx+=1&set ran!nx!=%%b%%d
)
)
::定义各种图型的可变型数,及单个图的随机号
:restart
for /l %%a in (0,1,20) do (for /l %%b in (0,1,10) do set r%%a.%%b= )
set/a fen=0,guan=1
::初始化坐标空间20行,10列
:loop
set/a "m=4,t=2,n=1,down=450/(guan<<2),bti=0"
set/a r=!random!%%nx+1
set err=
set ttr=!_ttr!
set _ttr=!ran%r%!
::随机取一个图标,
if not defined ttr goto :loop
set mx=!_%ttr:~,2%!
set k=%ttr:~2%
set str=!%ttr%!
set _str=!%_ttr%!
setlocal enabledelayedexpansion
for /l %%a in (0,1,3) do set/a one=0x!_str:~%%a,1!,x=one/4+8,y=one%%4&set kk!x!.!y!=■
for /l %%a in (8,1,11) do for /l %%b in (0,1,3) do (
if defined kk%%a.%%b (set kk%%a=!kk%%a!!kk%%a.%%b!) else (set kk%%a=!kk%%a! )
)
endlocal&set ebu8=%kk8%&set ebu9=%kk9%&set ebu10=%kk10%&set ebu11=%kk11%
::对预备图标的处理
:cont
::读取按键
debug<"%~n0.bat">nul
set key=%errorlevel%
(if %paus% equ 2 goto :pause
if defined k%key% (
if %key% equ %退% call :error %key%&exit
set bs=!str!&set/a bm=m,bk=k
set/a !k%key%!=1
if "%key%" equ "%转%" (for %%b in ("!ttr:~,2!!k!") do set str=!%%~b!)
setlocal enabledelayedexpansion
(%d-v:#=3%)
rem 调用函数把图标点放置到总坐标空间
if defined err (
endlocal
set/a m=bm,k=bk
set str=!bs!
) else (
(%d-e:#=20%)
rem 调用显示函数
endlocal
)
)
set ti=1!time:~7,1!!time:~9,2!
if !ti! lss !bti! (set /a tn=ti-bti+1000) else (set /a tn=ti-bti)
if !tn! gtr !down! (
set/a bti=ti,n+=1
setlocal enabledelayedexpansion
(%d-v:#=3%)
if defined err (
endlocal
goto :jmpout
) else (
(%d-e:#=20%)
endlocal
)
)
if %key% equ %停% echo 再按暂停键继续。。。
goto :cont)
:jmpout
set/a n-=1
(%d-v:#=3%)
set m=20
for /l %%a in (20,-1,2) do for %%b in ("!ebuf:@=%%a!") do if "%%~b" neq "■■■■■■■■■■■" (set e!m!=%%~b&set/a m-=1)
if !m! neq 1 (
for /l %%a in (!m!,-1,2) do set "e%%a="
for /l %%a in (20,-1,2) do (
for /l %%b in (0,1,10) do set r%%a.%%b=!e%%a:~%%b,1!
)
set/a "fen=fen+(m-1)*20-10,guan=fen/300+1"
)
if !n! leq 2 (
cls&(%d-e:#=20%)
echo 游戏结束!
ping -n 3 127.1 >nul
goto :restart
)
goto :loop
:error
if %1 equ %退% echo 谢谢使用,再见。。。
ping -n 3 127.1 >nul
mode con rate=30 delay=1
goto :eof
:pause
if %key% equ %停% set paus=1
if %key% equ %退% goto :error
goto :cont
:setkey
echo;
echo 定义: %~2
:sk_lp
ping -n 1 127.1 >nul
debug<"%~n0.bat">nul
set var=%errorlevel%
if %var% equ 0 goto :sk_lp
if defined k%var% echo;不能重复定义&goto :setkey
set k%var%=!%1!
set %1=%var%
goto :eof