标题: [游戏娱乐] 批处理贪吃蛇程序 [打印本页]
作者: a2002 时间: 2017-7-25 13:56 标题: 批处理贪吃蛇程序
本帖最后由 a2002 于 2017-7-26 09:02 编辑
无聊写了个贪吃蛇,练练笔。(原创区发不了,放在这儿)
[attach]10777[/attach]
源码:- @echo off&setlocal EnableDelayedExpansion&rem made by a2002
- if "%~1" equ "Control" set fw=s&set fa=d&set fs=w&set fd=a&goto :Control
- start /b "" "%~f0" Control
-
- set Speed=100
- set long=3
- set Snake=■
- set food=◇
- set Empty=
-
- call :StartWith
- :Main
- set mov=1&call :echo
- Cons Sleep,!Speed!
- set /p drv=<snk.tmp
- if !drv! equ w set /a X-=1
- if !drv! equ a set /a Y-=1
- if !drv! equ s set /a X+=1
- if !drv! equ d set /a Y+=1
- call :Check
- call :Move !mov!
- goto :Main
-
- :StartWith
- mode 80,24&set crlf=^
-
- &Cons SetTitle,贪吃蛇游戏
- Cons SetIcon,%~dp0Snake.ico&Cons HideCur
- for /l %%# in (1,1,!long!) do set t=!t!1
- set t=!t!00000000000000000000
- set Data=!t:~0,20!
- for /l %%# in (2,1,20) do set Data=!Data!00000000000000000000
- set Top=┏━━━━━━━━━━━━━━━━━━━━┓
- set Bot=┗━━━━━━━━━━━━━━━━━━━━┛
- for /l %%# in (1,1,!long!) do set Pos=!Pos!,1.%%#
- set Pos=!Pos:~1!&set /a X=1,Y=long
- echo d>snk.tmp&set foodPos=378&call :Setfood
- set Mark=0&exit /b
-
- :echo
- Cons SetCurPos,0,0
- set _Data=!Data:0=%Empty%!&set _Data=!_Data:1=%Snake%!&set _Data=!_Data:2=%food%!
- set echo=!Top!&for /l %%# in (0,20,380) do set echo=!echo!!crlf!┃!_Data:~%%#,20!┃&if %%# equ 0 set echo=!echo!分数:!mark! 蛇长:!long!
- echo;!echo!!crlf!!Bot!!crlf!made by a2002 press "u" to quit
- exit /b
-
- :Control
- set /p drv=<snk.tmp
- set "t="&for /f "delims=" %%a in ('xcopy /w . . 2^>nul') do if not defined t set "t=%%a"
- set "t=!t:~-1!"
- for %%# in (w a s d) do if "!t!" equ "%%#" if !f%drv%! neq %%# echo %%#>snk.tmp
- if "!t!" equ "u" Cons SendMsg,274,61536,0
- goto :Control
-
- :Getfood
- set /a foodPos=!random!%%400
- exit /b
-
- :Over
- set /p=Game over,press "u" to quit<nul
- pause>nul
-
- :Check
- if !X! gtr 20 goto :Over
- if !X! lss 1 goto :Over
- if !Y! gtr 20 goto :Over
- if !Y! lss 1 goto :Over
- set /a t1=X*20+Y-21
- if "!Data:~%t1%,1!" equ "2" call :Getfood&exit /b
- if "!Data:~%t1%,1!" equ "1" goto :Over
- exit /b
-
- :Move
- set /a t1=X*20+Y-21,t2=t1+1
- set Data=!Data:~0,%t1%!1!Data:~%t2%!
- for /f "tokens=1* delims=," %%a in ("!Pos!") do (
- for /f "tokens=1,2 delims=." %%x in ("%%a") do set /a t1=%%x*20+%%y-21,t2=t1+1
- if %1 equ 1 (set Pos=%%b,!X!.!Y!) else set Pos=!Pos!,!X!.!Y!)
- if %1 equ 1 set Data=!Data:~0,%t1%!0!Data:~%t2%!
- exit /b
-
- :Getfood
- set /a t1=X*20+Y-21,t2=t1+1,long+=1,mark+=long/10+1,mov=0
- set Data=!Data:~0,%t1%!1!Data:~%t2%!
- :Getfood_loop
- set /a foodPos=!random!%%400
- if "!Data:~%foodPos%,1!" neq "0" goto :Getfood_loop
- call :Setfood&exit /b
-
- :Setfood
- set /a t1=foodPos+1
- set Data=!Data:~0,%foodPos%!2!Data:~%t1%!
- exit /b
复制代码
下载:
[attach]10768[/attach]
作者: 523066680 时间: 2017-7-25 14:20
按键:习惯了按q退出
作者: a2002 时间: 2017-7-25 14:27
回复 2# 523066680
本来是q的,但wasd旁边是q,玩着玩着
不小心按到就退了,就取第二个字母u代替了
作者: a2002 时间: 2017-7-25 14:32
我估计玩到350长时速度会变慢甚至很卡,但应该很难玩到这么长吧
作者: a2002 时间: 2017-7-25 15:05
更改地图。增加难度
[attach]10770[/attach]
[attach]10771[/attach]
作者: 老刘1号 时间: 2017-7-25 21:59
自从你往第三方原创开源区放帖子以后,布局都变了……
现在这个板块叫开源原创工具……
作者: a2002 时间: 2017-7-25 22:07
回复 6# 老刘1号
是吗,随便发发而已啦
作者: a2002 时间: 2017-7-25 22:39
感谢Batcher的移帖..........好尴尬
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |