- mode con cols=135 lines=18 &title made by 523066680 -- If_Exist
- echo,p>x
- for %%a in (w a s d p q) do (set de%%a=d)
- set _w=s
- set _s=w
- set _a=d
- set _d=a
- :a
- cls
- set /p input="w a s d q(退出) r(重来) p(暂停):"
- set input=%input:~0,1%
- if not defined de%input% (goto :a)
- if "%input%"=="%ever%" (goto :a)
- if "%input%"=="q" (echo,q>x &exit)
- if "%input%"=="r" (echo,r>x)
- call,set ever=%%_%input%%%
- echo %input%>x
- goto :a
复制代码 以上是一个大神写的 贪吃蛇游戏 的控制部分我想把它 改成 自动输入 的怎么能做到
**********************************
主程序- @echo off
- start direction.bat
- title made by hi.baidu.com/523066680
- :action
- color 07
- setlocal enabledelayedexpansion
- mode con cols=65 lines=35
- for /l %%a in (1,1,60) do (set space= !space!)
- for /l %%a in (1,1,30) do (set L%%a=%space%)
- set /a line=15,col=29,i=0,long=9
- :loop
- :::::控制蛇长,判断是否建立食物部分(set /a i+=1)
- if %i% lss %long% (set /a i=1) else (set i=1)
- if defined cut%i% (
- if not defined dot (call :dot)
- !cut%i%:"=!
- set "L%a%=!L%a%:~0,%b%! !L%a%:~%c%!"
- set "%a%_%b%="
- )
- :pausego
- :::::显示
- cls
- echo, %space: =_%__
- for /l %%a in (1,1,30) do echo,│!L%%a!│
- echo, %space: =-%--
- echo,- 分数:%fen%00 %echo%
- for /l %%a in (1,1,2) do (ping -n 1 127.0>nul)
- ::::::读取数据,分析部分
- :typex
- set /p way=<x
- if %way%==q (exit)
- if %way%==r (endlocal &set echo=按wasd方向键激活。&goto :action) else (set echo=)
- if %way%==p (ping -n 2 127.0>nul &set echo=按wasd方向键激活。&goto :pausego) else (set echo=)
- if %way%==w (set /a line-=1)
- if %way%==s (set /a line+=1)
- if %way%==a (set /a col-=1)
- if %way%==d (set /a col+=1)
- if defined %line%_%col% (goto :gameover)
- if %line% equ 31 (goto :gameover)
- if %line% equ 0 (goto :gameover)
- if %col% equ -1 (goto :gameover)
- if %col% equ 60 (goto :gameover)
- ::::::句2描点,3记录点坐标并加以编号,4定义该点是存在的,5判断吃到食物否.
- set /a C2=col+1
- set "L%line%=!L%line%:~0,%col%!*!L%line%:~%C2%!"
- set cut%i%="set /a a=%line%,b=%col%,c=%C2%"
- set "%line%_%col%=exist"
- if "%line%_%col%"=="%dotl%_%dotc%" (set /a long+=3,fen+=1 &set dot=)
- goto :loop
- ::::::建立食物O的调用部分
- :dot
- set /a dotl=%random%%%28+2,dotc=%random%%%58+1
- if defined %dotl%_%dotc% (goto :dot)
- set dot=%dotl%_%dotc%
- set /a dotc2=dotc+1
- set "L%dotl%=!L%dotl%:~0,%dotc%!0!L%dotl%:~%dotc2%!"
- goto :eof
- :gameover
- echo,p>x
- color 0a
- ping -n 2 127.0>nul &cls
- echo,game over 在控制台按q结束游戏,r再玩一次,然后按任意方向键激活暂停状态
- ping -n 3 127.0>nul
- endlocal
- goto :action
复制代码
|