Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- title Icarus Challenge 2
- setlocal enabledelayedexpansion
- ::This script is based on assigning a variable to every position in the box
- ::m#1#2 #1 is the vertical assignment and #2 is the horizontal assignment
- :topset
- set /p size=What size box would you like? Please list in #x# format (41x16):
- for /f "delims=x tokens=1,2" %%a in ("%size%") do (
- set hori=%%a
- set verti=%%b
- )
- if "%verti%"=="" goto topset
- ::This section creates the original box
- for /l %%a in (0,1,%verti%) do (
- for /l %%b in (0,1,%hori%) do (
- set ml%%ac%%b=
- if "%%a" == "0" set ml%%ac%%b=#
- if "%%a" == "%verti%" set ml%%ac%%b=#
- if "%%b" == "0" set ml%%ac%%b=#
- if "%%b" == "%hori%" set ml%%ac%%b=#
- )
- )
- ::Max determines the maximum number of characters that the box can hold
- set /a max=(%hori% * %verti%) - ((2*%hori) + (2* %verti%) - 2)
- set /p input= Please enter the text that you would like to see displayed in the box:
- ::This for loop determines the length of the string entered up to the max characters
- that the box can hold.
- for /l %%c in (0,1,%max%) do (
- if "!input:~%%c,1!"=="" set total=%%c &goto next1
- )
- :next1
- ::mlength is the maximum length for one line
- set /a mlength=%hori% - 2
- ::checks if the total length of the string is longer than one line. If so, need to
- calculate multi line box.
- if %total% GTR %mlength% goto multi
- ::This section determines how much space is left on each end of the line.
- set text=%input%
- set /a verti1=%verti% / 2
- :addin
- set /a left=%mlength% - %total%
- set /a end1=(%left%)/ 2
- set /a end2=%mlength% - ((%left%) / 2)
- set /a temp=((%left% + 3) / 2 ) - 1
- if %end1% LSS %temp% set /a end1=%end1% + 1
- ::Adds spaces in front of the text to enter based on how many spaces on the left.
- for /l %%h in (0,1,%end1%) do (
- set text= !text!
- )
- ::sets the variables used to build the box to the text
- :setvars
- for /l %%e in (0,1,%end2%) do (
- set ml%verti1%c%%e=!text:~%%e,1!
- )
- set ml%verti1%c0=#
- if "%switch9%"=="Y" goto wrap
- goto show
- ::Builds the variables to display the box
- :show
- for /l %%f in (0,1,%verti%) do (
- for /l %%g in (0,1,%hori%) do (
- set line%%f=!line%%f!!ml%%fc%%g!
- )
- echo !line%%f!
- )
- pause>nul
- exit
- ::The multi section determines the vertical centering and will determine the length
- of text on each line. the first part checks if the total height of the string
- exceeds the max height of the box chosen
- :multi
- set /a vtot=(%total% / %mlength%) + 1
- set /a mheight=%verti% - 2
- if %vtot% GTR %mheight% set vtot=%mheight% &set switch3=1
- ::the next part parses the input into multiple variables.
- set atemp=1
- :loopfor
- for /f "tokens=%atemp%" %%a in ("%input%") do (
- set string%atemp%=%%a
- )
- if "!string%atemp%!"=="" goto next2
- set /a atemp=%atemp% + 1
- goto loopfor
- :next2
- set /a atemp=%atemp% - 1
- set /a btemp=1
- set /a ctempmin=1
- set /a ctempmax=0
- set /a ctempc=1
- set switch8=
- ::line creation sets up the text for each line to be pasted into the box
- :linecreation
- if "!string%ctempc%!" == "" set switch8=end&goto skip4
- set linet%btemp%=!linet%btemp%! !string%ctempc%!
- :skip4
- for /l %%c in (0,1,%max%) do (
- if "!linet%btemp%:~%%c,1!"=="" set total=%%c &goto next4
- )
- :next4
- if %ctempc% == %ctempmin% set /a total=%total% - 1
- if %ctempc% == %ctempmin% set linet%btemp%=!linet%btemp%:~1,%total%!
- if "%switch8%"=="end" goto linecomplete
- if %total% gtr %mlength% goto linecomplete
- set /a ctempc+=1
- goto linecreation
- :linecomplete
- set /a ctempmax=%ctempc% - 1
- for /l %%j in (%ctempmin%,1,%ctempmax%) do (
- set lineu%btemp%=!lineu%btemp%! !string%%j!
- )
- for /l %%c in (0,1,%max%) do (
- if "!lineu%btemp%:~%%c,1!"=="" set total=%%c &goto next6
- )
- :next6
- set /a total-=1
- set /a total%btemp%=%total%
- set lineu%btemp%=!lineu%btemp%:~1,%total%!
- if "%switch8%"=="end" goto finish
- set /a btemp+=1
- set /a ctempmin=%ctempmin%+%ctempmax%
- goto linecreation
- ::All lines and their lengths have been set and now it's time to pass them through
- to the box. Switch variables are used to differentiate between standard send 1 line
- box use and multi line use.
- :finish
- set switch9=Y
- set bc=1
- set /a vertileft=(%verti% - 2) - %btemp%
- set /a vend1=(%vertileft%)/ 2
- set /a vend2=(%verti% - 2) - ((%vertileft%) / 2)
- set /a vtemp=((%vertileft% + 3) / 2 ) - 1
- if %vend1% LSS %vtemp% set /a vend1=%vend1% + 1
- echo %vend1% %vend2% %vtemp%
- set verti1=%vend1%
- set total=!total%bc%!
- goto addin
- :wrap
- if "%bc%"=="%btemp%" goto show
- set /a verti1+=1
- set /a bc+=1
- set total=!total%bc%!
- goto addin
- :multitype2
Advertisement
Add Comment
Please, Sign In to add comment