GL1TCH3D

Box full

Jan 18th, 2016
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. @echo off
  2. title Icarus Challenge 2
  3. setlocal enabledelayedexpansion
  4. ::This script is based on assigning a variable to every position in the box
  5. ::m#1#2 #1 is the vertical assignment and #2 is the horizontal assignment
  6.  
  7.  
  8. :topset
  9. set /p size=What size box would you like? Please list in #x# format (41x16):
  10. for /f "delims=x tokens=1,2" %%a in ("%size%") do (
  11. set hori=%%a
  12. set verti=%%b
  13. )
  14. if "%verti%"=="" goto topset
  15.  
  16. ::This section creates the original box
  17. for /l %%a in (0,1,%verti%) do (
  18. for /l %%b in (0,1,%hori%) do (
  19. set ml%%ac%%b=
  20. if "%%a" == "0" set ml%%ac%%b=#
  21. if "%%a" == "%verti%" set ml%%ac%%b=#
  22. if "%%b" == "0" set ml%%ac%%b=#
  23. if "%%b" == "%hori%" set ml%%ac%%b=#
  24. )
  25. )
  26.  
  27. ::Max determines the maximum number of characters that the box can hold
  28.  
  29. set /a max=(%hori% * %verti%) - ((2*%hori) + (2* %verti%) - 2)
  30.  
  31.  
  32. set /p input= Please enter the text that you would like to see displayed in the box:
  33.  
  34.  
  35.  
  36. ::This for loop determines the length of the string entered up to the max characters
  37.  
  38. that the box can hold.
  39.  
  40. for /l %%c in (0,1,%max%) do (
  41. if "!input:~%%c,1!"=="" set total=%%c &goto next1
  42. )
  43.  
  44.  
  45.  
  46. :next1
  47.  
  48. ::mlength is the maximum length for one line
  49.  
  50.  
  51. set /a mlength=%hori% - 2
  52.  
  53. ::checks if the total length of the string is longer than one line. If so, need to
  54.  
  55. calculate multi line box.
  56.  
  57.  
  58. if %total% GTR %mlength% goto multi
  59.  
  60. ::This section determines how much space is left on each end of the line.
  61.  
  62. set text=%input%
  63. set /a verti1=%verti% / 2
  64.  
  65. :addin
  66.  
  67.  
  68. set /a left=%mlength% - %total%
  69. set /a end1=(%left%)/ 2
  70. set /a end2=%mlength% - ((%left%) / 2)
  71. set /a temp=((%left% + 3) / 2 ) - 1
  72. if %end1% LSS %temp% set /a end1=%end1% + 1
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. ::Adds spaces in front of the text to enter based on how many spaces on the left.
  80.  
  81. for /l %%h in (0,1,%end1%) do (
  82. set text= !text!
  83. )
  84.  
  85. ::sets the variables used to build the box to the text
  86.  
  87.  
  88.  
  89.  
  90. :setvars
  91. for /l %%e in (0,1,%end2%) do (
  92. set ml%verti1%c%%e=!text:~%%e,1!
  93. )
  94. set ml%verti1%c0=#
  95. if "%switch9%"=="Y" goto wrap
  96. goto show
  97.  
  98. ::Builds the variables to display the box
  99.  
  100. :show
  101. for /l %%f in (0,1,%verti%) do (
  102. for /l %%g in (0,1,%hori%) do (
  103. set line%%f=!line%%f!!ml%%fc%%g!
  104. )
  105. echo !line%%f!
  106. )
  107.  
  108. pause>nul
  109. exit
  110.  
  111. ::The multi section determines the vertical centering and will determine the length
  112.  
  113. of text on each line. the first part checks if the total height of the string
  114.  
  115. exceeds the max height of the box chosen
  116.  
  117. :multi
  118. set /a vtot=(%total% / %mlength%) + 1
  119. set /a mheight=%verti% - 2
  120. if %vtot% GTR %mheight% set vtot=%mheight% &set switch3=1
  121.  
  122. ::the next part parses the input into multiple variables.
  123.  
  124. set atemp=1
  125. :loopfor
  126. for /f "tokens=%atemp%" %%a in ("%input%") do (
  127. set string%atemp%=%%a
  128. )
  129. if "!string%atemp%!"=="" goto next2
  130. set /a atemp=%atemp% + 1
  131. goto loopfor
  132.  
  133.  
  134.  
  135. :next2
  136. set /a atemp=%atemp% - 1
  137.  
  138. set /a btemp=1
  139. set /a ctempmin=1
  140. set /a ctempmax=0
  141. set /a ctempc=1
  142. set switch8=
  143.  
  144. ::line creation sets up the text for each line to be pasted into the box
  145.  
  146. :linecreation
  147. if "!string%ctempc%!" == "" set switch8=end&goto skip4
  148. set linet%btemp%=!linet%btemp%! !string%ctempc%!
  149.  
  150. :skip4
  151. for /l %%c in (0,1,%max%) do (
  152. if "!linet%btemp%:~%%c,1!"=="" set total=%%c &goto next4
  153. )
  154.  
  155.  
  156.  
  157. :next4
  158.  
  159. if %ctempc% == %ctempmin% set /a total=%total% - 1
  160. if %ctempc% == %ctempmin% set linet%btemp%=!linet%btemp%:~1,%total%!
  161.  
  162. if "%switch8%"=="end" goto linecomplete
  163. if %total% gtr %mlength% goto linecomplete
  164.  
  165. set /a ctempc+=1
  166. goto linecreation
  167.  
  168.  
  169.  
  170. :linecomplete
  171. set /a ctempmax=%ctempc% - 1
  172.  
  173. for /l %%j in (%ctempmin%,1,%ctempmax%) do (
  174. set lineu%btemp%=!lineu%btemp%! !string%%j!
  175. )
  176.  
  177.  
  178.  
  179. for /l %%c in (0,1,%max%) do (
  180. if "!lineu%btemp%:~%%c,1!"=="" set total=%%c &goto next6
  181. )
  182.  
  183. :next6
  184. set /a total-=1
  185. set /a total%btemp%=%total%
  186. set lineu%btemp%=!lineu%btemp%:~1,%total%!
  187. if "%switch8%"=="end" goto finish
  188. set /a btemp+=1
  189. set /a ctempmin=%ctempmin%+%ctempmax%
  190. goto linecreation
  191.  
  192.  
  193. ::All lines and their lengths have been set and now it's time to pass them through
  194.  
  195. to the box. Switch variables are used to differentiate between standard send 1 line
  196.  
  197. box use and multi line use.
  198.  
  199. :finish
  200. set switch9=Y
  201. set bc=1
  202. set /a vertileft=(%verti% - 2) - %btemp%
  203. set /a vend1=(%vertileft%)/ 2
  204. set /a vend2=(%verti% - 2) - ((%vertileft%) / 2)
  205. set /a vtemp=((%vertileft% + 3) / 2 ) - 1
  206. if %vend1% LSS %vtemp% set /a vend1=%vend1% + 1
  207. echo %vend1% %vend2% %vtemp%
  208. set verti1=%vend1%
  209. set total=!total%bc%!
  210. goto addin
  211.  
  212. :wrap
  213. if "%bc%"=="%btemp%" goto show
  214. set /a verti1+=1
  215. set /a bc+=1
  216. set total=!total%bc%!
  217. goto addin
  218.  
  219. :multitype2
Advertisement
Add Comment
Please, Sign In to add comment