Advertisement
T3RRYT3RR0R

Batch Game Tutorial

Jan 25th, 2020
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 4.44 KB | None | 0 0
  1. ::: REM Batch Movement Based Demo Game for Demonstration / tutorial Purposes.
  2. ::: REM Visit https://pastebin.com/k10rXbcC for an updated version
  3.  
  4. @ECHO OFF
  5. :start
  6. cls
  7.  
  8. ::: Establish Screen size. Larger screen sizes will result in slower Load times and Gameplay.
  9.  
  10. Mode Con cols=50 Lines=35
  11.  
  12. ::: REM Define 'Play Field' Parameters. Allows Play Field Characteristics to be easily Changed.
  13. :: Outer Border
  14. Set Hieght=30
  15. Set Width=50
  16. :: Inner Border
  17. Set Axis_mins=2
  18. Set X_Axis_Boundary=49
  19. Set Y_Axis_Boundary=29
  20. :: Move Limits within Borders
  21. Set Limit_Axis_Min=3
  22. Set Limit_X_Max=48
  23. Set Limit_Y_Max=28
  24. :: Character Displayed as Outside Border
  25. Set "space= "
  26.  
  27. ::: REM Build Screen Background using for /L loop to repeat action for the desired number of times in each Line and Column Position
  28. ::: REM (cont) Defined within the Nested Loops.
  29.  
  30.     For /L %%A IN (1,1,%Width%) DO (
  31.         For /L %%B IN (1,1,%hieght%) DO (
  32.         ECHO([%%B;%%AHX
  33.         )
  34.     )
  35.    
  36.     For /L %%A IN (1,1,%hieght%) DO (
  37.         For %%B IN (%Axis_mins%,%X_Axis_Boundary%) DO (
  38.         ECHO([%%A;%%BH+
  39.         )
  40.     )
  41.  
  42.     For /L %%A IN (1,1,%Width%) DO (
  43.         For %%B IN (%Axis_mins%,%Y_Axis_Boundary%) DO (
  44.         ECHO([%%B;%%AH+
  45.         )
  46.     )
  47.  
  48.     For /L %%A IN (1,1,%hieght%) DO (
  49.         ECHO([%%A;1H%space%
  50.         ECHO([%%A;50H%space%
  51.     )
  52.  
  53.     For /L %%A IN (1,1,%Width%) DO (
  54.         ECHO([1;%%AH%space%
  55.         ECHO([30;%%AH%space%
  56.     )
  57.  
  58. ::: REM Define Starting Position
  59.    
  60. Set X_Pos=25
  61. Set Y_Pos=15
  62.  
  63. ::: REM Initialise Last Position variables
  64.  
  65. Set L_Y_Pos=%Y_Pos%
  66. Set L_X_Pos=%X_Pos%
  67.  
  68. :bomb
  69.  
  70. ::: REM Define Random Position For "Bomb" as loss condition, ensuring value within 'play field'
  71.  
  72. Set /a X_B=%random% %%48 + 1
  73. Set /a Y_B=%random% %%28 + 1
  74. IF %X_B% LSS 3 GOTO :bomb
  75. IF %Y_B% LSS 3 GOTO :bomb
  76.  
  77.     IF %X_B%==%X_Pos% (
  78.         IF %Y_B%==%Y_Pos% (
  79.             GOTO :bomb
  80.         )
  81.     )
  82.  
  83. ::: REM Define Random Position For "Treasure" as win condition, ensuring value within 'play field', and Different to "bomb" position
  84.  
  85. :treasure
  86. Set /a X_T=%random% %%48 + 1
  87. Set /a Y_T=%random% %%28 + 1
  88. IF %X_T% LSS 3 GOTO :treasure
  89. IF %Y_T% LSS 3 GOTO :treasure
  90.  
  91.     IF %X_T%==%X_Pos% (
  92.         IF %Y_T%==%Y_Pos% (
  93.             GOTO :treasure
  94.         )
  95.     )
  96.  
  97.     IF %X_T%==%X_B% (
  98.         IF %Y_T%==%Y_B% (
  99.             GOTO :treasure
  100.         )
  101.     )
  102.  
  103. ::: REM Set initial 'timer' to apply incentive to Move
  104.  
  105. Set countdown=5
  106.  
  107. ::: REM Call refresh Function to Display initial Position, and Update Position after Movement within 'move' loop
  108. ::: Update Last X and Y Positions prior to Movement
  109.  
  110. :Move
  111. CALL :refresh
  112. Set L_Y_Pos=%Y_Pos%
  113. Set L_X_Pos=%X_Pos%
  114. ECHO( Time Remaining: [%countdown%]
  115. ECHO( Movement: [W A S D] freezes the Clock.
  116. CHOICE /T 1 /N /C wasd0 /M "" /D 0 >nul
  117. CALL :Direction%ERRORLEVEL%
  118. GOTO :Move
  119.  
  120. REM :: Countdown    Enforced through /T (Timeout) /D (Delay) Switches of CHoice Command
  121. :Direction5
  122. Set /a countdown-=1
  123.  
  124.     IF %countdown%==0 (
  125.         Set "died=You ran out of Time"
  126.         GOTO :lost
  127.     ) else (
  128.         GOTO :EOF
  129.     )
  130.  
  131. REM :: Right    Test If at Rightmost Limit of X axis before allowing Movement, By Increasing X axis count by one.
  132. :Direction4
  133.     IF NOT %X_Pos%==%Limit_X_Max% (Set /a X_Pos+=1)
  134.     GOTO :EOF
  135.  
  136. REM :: Down Test If at Lower Limit of Y axis before allowing Movement, By Increasing Y axis count by one.
  137. :Direction3
  138.     IF NOT %Y_Pos%==%Limit_Y_Max% (Set /a Y_Pos+=1)
  139.     GOTO :EOF
  140.  
  141. REM :: Left Test If at Leftmost Limit of X axis before allowing Movement, By reducing X axis count by one.
  142. :Direction2
  143.     IF NOT %X_Pos%==%Limit_Axis_Min% (Set /a X_Pos-=1)
  144.     GOTO :EOF
  145.    
  146. REM :: Up.  Test If at Upper Limit of Y axis before allowing Movement, By reducing Y axis count by one.
  147. :Direction1
  148.     IF NOT %Y_Pos%==%Limit_Axis_Min% (Set /a Y_Pos-=1)
  149.     GOTO :EOF
  150.    
  151. ::: REM Upgrade screen display with Movement trail and New Position And test win / loss conditions (Position Comparison)
  152.  
  153. :refresh
  154. ECHO([%L_Y_Pos%;%L_X_Pos%H.
  155. ECHO([%Y_Pos%;%X_Pos%HO
  156.  
  157.     IF %X_Pos%==%X_B% (
  158.         IF %Y_Pos%==%Y_B% (
  159.             ECHO([%Y_Pos%;%X_Pos%HX
  160.             Set "died=You Hit the Bomb"
  161.             GOTO :lost
  162.         )
  163.     )
  164.  
  165.     IF %X_Pos%==%X_T% (
  166.         IF %Y_Pos%==%Y_T% (
  167.             ECHO([%Y_Pos%;%X_Pos%HO
  168.             GOTO :won
  169.         )
  170.     )
  171. GOTO :EOF
  172.  
  173.  
  174. :lost
  175.  
  176.     ECHO( %died%
  177.  
  178. :end
  179. ECHO([E]xit [R]eplay
  180. CHOICE /N /C re /M "" >nul
  181.     IF NOT %ERRORLEVEL%==2 (
  182.         GOTO :start
  183.     ) else (
  184.         exit
  185.     )
  186.  
  187. :won
  188. ECHO( You've Found the Treasure.
  189. GOTO :END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement