Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM ::: Batch Minigame Tutorial By T3RRY
- @ECHO OFF & TITLE Escape the Ampersand Demo Game
- :start
- ::: 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.
- :: Outer Border
- Set "Hieght=30"
- Set "Width=50"
- 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 "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= "
- :: Character Displayed as Enenmy
- Set "E_C=^&"
- Set "ENEMY=[31m%E_C%"
- ::: 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 Positions
- Set "X_Pos=25"
- Set "Y_Pos=15"
- Set "AI_X=10"
- Set "AI_Y=10"
- ::: REM Initialise Last Position variables
- Set "L_Y_Pos=%Y_Pos%"
- Set "L_X_Pos=%X_Pos%"
- Set "L_AI_X=%AI_X%"
- Set "L_AI_Y=%AI_Y%"
- :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 "Escape" as win condition, ensuring value within 'play field', and Different to "bomb" position
- :escape
- Set /a "X_Esc=%random% %%48 + 1"
- Set /a "Y_Esc=%random% %%28 + 1"
- IF %X_Esc% LSS 3 (GOTO :escape)
- IF %Y_Esc% LSS 3 (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
- ECHO([31;1H[K[37m Escape the Ampersand. [[33mW A S D[37m]
- :Move
- ECHO([%L_Y_Pos%;%L_X_Pos%H[34m.
- ECHO([%L_AI_Y%;%L_AI_X%H[31m.
- CALL :refresh
- Set "L_AI_X=%AI_X%"
- Set "L_AI_Y=%AI_Y%"
- Set "L_Y_Pos=%Y_Pos%"
- Set "L_X_Pos=%X_Pos%"
- ECHO([32;1H
- 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
- CALL :Col_AI
- CALL :AImove%AI_Move%
- GOTO :Move
- :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
- :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
- 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
- ::: REM Upgrade screen display with Movement trail and New Position And test win / loss conditions (Position Comparison)
- :refresh
- IF %L_X_Pos%==%X_Pos% (
- IF %L_X_Pos%==%Y_Pos% (
- ECHO([%Y_Pos%;%X_Pos%H[36m^@
- )
- )
- ECHO([%Y_Pos%;%X_Pos%H[36m^@
- ECHO([%AI_Y%;%AI_X%H%ENEMY%
- IF %X_Pos%==%AI_X% (
- IF %Y_Pos%==%AI_Y% (
- ECHO([%Y_Pos%;%X_Pos%H[31m[7mX[0m
- Set "G_Over=[31;1H[K[31mYou were Nommed by the AI"
- GOTO :end
- )
- )
- IF %X_Pos%==%X_B% (
- IF %Y_Pos%==%Y_B% (
- ECHO([%Y_Pos%;%X_Pos%H[31m[7mX[0m
- Set "G_Over=[31;1H[K[31mYou Hit the Bomb"
- GOTO :end
- )
- )
- IF %X_Pos%==%X_Esc% (
- IF %Y_Pos%==%Y_Esc% (
- ECHO([%Y_Pos%;%X_Pos%H[36m[7m^^[0m
- ECHO([%AI_Y%;%AI_X%H[37m[7m%E_C%[0m
- Set "G_Over=[31;1H[K[36m You've Found the Escape"
- GOTO :end
- )
- )
- EXIT /B 0
- :Col_AI
- Set /a "Rand_Col=%random% %%5 + 1"
- IF %Rand_Col%==5 (Set "ENEMY=[31m%E_C%")
- IF %Rand_Col%==4 (Set "ENEMY=[33m%E_C%")
- IF %Rand_Col%==3 (Set "ENEMY=[35m%E_C%")
- IF %Rand_Col%==2 (Set "ENEMY=[37m%E_C%")
- IF %Rand_Col%==1 (Set "ENEMY=[90m%E_C%")
- EXIT /B 0
- :end
- ECHO(%G_over%
- ECHO([32;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