Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF & TITLE Escape the Ampersands
- REM ::: Batch Minigame Tutorial By T3RRY
- REM ::: Youtube : https://youtu.be/4j1myFxh8xc
- :start
- CLS
- ::: 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.
- ::: REM Define 'Play Field' Parameters. Allows Play Field Characteristics to be easily Changed. Only Hieght and Width need changing
- :: Outer Border
- REM Hieght Max = 38 Min = 20
- REM Width Max = 150 Min =35
- Set "Hieght=25"
- Set "Width=35"
- Set /A Score=(%Hieght% * %Width%) * 2
- Set "Lines=%Hieght%"
- Set /a "Lines+=5"
- Set "Columns=%Width%"
- ::: Establish Screen size. Larger screen sizes will result in slower Load times and Gameplay.
- cls & Mode Con cols=%Columns% Lines=%Lines%
- :: Inner Border
- Set "Axis_mins=2"
- Set /A "X_Axis_Boundary=%Width% - 1"
- Set /A "Y_Axis_Boundary=%Hieght% - 1"
- :: Move Limits within Borders
- Set "Limit_Axis_Min=3"
- Set /A "Limit_X_Max=%X_Axis_Boundary% - 1"
- Set /A "Limit_Y_Max=%Y_Axis_Boundary% - 1"
- :: Character Displayed as Outside Border
- Set "space= "
- :: Character Displayed as Enenmy
- Set "P_C=@"
- Set "E_C=^&"
- Set "Esc=[37m^"
- Set "ENEMY=[31m%E_C%"
- :: Instruction Line Pos - Line number that information is displayed to the player on
- Set /A Instructions=%hieght% + 2
- Set "Game_Over=Goto :end"
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Macro Definition
- setlocal DisableDelayedExpansion
- set LF=^
- ::Above 2 blank lines are required - do not remove
- set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
- Set @COL=for /L %%n in (1 1 2) do if %%n==2 (%\n%
- for /F "tokens=1 delims=," %%G in ("!argv!") do (%\n%
- Set /a "Rand_Col=!random! * 5 / 32768 + 1" %\n%
- IF !Rand_Col!==5 (Set "%%G=[31m!E_C!") %\n%
- IF !Rand_Col!==4 (Set "%%G=[33m!E_C!") %\n%
- IF !Rand_Col!==3 (Set "%%G=[35m!E_C!") %\n%
- IF !Rand_Col!==2 (Set "%%G=[37m!E_C!") %\n%
- IF !Rand_Col!==1 (Set "%%G=[90m!E_C!") %\n%
- ) %\n%
- ) ELSE setlocal enableDelayedExpansion ^& set argv=,
- Set @POS=for /L %%n in (1 1 2) do if %%n==2 (%\n%
- for /F "tokens=1 delims=, " %%G in ("!argv!") do (%\n%
- ECHO([!L_Y_Pos!;!L_X_Pos!H[34m.%\n%
- ECHO([!L_AI_Y!;!L_AI_X!H[31m.%\n%
- ECHO([!L_AI2_Y!;!L_AI2_X!H[31m.%\n%
- ECHO([!Y_Pos!;!X_Pos!H[36m!P_C!%\n%
- ) %\n%
- ) ELSE setlocal enableDelayedExpansion ^& set argv=,
- Set @REFRESH=for /L %%n in (1 1 2) do if %%n==2 (%\n%
- for /F "tokens=1 delims=, " %%G in ("!argv!") do (%\n%
- IF "!L_X_Pos!"=="!X_Pos!" IF "!L_Y_Pos!"=="!Y_Pos!" ECHO([!Y_Pos!;!X_Pos!H[36m!P_C!%\n%
- IF "!X_Pos!"=="!AI_X!" IF "!Y_Pos!"=="!AI_Y!" (%\n%
- ECHO([!Y_Pos!;!X_Pos!H[31m[7mX[0m%\n%
- Set "G_Over=[!Instructions!;1H[K[31mYou were Nommed by the AI"%\n%
- !Game_Over!%\n%
- ) %\n%
- IF "!X_Pos!"=="!AI2_X!" IF "!Y_Pos!"=="!AI2_Y!" (%\n%
- ECHO([!Y_Pos!;!X_Pos!H[31m[7mX[0m%\n%
- Set "G_Over=[!Instructions!;1H[K[31mYou were Nommed by the AI"%\n%
- !Game_Over!%\n%
- ) %\n%
- IF "!X_Pos!"=="!X_B!" IF "!Y_Pos!"=="!Y_B!" (%\n%
- ECHO([!Y_Pos!;!X_Pos!H[31m[7mX[0m%\n%
- Set "G_Over=[!Instructions!;1H[K[31mYou Hit the Bomb"%\n%
- !Game_Over!%\n%
- ) %\n%
- IF "!X_Pos!"=="!X_Esc!" IF "!Y_Pos!"=="!Y_Esc!" (%\n%
- ECHO([!Y_Pos!;!X_Pos!H[36m[7m!Esc![0m%\n%
- ECHO([!AI_Y!;!AI_X!H[37m[7m!space![0m%\n%
- ECHO([!AI2_Y!;!AI2_X!H[37m[7m!space![0m%\n%
- Set "G_Over=[!Instructions!;1H[K[36mYou've Escaped with !Score! points"%\n%
- !Game_Over!%\n%
- ) %\n%
- ) %\n%
- ) ELSE setlocal enableDelayedExpansion ^& set argv=,
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: End Macro's
- ::: 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;%Width%H[7m[37m%space%[0m
- )
- For /L %%A IN (1,1,%Width%) DO (
- ECHO([1;%%AH[7m[37m%space%[0m
- ECHO([%hieght%;%%AH[7m[37m%space%[0m
- )
- REM Define Starting Positions
- :startpos
- Set /A "X_Pos=%random% %%%Limit_X_Max% + 2"
- Set /A "Y_Pos=%random% %%%Limit_Y_Max% + 2"
- Set /A "AI_X=%random% %%%Limit_X_Max% + 2"
- Set /A "AI_Y=%random% %%%Limit_Y_Max% + 2"
- Set /A "AI2_X=%random% %%%Limit_X_Max% + 2"
- Set /A "AI2_Y=%random% %%%Limit_Y_Max% + 2"
- IF "%X_Pos%"=="%AI_X%" IF "%Y_Pos%"=="%AI_Y%" GOTO :startpos
- IF "%X_Pos%"=="%AI2_X%" IF "%Y_Pos%"=="%AI2_Y%" GOTO :startpos
- IF "%AI2_X%"=="%AI_X%" IF "%AI2_Y%"=="%AI_Y%" GOTO :startpos
- FOR %%A in (%X_Pos%,%AI_X%,%AI2_X%) Do (
- IF %%A LSS %Limit_Axis_Min% GOTO :startpos
- IF %%A GEQ %Limit_X_Max% GOTO :startpos
- )
- FOR %%A in (%Y_Pos%,%AI_Y%,%AI2_Y%) Do (
- IF %%A LSS %Limit_Axis_Min% GOTO :startpos
- IF %%A GEQ %Limit_Y_Max% GOTO :startpos
- )
- REM Initialise Last Position variables
- Set "L_Y_Pos=%Y_Pos%"
- Set "L_X_Pos=%X_Pos%"
- Set "L_AI_X=%AI2_X%"
- Set "L_AI_Y=%AI2_Y%"
- Set "L_AI2_X=%AI_X%"
- Set "L_AI2_Y=%AI_Y%"
- ::: REM initialise Jump properties. Jump properties are calculated based on starting score, which is double the playfield Area
- Set Jump=0
- Set /A "Jump_Freq=%score% / 100"
- Set /A "Jump_Reset=%Jump_Freq% * 5"
- :bomb
- REM Define Random Position For "Bomb" as loss condition, ensuring value within 'play field'
- Set /a "Y_B=%random% %%%Limit_Y_Max% + 1"
- Set /a "X_B=%random% %%%Limit_X_Max% + 1"
- For %%A in (%Y_B%,%X_B%) Do (
- IF %%A GEQ %Limit_Y_Max% (GOTO :bomb)
- IF %%A LSS %Limit_Axis_Min% (GOTO :bomb)
- )
- IF "%X_B%"=="%X_Pos%" IF "%Y_B%"=="%Y_Pos%" (GOTO :bomb)
- ::: REM Define Random Position For "Escape" as win condition, ensuring value within 'play field', and Different to "bomb" position
- :escape
- Set /a "Y_Esc=%random% %%%Limit_Y_Max% + 1"
- Set /a "X_Esc=%random% %%%Limit_X_Max% + 1"
- For %%A in (%Y_Esc%,%X_Esc%) Do (
- IF %%A GEQ %Limit_Y_Max% (GOTO :escape)
- IF %%A LSS %Limit_Axis_Min% (GOTO :escape)
- )
- IF "%X_Esc%"=="%X_Pos%" IF %Y_Esc%=="%Y_Pos%" (GOTO :escape)
- IF "%X_Esc%"=="%X_B%" IF "%Y_Esc%"=="%Y_B%" (GOTO :escape)
- ::: 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
- Set /A Jump+=1
- %@POS% refresh
- Endlocal
- %@COL% ENEMY
- ECHO([%AI_Y%;%AI_X%H%ENEMY%
- Endlocal
- %@COL% ENEMY
- ECHO([%AI2_Y%;%AI2_X%H%ENEMY%
- Endlocal
- %@REFRESH% screen
- Endlocal
- Set /A Score-=1
- Set "L_AI_X=%AI_X%"
- Set "L_AI_Y=%AI_Y%"
- Set "L_AI2_X=%AI2_X%"
- Set "L_AI2_Y=%AI2_Y%"
- Set "L_Y_Pos=%Y_Pos%"
- Set "L_X_Pos=%X_Pos%"
- ECHO([%instructions%;1H[K[37m Escape the Ampersands [[33mW A S D[37m]
- REM :: Default switch results in a Free Move for the AI
- CHOICE /T 1 /N /C wasd0 /M "" /D 0 >nul
- CALL :Direction%ERRORLEVEL%
- Set /a AI_Move=%random% %%2 +1
- Set /a AI2_Move=%random% %%2 +1
- REM Warp the enemy characters to a new position Only if they are not on the same X axis at defined intervals
- For /L %%A in (%Jump_Freq%,%Jump_Freq%,%Jump_Reset%) Do (
- IF %Jump%==%%A (
- IF Not "%X_Pos%"=="%AI_X%" Call :Jump
- IF Not "%X_Pos%"=="%AI2_X%" Call :Jump2
- IF "%%A"=="%Jump_Reset%" (Set /A "Score+=%Jump_Reset%" && Set "Jump=0")
- )
- )
- IF Not Errorlevel 1 (
- CALL :AImove%AI_Move%
- CALL :AI2move%AI2_Move%
- )
- GOTO :Move
- ::::::::::::::::::::::::::::::::::::::::::::::::::: Script break
- :AImove1
- IF "%AI_X%"=="%X_Pos%" (
- IF %AI_Y% LSS %Y_POS% (Set /a "AI_Y+=1")
- IF %AI_Y% GTR %Y_POS% (Set /a "AI_Y-=1")
- ) else (
- IF %AI_X% LSS %X_POS% (Set /a "AI_X+=1")
- IF %AI_X% GTR %X_POS% (Set /a "AI_X-=1")
- )
- EXIT /B 0
- :AI2move1
- IF "%AI2_X%"=="%X_Pos%" (
- IF %AI2_Y% LSS %Y_POS% (Set /a "AI2_Y+=1")
- IF %AI2_Y% GTR %Y_POS% (Set /a "AI2_Y-=1")
- ) else (
- IF %AI2_X% LSS %X_POS% (Set /a "AI2_X+=1")
- IF %AI2_X% GTR %X_POS% (Set /a "AI2_X-=1")
- )
- EXIT /B 0
- :AImove2
- ::: REM Y Pos Equal Comparison Disabled to Balance AI Tracking Ability. Remove ::: In Function to Make AI more Challenging
- IF "%AI_Y%"=="%Y_Pos%" (
- IF %AI_X% LSS %X_POS% (Set /a "AI_X+=1")
- IF %AI_X% GTR %X_POS% (Set /a "AI_X-=1")
- ) else (
- IF %AI_Y% LSS %Y_POS% (Set /a "AI_Y+=1")
- IF %AI_Y% GTR %Y_POS% (Set /a "AI_Y-=1")
- )
- EXIT /B 0
- :AI2move2
- IF "%AI2_Y%"=="%Y_Pos%" (
- IF %AI2_X% LSS %X_POS% (Set /a "AI2_X+=1")
- IF %AI2_X% GTR %X_POS% (Set /a "AI2_X-=1")
- ) else (
- IF %AI2_Y% LSS %Y_POS% (Set /a "AI2_Y+=1")
- IF %AI2_Y% GTR %Y_POS% (Set /a "AI2_Y-=1")
- )
- EXIT /B 0
- REM :: AI Advance
- :Direction5
- EXIT /B 0
- REM :: Right Test If at Rightmost Limit of X axis before allowing Movement, By Increasing Y axis count by one.
- :Direction4
- IF NOT "%X_Pos%"=="%Limit_X_Max%" (Set /a "X_Pos+=1")
- EXIT /B 0
- 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")
- EXIT /B 0
- 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")
- EXIT /B 0
- 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")
- EXIT /B 0
- :Jump
- Set /A AI_X=%random% %%%Limit_X_Max% + 2
- Set /A AI_Y=%random% %%%Limit_Y_Max% + 2
- FOR %%A in (%AI_Y%) Do (
- IF %%A LSS %Limit_Axis_Min% GOTO :Jump
- IF %%A GEQ %Limit_Y_Max% GOTO :Jump
- )
- FOR %%A in (%AI_X%) Do (
- IF %%A LSS %Limit_Axis_Min% GOTO :Jump
- IF %%A GEQ %Limit_X_Max% GOTO :Jump
- )
- IF %X_Pos%==%AI_X% IF %Y_Pos%==%AI_Y% GOTO :Jump
- Exit /B 1
- :Jump2
- Set /A AI2_X=%random% %%%Limit_X_Max% + 2
- Set /A AI2_Y=%random% %%%Limit_Y_Max% + 2
- FOR %%A in (%AI2_Y%) Do (
- IF %%A LSS %Limit_Axis_Min% GOTO :Jump2
- IF %%A GEQ %Limit_Y_Max% GOTO :Jump2
- )
- FOR %%A in (%AI2_X%) Do (
- IF %%A LSS %Limit_Axis_Min% GOTO :Jump2
- IF %%A GEQ %Limit_X_Max% GOTO :Jump2
- )
- IF %X_Pos%==%AI2_X% IF %Y_Pos%==%AI2_Y% GOTO :Jump2
- Exit /B 1
- :end
- ECHO(%G_over%
- Set /A Instructions+=1
- ECHO([%Instructions%;1H[K[34m[E]xit [R]eplay
- CHOICE /N /C re /M "" >nul
- IF %ERRORLEVEL%==2 (EXIT)
- ENDLOCAL & GOTO :start
Advertisement
Add Comment
Please, Sign In to add comment