Batch 批处理小弹珠

试了下写一个弹珠在黑框框中弹


上下弹的~

没想到运行这么快,所以加了一句延时的

:: ——by EC
@echo off & setlocal EnableDelayedExpansion
mode con: cols=80 lines=24
set xy=
:loop
for /l %%i in (1 1 64) do (
	if defined direct (
	set /a xy-=1
	) else ( set /a xy+=1 )
	cls & for /l %%j in (1 1 !xy!) do echo=
	set /p=● < nul
	for /l %%k in (1 1 128) do ver > nul
	if !xy! equ 0 set "direct=" & goto :loop
	if !xy! equ 24 set direct=a & goto :loop
)	

在屏幕内弹~

:: ——by EC
@echo off & setlocal EnableDelayedExpansion
mode con: cols=80 lines=24
set /a x=1
set /a y=1
set "space= "
set ball=●
set "str="
set dx=+
set dy=-
:loop
cls
for /l %%i in (1 1 %y%) do echo=
set "str="
set /a x%dx%=1,y%dy%=1
if %x% equ 0 set dx=+
if %x% equ 79 set dx=-
for /l %%i in (1 1 %x%) do set str=!str!%space%
set str=!str!%ball%
if %y% equ 24 set dy=- & goto :loop
if %y% equ 0 set dy=+ & goto :loop
echo %str% 
for /l %%i in (1 1 128) do ver > nul
goto :loop

改写了下。

:: ——by EC
@echo off & setlocal EnableDelayedExpansion
mode con: cols=80 lines=24
set /a x=1
set /a y=1
set "space= "
set ball=●
set "str="
set /a dx=1
set /a dy=1
:loop
cls
for /l %%i in (1 1 %y%) do echo=
set "str="
set /a x+=%dx%,y+=%dy%
if %x% equ 0 set /a dx=1
if %x% equ 79 set /a dx=-1
for /l %%i in (1 1 %x%) do set str=!str!%space%
set str=!str!%ball%
if %y% equ 24 set /a dy=-1 & goto :loop
if %y% equ 0 set /a dy=1 & goto :loop
echo %str% 
for /l %%i in (1 1 128) do ver > nul
goto :loop

多个球

:: ——by EC
@echo off & setlocal EnableDelayedExpansion
mode con: cols=80 lines=24
set ball=●
for /l %%i in (1 1 39) do set "space=  !space!"
set num=4
for /l %%i in (1 1 %num%) do (
	set /a b%%idx=1,b%%idy=1
	set /a b%%ix=!random!%%79,b%%iy=!random!%%23
)
:loop
for /l %%i in (1 1 %num%) do (
	set /a b%%ix+=b%%idx,b%%iy+=b%%idy
	for /f "tokens=1,2" %%a in ("!b%%ix! line!b%%iy!") do (
		if defined %%b (set %%b=!%%b:~0,%%a!%ball%) else (
			set %%b=!space:~0,%%a!%ball% 
		)
	)
)
cls
for /l %%i in (1 1 23) do echo=!line%%i! 
set /p=!line24! < nul
for /l %%i in (1 1 %num%) do (
	set line!b%%iy!=
	if !b%%ix! geq 78 set /a b%%idx=-1
	if !b%%ix! leq 0 set /a b%%idx=1
	if !b%%iy! geq 23 set /a b%%idy=-1
	if !b%%iy! leq 0 set /a b%%idy=1
)
for /l %%i in (1 1 128) do ver > nul
goto :loop

写起来还挺麻烦的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值