Board logo

标题: [游戏娱乐] 批处理贪吃蛇程序 [打印本页]

作者: a2002    时间: 2017-7-25 13:56     标题: 批处理贪吃蛇程序

本帖最后由 a2002 于 2017-7-26 09:02 编辑

无聊写了个贪吃蛇,练练笔。(原创区发不了,放在这儿)

[attach]10777[/attach]

源码:
  1. @echo off&setlocal EnableDelayedExpansion&rem made by a2002
  2. if "%~1" equ "Control" set fw=s&set fa=d&set fs=w&set fd=a&goto :Control
  3. start /b "" "%~f0" Control
  4. set Speed=100
  5. set long=3
  6. set Snake=■
  7. set food=◇
  8. set Empty= 
  9. call :StartWith
  10. :Main
  11. set mov=1&call :echo
  12. Cons Sleep,!Speed!
  13. set /p drv=<snk.tmp
  14. if !drv! equ w set /a X-=1
  15. if !drv! equ a set /a Y-=1
  16. if !drv! equ s set /a X+=1
  17. if !drv! equ d set /a Y+=1
  18. call :Check
  19. call :Move !mov!
  20. goto :Main
  21. :StartWith
  22. mode 80,24&set crlf=^
  23. &Cons SetTitle,贪吃蛇游戏
  24. Cons SetIcon,%~dp0Snake.ico&Cons HideCur
  25. for /l %%# in (1,1,!long!) do set t=!t!1
  26. set t=!t!00000000000000000000
  27. set Data=!t:~0,20!
  28. for /l %%# in (2,1,20) do set Data=!Data!00000000000000000000
  29. set Top=┏━━━━━━━━━━━━━━━━━━━━┓
  30. set Bot=┗━━━━━━━━━━━━━━━━━━━━┛
  31. for /l %%# in (1,1,!long!) do set Pos=!Pos!,1.%%#
  32. set Pos=!Pos:~1!&set /a X=1,Y=long
  33. echo d>snk.tmp&set foodPos=378&call :Setfood
  34. set Mark=0&exit /b
  35. :echo
  36. Cons SetCurPos,0,0
  37. set _Data=!Data:0=%Empty%!&set _Data=!_Data:1=%Snake%!&set _Data=!_Data:2=%food%!
  38. set echo=!Top!&for /l %%# in (0,20,380) do set echo=!echo!!crlf!┃!_Data:~%%#,20!┃&if %%# equ 0 set echo=!echo!分数:!mark!    蛇长:!long!
  39. echo;!echo!!crlf!!Bot!!crlf!made by a2002     press "u" to quit
  40. exit /b
  41. :Control
  42. set /p drv=<snk.tmp
  43. set "t="&for /f "delims=" %%a in ('xcopy /w . . 2^>nul') do if not defined t set "t=%%a"
  44. set "t=!t:~-1!"
  45. for %%# in (w a s d) do if "!t!" equ "%%#" if !f%drv%! neq %%# echo %%#>snk.tmp
  46. if "!t!" equ "u" Cons SendMsg,274,61536,0
  47. goto :Control
  48. :Getfood
  49. set /a foodPos=!random!%%400
  50. exit /b
  51. :Over
  52. set /p=Game over,press "u" to quit<nul
  53. pause>nul
  54. :Check
  55. if !X! gtr 20 goto :Over
  56. if !X! lss 1 goto :Over
  57. if !Y! gtr 20 goto :Over
  58. if !Y! lss 1 goto :Over
  59. set /a t1=X*20+Y-21
  60. if "!Data:~%t1%,1!" equ "2" call :Getfood&exit /b
  61. if "!Data:~%t1%,1!" equ "1" goto :Over
  62. exit /b
  63. :Move
  64. set /a t1=X*20+Y-21,t2=t1+1
  65. set Data=!Data:~0,%t1%!1!Data:~%t2%!
  66. for /f "tokens=1* delims=," %%a in ("!Pos!") do (
  67. for /f "tokens=1,2 delims=." %%x in ("%%a") do set /a t1=%%x*20+%%y-21,t2=t1+1
  68. if %1 equ 1 (set Pos=%%b,!X!.!Y!) else set Pos=!Pos!,!X!.!Y!)
  69. if %1 equ 1 set Data=!Data:~0,%t1%!0!Data:~%t2%!
  70. exit /b
  71. :Getfood
  72. set /a t1=X*20+Y-21,t2=t1+1,long+=1,mark+=long/10+1,mov=0
  73. set Data=!Data:~0,%t1%!1!Data:~%t2%!
  74. :Getfood_loop
  75. set /a foodPos=!random!%%400
  76. if "!Data:~%foodPos%,1!" neq "0" goto :Getfood_loop
  77. call :Setfood&exit /b
  78. :Setfood
  79. set /a t1=foodPos+1
  80. set Data=!Data:~0,%foodPos%!2!Data:~%t1%!
  81. 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://www.bathome.net/) Powered by Discuz! 7.2