纯数字随机生成,翻转功能没做,但是在此基础实现不难,个位跟十位对换就可以了...- @echo off
- title 俄罗斯方块
- color 0a
- setlocal enabledelayedexpansion
- :main
- call :go
- ping -n 2 127.1 >nul
- goto :main
-
- :go
- call :rdvar 4
- set /a value=var*10
- call :rdvar 4
- set /a value=value+var
- set /a _xy_1=value
- set /a _%value%=1
- for /l %%a in (2,1,4) do (
- call :fd !value!
- set _xy_%%a=!value!
- )
- rem set _
- call :display
- goto :eof
-
-
- ::::::产生随机数,如果是cal:rdvar2,就同时返回0,1:::::::
- :rdvar
- set /a var=%RANDOM%*%1/32768+1
- if %1 equ 2 (
- set /a rt=var-1
- exit /b !rt!
- )
- goto :eof
-
-
- ::::::::产生指定坐标周围4个坐标,并去除不合格坐标,从中随机得到一个::::::::::::
- :fd
- set /a x=%1 / 10 & set /a y=%1 %% 10
- set /a xy_1=^(x+1^)*10+y & set /a xy_2=^(x-1^)*10+y &set /a xy_3=x*10+y+1 & set /a xy_4= x*10+y-1
- if %x% LEQ 1 set "xy_2="
- if %x% GEQ 4 set "xy_1="
- if %y% LEQ 1 set "xy_4="
- if %y% GEQ 4 set "xy_3="
- set /a n=0
- for /l %%i in (1,1,4) do (
- set xy=!xy_%%i!
- if !xy!.==. set /a n-=1
- if defined _!xy! ( set "xy_%%i=" ) else ( set /a n+=1 )
- )
- set vstr=%xy_1% %xy_2% %xy_3% %xy_4%
- if %n% EQU 1 (
- set /a value=vstr
- set /a _!value!=1
- goto :eof
- )
- call :rdvar %n%
- for /f "tokens=%var%" %%c in ("!vstr!") do (
- set /a value=%%c
- set /a _!value!=1
- )
- goto :eof
-
-
- :display
- for /l %%c in (1,1,4) do (
- echo;
- for /l %%l in (1,1,4) do (
- if defined _%%c%%l (set/p "=■"<nul) else (set/p "= "<nul)
- set _%%c%%l=
- )
- )
- echo;
复制代码
[ 本帖最后由 caruko 于 2010-4-1 16:09 编辑 ] |