Board logo

标题: [其他] 批处理迷宫游戏 [打印本页]

作者: HOPE2021    时间: 2021-8-9 10:26     标题: 批处理迷宫游戏

本帖最后由 HOPE2021 于 2021-8-9 10:32 编辑

代码:
  1. @echo off
  2. chcp 936 > nul
  3. title 迷宫
  4. Mode Con: Cols=30 Lines=15
  5. color 0f
  6. set Level=0
  7. set x=1
  8. set y=1
  9. @goto Level
  10. :Start
  11. if %win%==1 goto End
  12. Mode Con: Cols=30 Lines=15
  13. set s=%key%
  14. call :Area 1 9 1 9
  15. for /l %%i in (1,1,9) do (
  16. for /l %%j in (1,1,9) do (
  17. set "s%%i%%j=  "
  18. )
  19. )
  20. set s99=门
  21. if %Level% leq 2 (
  22. call :%Level%
  23. )
  24. if %Level% geq 3 (
  25. set Key=0
  26. call :Rand
  27. )
  28. set s%x%%y%=♀
  29. Mode Con: Cols=30 Lines=15
  30. call :Visual
  31. call :get_key
  32. set s=%key%
  33. for %%i in (w a s d) do (
  34. if /i "%s%"=="%%i" (
  35. set msg=上一步:%s%
  36. call :%%i
  37. )
  38. )
  39. call :win
  40. if "%valid_key%" equ "0" goto Start
  41. :w
  42. set /a x=%x%-1
  43. goto :eof
  44. :a
  45. set /a y=%y%-1
  46. goto :eof
  47. :s
  48. set /a x=%x%+1
  49. goto :eof
  50. :d
  51. set /a y=%y%+1
  52. goto :eof
  53. :Obstacle
  54. if /i "s%x%%y%"=="s%1" (
  55. if /i "%s%"=="w" (
  56. set /a x+=1
  57. )
  58. if /i "%s%"=="a" (
  59. set /a y+=1
  60. )
  61. if /i "%s%"=="s" (
  62. set /a x-=1
  63. )
  64. if /i "%s%"=="d" (
  65. set /a y-=1
  66. )
  67. goto :eof
  68. )
  69. goto :eof
  70. :Visual
  71. cls
  72. title 迷宫    No.%Level%    〖%title%〗
  73. echo.
  74. echo.    No.%Level%    〖%title%〗
  75. echo.    ■■■■■■■■■■■
  76. echo.    ■%s11%%s12%%s13%%s14%%s15%%s16%%s17%%s18%%s19%■
  77. echo.    ■%s21%%s22%%s23%%s24%%s25%%s26%%s27%%s28%%s29%■
  78. echo.    ■%s31%%s32%%s33%%s34%%s35%%s36%%s37%%s38%%s39%■
  79. echo.    ■%s41%%s42%%s43%%s44%%s45%%s46%%s47%%s48%%s49%■
  80. echo.    ■%s51%%s52%%s53%%s54%%s55%%s56%%s57%%s58%%s59%■
  81. echo.    ■%s61%%s62%%s63%%s64%%s65%%s66%%s67%%s68%%s69%■
  82. echo.    ■%s71%%s72%%s73%%s74%%s75%%s76%%s77%%s78%%s79%■
  83. echo.    ■%s81%%s82%%s83%%s84%%s85%%s86%%s87%%s88%%s89%■
  84. echo.    ■%s91%%s92%%s93%%s94%%s95%%s96%%s97%%s98%%s99%■
  85. echo.    ■■■■■■■■■■■
  86. echo.    X: %x%,Y: %y%  %msg%
  87. goto :eof
  88. :get_key
  89. set "key="
  90. for /f "delims=" %%a in ('xcopy /w "%~f0" "%~f0" 2^>nul') do if not defined key set "key=%%a"
  91. set "key=%key:~-1%"
  92. set "valid_key=0"
  93. cls
  94. goto :eof
  95. :Area
  96. if /i %x% lss 1 set x=%1
  97. if /i %x% gtr 9 set x=%2
  98. if /i %y% lss 1 set y=%3
  99. if /i %y% gtr 9 set y=%4
  100. goto :eof
  101. :Level
  102. color 0f
  103. set "msg="
  104. set /a Level+=1
  105. set x=1
  106. set y=1
  107. set Win=0
  108. goto Start
  109. :End
  110. cls
  111. color 4e
  112. for /l %%i in (1,1,9) do (
  113. for /l %%j in (1,1,9) do (
  114. set "s%%i%%j=  "
  115. )
  116. )
  117. for %%i in (%Map%) do (
  118. set s%%i=□
  119. )
  120. set s99=♀
  121. Mode Con: Cols=30 Lines=17
  122. call :visual
  123. echo.    ^>^> 你赢了!!!
  124. echo.    ^>^> 按回车键开始下一关...
  125. pause > nul
  126. goto :Level
  127. :End_If
  128. if /i "s%x%%y%"=="%1" (
  129. set Win=1
  130. ) else (
  131. set Win=0
  132. )
  133. goto :eof
  134. :2
  135. set Map=13 17 22 23 25 27 35 37 41 42 43 44 45 47 57 62 63 64 65 66 67 74 78 82 84 86 88 92 96
  136. set title=层叠石障
  137. call :Map
  138. call :win
  139. goto :eof
  140. :1
  141. set Map=13 56 67 23 56 77 34 65 65 34 45 78 27 89 29 37 87 14 28
  142. set title=小试身手
  143. call :Map
  144. call :win
  145. goto :eof
  146. :Rand
  147. set /a Key=%Random%%%8+1
  148. call :%Key%
  149. set title=随机迷阵
  150. call :Obstacle %Map%
  151. goto :eof
  152. :3
  153. set Map=21 22 23 24 35 26 27 28 38 48 58 68 78 88 98 87 32 54 67 83 74 46 34 38 63 53
  154. call :Map
  155. call :win
  156. goto :eof
  157. :4
  158. set Map=11 22 33 44 55 66 77 88
  159. call :Map
  160. call :win
  161. goto :eof
  162. :5
  163. set Map=19 28 37 46 55 64 73 82 91
  164. call :Map
  165. call :win
  166. goto :eof
  167. :6
  168. set Map=19 28 37 46 55 64 73 82 91 11 22 33 44 55 66 77 88
  169. call :Map
  170. call :win
  171. goto :eof
  172. :7
  173. set Map=11 12 13 14 15 16 17 18 19 21 31 41 51 61 71 81 91 89 88 98 69 68 67 66 76 86 96 49 48 47 46 45 44 54 64 74 84 94
  174. call :Map
  175. call :win
  176. goto :eof
  177. :8
  178. set Map=12 21 22 14 24 34 44 41 42 43 16 26 36 46 56 66 61 62 63 64 65 19 29 39 49 59 69 79 89 91 92 93 94 95 96 97 98
  179. call :Map
  180. call :win
  181. goto :eof
  182. :win
  183. if /i "%x%%y%"=="99" (
  184. set win=1
  185. )
  186. goto :eof
  187. :Map
  188. for %%i in (%Map%) do (
  189. set s%%i=□
  190. call :Obstacle %%i
  191. )
复制代码
By HOPE2021
谢谢。




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2