T3RRYT3RR0R

Batch Escape the Ampersand Mini Game

Jan 27th, 2020
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.88 KB | None | 0 0
  1. REM ::: Batch Minigame Tutorial By T3RRY
  2.  
  3. @ECHO OFF & TITLE Escape the Ampersand Demo Game
  4. :start
  5.  
  6. ::: REM EXIT /B 0 is used to return from Functions with a Zero Errorlevel. This is done due to the frequent use of Choice Command with Errorlevel.
  7.  
  8. ::: REM Define 'Play Field' Parameters. Allows Play Field Characteristics to be easily Changed.
  9. :: Outer Border
  10. Set "Hieght=30"
  11. Set "Width=50"
  12.  
  13. Set "Lines=%Hieght%"
  14. Set /a "Lines+=5"
  15. Set "Columns=%Width%"
  16.  
  17. ::: Establish Screen size. Larger screen sizes will result in slower Load times and Gameplay.
  18.  
  19. cls & Mode Con cols=%Columns% Lines=%Lines%
  20.  
  21. :: Inner Border
  22. Set "Axis_mins=2"
  23. Set "X_Axis_Boundary=49"
  24. Set "Y_Axis_Boundary=29"
  25. :: Move Limits within Borders
  26. Set "Limit_Axis_Min=3"
  27. Set "Limit_X_Max=48"
  28. Set "Limit_Y_Max=28"
  29. :: Character Displayed as Outside Border
  30. Set "space= "
  31. :: Character Displayed as Enenmy
  32. Set "E_C=^&"
  33. Set "ENEMY=%E_C%"
  34. ::: REM Build Screen Background using for /L loop to repeat action for the desired number of times in each Line and Column Position
  35. ::: REM (cont) Defined within the Nested Loops.
  36.  
  37.     For /L %%A IN (1,1,%Width%) DO (
  38.         For /L %%B IN (1,1,%hieght%) DO (
  39.         ECHO([%%B;%%AHX
  40.         )
  41.     )
  42.    
  43.     For /L %%A IN (1,1,%hieght%) DO (
  44.         For %%B IN (%Axis_mins%,%X_Axis_Boundary%) DO (
  45.         ECHO([%%A;%%BH+
  46.         )
  47.     )
  48.  
  49.     For /L %%A IN (1,1,%Width%) DO (
  50.         For %%B IN (%Axis_mins%,%Y_Axis_Boundary%) DO (
  51.         ECHO([%%B;%%AH+
  52.         )
  53.     )
  54.  
  55.     For /L %%A IN (1,1,%hieght%) DO (
  56.         ECHO([%%A;1H%space%
  57.         ECHO([%%A;50H%space%
  58.     )
  59.  
  60.     For /L %%A IN (1,1,%Width%) DO (
  61.         ECHO([1;%%AH%space%
  62.         ECHO([30;%%AH%space%
  63.     )
  64.  
  65. ::: REM Define Starting Positions
  66.    
  67. Set "X_Pos=25"
  68. Set "Y_Pos=15"
  69.  
  70. Set "AI_X=10"
  71. Set "AI_Y=10"
  72.  
  73. ::: REM Initialise Last Position variables
  74.  
  75. Set "L_Y_Pos=%Y_Pos%"
  76. Set "L_X_Pos=%X_Pos%"
  77. Set "L_AI_X=%AI_X%"
  78. Set "L_AI_Y=%AI_Y%"
  79.  
  80. :bomb
  81.  
  82. ::: REM Define Random Position For "Bomb" as loss condition, ensuring value within 'play field'
  83.  
  84. Set /a "X_B=%random% %%48 + 1"
  85. Set /a "Y_B=%random% %%28 + 1"
  86. IF %X_B% LSS 3 GOTO :bomb
  87. IF %Y_B% LSS 3 GOTO :bomb
  88.  
  89.     IF %X_B%==%X_Pos% (
  90.         IF %Y_B%==%Y_Pos% (
  91.             GOTO :bomb
  92.         )
  93.     )
  94.  
  95. ::: REM Define Random Position For "Escape" as win condition, ensuring value within 'play field', and Different to "bomb" position
  96.  
  97. :escape
  98. Set /a "X_Esc=%random% %%48 + 1"
  99. Set /a "Y_Esc=%random% %%28 + 1"
  100. IF %X_Esc% LSS 3 (GOTO :escape)
  101. IF %Y_Esc% LSS 3 (GOTO :escape)
  102.  
  103.     IF %X_Esc%==%X_Pos% (
  104.         IF %Y_Esc%==%Y_Pos% (
  105.             GOTO :escape
  106.         )
  107.     )
  108.  
  109.     IF %X_Esc%==%X_B% (
  110.         IF %Y_Esc%==%Y_B% (
  111.             GOTO :escape
  112.         )
  113.     )
  114.  
  115. ::: REM Call refresh Function to Display initial Position, and Update Position after Movement within 'move' loop, Update Last X and Y Positions prior to Movement
  116. ECHO( Escape the Ampersand. [W A S D]
  117.  
  118. :Move
  119.  
  120. ECHO([%L_Y_Pos%;%L_X_Pos%H.
  121. ECHO([%L_AI_Y%;%L_AI_X%H.
  122.  
  123. CALL :refresh
  124.  
  125. Set "L_AI_X=%AI_X%"
  126. Set "L_AI_Y=%AI_Y%"
  127. Set "L_Y_Pos=%Y_Pos%"
  128. Set "L_X_Pos=%X_Pos%"
  129.  
  130. ECHO(
  131.  
  132. REM :: Default switch results in a Free Move for the AI
  133.  
  134. CHOICE /T 1 /N /C wasd0 /M "" /D 0 >nul
  135. CALL :Direction%ERRORLEVEL%
  136.  
  137. Set /a AI_Move=%random% %%2 +1
  138. CALL :Col_AI
  139. CALL :AImove%AI_Move%
  140.  
  141. GOTO :Move
  142.  
  143. :AImove1
  144.    
  145.     IF %AI_X%==%X_Pos% (
  146.     IF %AI_Y% LSS %Y_POS% (Set /a "AI_Y+=1")
  147.     IF %AI_Y% GTR %Y_POS% (Set /a "AI_Y-=1")
  148.     ) else (
  149.     IF %AI_X% LSS %X_POS% (Set /a "AI_X+=1")
  150.     IF %AI_X% GTR %X_POS% (Set /a "AI_X-=1")
  151.     )
  152.     EXIT /B 0
  153.  
  154. :AImove2
  155.  
  156. ::: REM Y Pos Equal Comparison Disabled to Balance AI Tracking Ability. Remove ::: In Function to Make AI more Challenging
  157.  
  158.     IF %AI_Y%==%Y_Pos% (
  159.     IF %AI_X% LSS %X_POS% (Set /a "AI_X+=1")
  160.     IF %AI_X% GTR %X_POS% (Set /a "AI_X-=1")
  161.     ) else (
  162.     IF %AI_Y% LSS %Y_POS% (Set /a "AI_Y+=1")
  163.     IF %AI_Y% GTR %Y_POS% (Set /a "AI_Y-=1")
  164.     )
  165.     EXIT /B 0
  166.  
  167. REM :: AI Advance
  168. :Direction5
  169.     EXIT /B 0
  170.  
  171. REM :: Right    Test If at Rightmost Limit of X axis before allowing Movement, By Increasing Y axis count by one.
  172. :Direction4
  173.  
  174.     IF NOT %X_Pos%==%Limit_X_Max% (Set /a "X_Pos+=1")
  175.     EXIT /B 0
  176.  
  177. REM :: Down Test If at Lower Limit of Y axis before allowing Movement, By Increasing Y axis count by one.
  178. :Direction3
  179.  
  180.     IF NOT %Y_Pos%==%Limit_Y_Max% (Set /a "Y_Pos+=1")
  181.     EXIT /B 0
  182.  
  183. REM :: Left Test If at Leftmost Limit of X axis before allowing Movement, By reducing X axis count by one.
  184. :Direction2
  185.  
  186.     IF NOT %X_Pos%==%Limit_Axis_Min% (Set /a "X_Pos-=1")
  187.     EXIT /B 0
  188.    
  189. REM :: Up.  Test If at Upper Limit of Y axis before allowing Movement, By reducing Y axis count by one.
  190. :Direction1
  191.  
  192.     IF NOT %Y_Pos%==%Limit_Axis_Min% (Set /a "Y_Pos-=1")
  193.     EXIT /B 0
  194.  
  195. ::: REM Upgrade screen display with Movement trail and New Position And test win / loss conditions (Position Comparison)
  196.  
  197. :refresh
  198.  
  199.     IF %L_X_Pos%==%X_Pos% (
  200.         IF %L_X_Pos%==%Y_Pos% (
  201.         ECHO([%Y_Pos%;%X_Pos%H^@
  202.         )
  203.     )
  204.  
  205. ECHO([%Y_Pos%;%X_Pos%H^@
  206. ECHO([%AI_Y%;%AI_X%H%ENEMY%
  207.  
  208.     IF %X_Pos%==%AI_X% (
  209.         IF %Y_Pos%==%AI_Y% (
  210.             ECHO([%Y_Pos%;%X_Pos%HX
  211.             Set "G_Over=You were Nommed by the AI"
  212.             GOTO :end
  213.         )
  214.     )
  215.  
  216.     IF %X_Pos%==%X_B% (
  217.         IF %Y_Pos%==%Y_B% (
  218.             ECHO([%Y_Pos%;%X_Pos%HX
  219.             Set "G_Over=You Hit the Bomb"
  220.             GOTO :end
  221.         )
  222.     )
  223.  
  224.     IF %X_Pos%==%X_Esc% (
  225.         IF %Y_Pos%==%Y_Esc% (
  226.             ECHO([%Y_Pos%;%X_Pos%H^^
  227.             ECHO([%AI_Y%;%AI_X%H%E_C%
  228.             Set "G_Over= You've Found the Escape"
  229.             GOTO :end
  230.         )
  231.     )
  232.     EXIT /B 0
  233.  
  234. :Col_AI
  235. Set /a "Rand_Col=%random% %%5 + 1"
  236. IF %Rand_Col%==5 (Set "ENEMY=%E_C%")
  237. IF %Rand_Col%==4 (Set "ENEMY=%E_C%")
  238. IF %Rand_Col%==3 (Set "ENEMY=%E_C%")
  239. IF %Rand_Col%==2 (Set "ENEMY=%E_C%")
  240. IF %Rand_Col%==1 (Set "ENEMY=%E_C%")
  241.  
  242.     EXIT /B 0
  243.  
  244. :end
  245.     ECHO(%G_over%
  246.     ECHO([E]xit [R]eplay
  247. CHOICE /N /C re /M "" >nul
  248.     IF %ERRORLEVEL%==2 (EXIT)
  249.  
  250.     ENDLOCAL & GOTO :start
Advertisement
Add Comment
Please, Sign In to add comment