Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: REM Batch Movement Based Demo Game for Demonstration / tutorial Purposes.
- ::: REM Visit https://pastebin.com/k10rXbcC for an updated version
- @ECHO OFF
- :start
- cls
- ::: Establish Screen size. Larger screen sizes will result in slower Load times and Gameplay.
- Mode Con cols=50 Lines=35
- ::: REM Define 'Play Field' Parameters. Allows Play Field Characteristics to be easily Changed.
- :: Outer Border
- Set Hieght=30
- Set Width=50
- :: Inner Border
- Set Axis_mins=2
- Set X_Axis_Boundary=49
- Set Y_Axis_Boundary=29
- :: Move Limits within Borders
- Set Limit_Axis_Min=3
- Set Limit_X_Max=48
- Set Limit_Y_Max=28
- :: Character Displayed as Outside Border
- Set "space= "
- ::: REM Build Screen Background using for /L loop to repeat action for the desired number of times in each Line and Column Position
- ::: REM (cont) Defined within the Nested Loops.
- For /L %%A IN (1,1,%Width%) DO (
- For /L %%B IN (1,1,%hieght%) DO (
- ECHO([%%B;%%AH[32mX
- )
- )
- For /L %%A IN (1,1,%hieght%) DO (
- For %%B IN (%Axis_mins%,%X_Axis_Boundary%) DO (
- ECHO([%%A;%%BH[7m[31m+[0m
- )
- )
- For /L %%A IN (1,1,%Width%) DO (
- For %%B IN (%Axis_mins%,%Y_Axis_Boundary%) DO (
- ECHO([%%B;%%AH[7m[31m+[0m
- )
- )
- For /L %%A IN (1,1,%hieght%) DO (
- ECHO([%%A;1H[7m[37m%space%[0m
- ECHO([%%A;50H[7m[37m%space%[0m
- )
- For /L %%A IN (1,1,%Width%) DO (
- ECHO([1;%%AH[7m[37m%space%[0m
- ECHO([30;%%AH[7m[37m%space%[0m
- )
- ::: REM Define Starting Position
- Set X_Pos=25
- Set Y_Pos=15
- ::: REM Initialise Last Position variables
- Set L_Y_Pos=%Y_Pos%
- Set L_X_Pos=%X_Pos%
- :bomb
- ::: REM Define Random Position For "Bomb" as loss condition, ensuring value within 'play field'
- Set /a X_B=%random% %%48 + 1
- Set /a Y_B=%random% %%28 + 1
- IF %X_B% LSS 3 GOTO :bomb
- IF %Y_B% LSS 3 GOTO :bomb
- IF %X_B%==%X_Pos% (
- IF %Y_B%==%Y_Pos% (
- GOTO :bomb
- )
- )
- ::: REM Define Random Position For "Treasure" as win condition, ensuring value within 'play field', and Different to "bomb" position
- :treasure
- Set /a X_T=%random% %%48 + 1
- Set /a Y_T=%random% %%28 + 1
- IF %X_T% LSS 3 GOTO :treasure
- IF %Y_T% LSS 3 GOTO :treasure
- IF %X_T%==%X_Pos% (
- IF %Y_T%==%Y_Pos% (
- GOTO :treasure
- )
- )
- IF %X_T%==%X_B% (
- IF %Y_T%==%Y_B% (
- GOTO :treasure
- )
- )
- ::: REM Set initial 'timer' to apply incentive to Move
- Set countdown=5
- ::: 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
- :Move
- CALL :refresh
- Set L_Y_Pos=%Y_Pos%
- Set L_X_Pos=%X_Pos%
- ECHO([31;1H[K [33mTime Remaining: [[31m%countdown%[33m]
- ECHO([32;1H[37m Movement: [[36mW A S D[37m] freezes the Clock.
- CHOICE /T 1 /N /C wasd0 /M "" /D 0 >nul
- CALL :Direction%ERRORLEVEL%
- GOTO :Move
- REM :: Countdown Enforced through /T (Timeout) /D (Delay) Switches of CHoice Command
- :Direction5
- Set /a countdown-=1
- IF %countdown%==0 (
- Set "died=You ran out of Time"
- GOTO :lost
- ) else (
- GOTO :EOF
- )
- REM :: Right Test If at Rightmost Limit of X axis before allowing Movement, By Increasing X axis count by one.
- :Direction4
- IF NOT %X_Pos%==%Limit_X_Max% (Set /a X_Pos+=1)
- GOTO :EOF
- REM :: Down Test If at Lower Limit of Y axis before allowing Movement, By Increasing Y axis count by one.
- :Direction3
- IF NOT %Y_Pos%==%Limit_Y_Max% (Set /a Y_Pos+=1)
- GOTO :EOF
- REM :: Left Test If at Leftmost Limit of X axis before allowing Movement, By reducing X axis count by one.
- :Direction2
- IF NOT %X_Pos%==%Limit_Axis_Min% (Set /a X_Pos-=1)
- GOTO :EOF
- REM :: Up. Test If at Upper Limit of Y axis before allowing Movement, By reducing Y axis count by one.
- :Direction1
- IF NOT %Y_Pos%==%Limit_Axis_Min% (Set /a Y_Pos-=1)
- GOTO :EOF
- ::: REM Upgrade screen display with Movement trail and New Position And test win / loss conditions (Position Comparison)
- :refresh
- ECHO([%L_Y_Pos%;%L_X_Pos%H[34m.
- ECHO([%Y_Pos%;%X_Pos%H[36mO
- IF %X_Pos%==%X_B% (
- IF %Y_Pos%==%Y_B% (
- ECHO([%Y_Pos%;%X_Pos%H[31m[7mX[0m
- Set "died=You Hit the Bomb"
- GOTO :lost
- )
- )
- IF %X_Pos%==%X_T% (
- IF %Y_Pos%==%Y_T% (
- ECHO([%Y_Pos%;%X_Pos%H[36m[7mO[0m
- GOTO :won
- )
- )
- GOTO :EOF
- :lost
- ECHO([31;1H[K[31m %died%
- :end
- ECHO([32;1H[K[34m[E]xit [R]eplay
- CHOICE /N /C re /M "" >nul
- IF NOT %ERRORLEVEL%==2 (
- GOTO :start
- ) else (
- exit
- )
- :won
- ECHO([31;1H[K[36m You've Found the Treasure.
- GOTO :END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement