Code: Select all
@echo off
setlocal EnableDelayedExpansion
set _cls=%5
set _lns=%6
:::: game Function ::::
:11aCreator
set cols=!_cls!
set /a num=%_COLS%/3
set lines=!_lns!
set winPos=%4
if defined %3 (set prev=%3)
set "sx=%1"
set "sy=%2"
set ship=!sx!-!sy!
set "!prev!= "
set /a cls=%cols%+3
set /a lns=%lines%+3
mode con cols=%cls% lines=%lns%
for /l %%a in (1 1 !num!) do (
%=== declare the positions of the asteroids ===%
set /a w=!RANDOM! %%!cols!
set /a h=!RANDOM! %%!lines!
set /a a=!RANDOM! %%!cols!
cls
set "charsp=!w!-!h!"
set "char=!a!-!w!"
set "top="
for /l %%w in (1 1 !_cls!) do (
set "top=Û!top!"
)
for /l %%h in (1 1 !_lns!) do (
for /l %%w in (1 1 !_cls!) do (
if %%w-%%h==!char! (
set "%%w-%%h=±"
) Else if not defined %%w-%%h (set "%%w-%%h= ")
set "!charsp!=Û"
set "!winPos!="
if %%w-%%h==!ship! (
set "%%w-%%h="
if !ship!==%winPos% (cls&echo You win!!&pause&exit/b 1
) Else if !ship!==!charsp! (echo You lose D:&pause&exit/b 1
) Else if !ship!==!char! (echo You took damage.&pause&exit/b 0)
)
)
)
)
cls
for /l %%h in (1 1 !_lns!) do (
if %%h == 1 (echo Û%top%Û)
set "row="
for /l %%w in (1 1 !_cls!) do (
set "row=!row!!%%w-%%h!"
)
echo Û!row!Û
)
echo Û!top!Û
:::::::::::::::::::::::::::::::::::::::::::PLAY.bat:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Code: Select all
@echo off
setlocal EnableDelayedExpansion
color 8A
title Asteroid Field
set _COLS=25
set /a _LINS=%_COLS%/2
if not exist Asteroids.bat (
echo This game requires Asteroids.bat to be in the same folder.
pause
exit
)
:menu
mode 100,30
echo _ ______ _______ _______ ______ _______ ______ ____
echo /^^\ ^|______^| ^|__ __^| ^|^|______^| ^| __ ^| ^| ___ ^| ^|__ __^| ^| __ \
echo // \\ ^| ^| ^| ^|^| ^| ^|__^| ^| ^| ^| ^| ^| ^|^| ^|^| \ \
echo /=====\ ^|======^| ^| ^| ^|^|==== ^|______^| ^| ^| ^| ^| ^|^| ^|^| ^| ^|
echo // \\ ______^| ^| ^| ^|^|______ ^|^| \\ ^| ^|___^| ^| __^|^|__ ^|^|__/ /
echo ^|^| ^|^| ^|______^| ^|_^| ^|^|______^| ^|^| \\ ^|_______^| ^|______^| ^|____/ v1.5
echo.
echo ______________
echo / \
echo ^|1. Origial ^|
echo ^|2. Impossible ^|
echo ^|3. Size ^|
echo ^| ^|
echo ^| ^|
echo \______________/
choice /c 123 /n
set coice=%ERRORLEVEL%
if %coice%==2 goto :begin2
if %coice%==3 (set /p "_COLS=Columns: "&goto:menu)
:begin
cls
echo Use WASD keys to move X to exit
set "posX=%_LINS%"
set "posY=%_LINS%"
set /a bord1=%_COLS%-1
set /a bord2=%_LINS%-1
set /a zx=%RANDOM% %%!bord1!
set /a zy=%RANDOM% %%!bord2!
set "posZ=!zx!-!zy!"
timeout -t 02
:game
if defined posX if defined posY (set prev=!posX!-!posY!)
Call Asteroids.bat !posX! !posY! !prev! !posZ! !_COLS! !_LINS!
if %ERRORLEVEL%==1 (goto :menu)
choice /c WASDXÛ /d Û /t 01>nul
set mov=%ERRORLEVEL%
if %mov% EQU 1 (
call :up
) else if %mov% EQU 2 (
call :left
) else if %mov% EQU 3 (
call :down
) else if %mov% EQU 4 (
call :right
) else if %mov% EQU 5 (
del Board.txt&&exit
) else (
goto :game
)
goto :game
exit
:begin2
cls
echo Use WASD keys to move X to exit
set "posX=%_LINS%"
set "posY=%_LINS%"
set /a zx=%RANDOM% %%!bord1!
set "posZ=!bord1!-5"
timeout -t 02
:game2
if defined posX if defined posY (set prev=!posX!-!posY!)
Call :Asteroids !posX! !posY! !prev! !posZ!
if %ERRORLEVEL%==1 goto:menu
choice /c WASDXÛ /d Û /t 01>nul
set mov=%ERRORLEVEL%
if %mov% EQU 1 (
call :up
) else if %mov% EQU 2 (
call :left
) else if %mov% EQU 3 (
call :down
) else if %mov% EQU 4 (
call :right
) else if %mov% EQU 5 (
del Board.txt&&exit
) else (
goto :game2
)
goto :game2
::::::::::::::::::::::::::::::::::::::FUNCTIONS:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:up
set /a posY=%posY%-1
goto:eof
:left
set /a posX=%posX%-1
goto:eof
:down
set /a posY=%posY%+1
goto:eof
:right
set /a posX=%posX%+1
goto:eof
:::: game Function ::::
setlocal EnableDelayedExpansion
:Asteroids
set cols=%_COLS%
set /a num=%_COLS%/3
set lines=%_LINS%
set winPos=%4
if defined %3 (set prev=%3)
set "sx=%1"
set "sy=%2"
set ship=!sx!-!sy!
set "!prev!= "
set /a cls=%cols%+3
set /a lns=%lines%+3
mode con cols=%cls% lines=%lns%
for /l %%a in (1 1 !num!) do (
set /a w=!RANDOM! %%!cols!
set /a h=!RANDOM! %%!lines!
set /a a=!RANDOM! %%!cols!
cls
set "charsp=!w!-!h!"
set "char=!a!-!w!"
set "top="
for /l %%w in (1 1 !_COLS!) do (
set "top=Û!top!"
)
for /l %%h in (1 1 !_LINS!) do (
for /l %%w in (1 1 !_COLS!) do (
if %%w-%%h==!char! (
set "%%w-%%h=±"
) Else if not defined %%w-%%h (set "%%w-%%h= ")
set "!charsp!=Û"
set "!winPos!="
if %%w-%%h==!ship! (
set "%%w-%%h="
if !ship!==%winPos% (cls&echo You win!!&pause&exit/b 1
) Else if !ship!==!charsp! (cls&echo You lose D:&pause&exit/b 1
) Else if !ship!==!char! (cls&echo You took damage.&pause&exit/b 0)
)
)
)
)
cls
for /l %%h in (1 1 !_LINS!) do (
if %%h == 1 (echo Û%top%Û)
set "row="
for /l %%w in (1 1 !_COLS!) do (
set "row=!row!!%%w-%%h!"
)
echo Û!row!Û
)
echo Û!top!Û
Please Comment Below
Also, I noticed that if you set the columns too big, then it takes forever to load each time it clears.
I thought i heard dbenham say something about using macros... but i couldn't figure it out.
if anybody could help me, it would be greatly appreciated.
Thanks,
BatNoob