Jan 13, 2017 12:27 PM
(This post was last modified: Jan 13, 2017 03:23 PM by ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™.)
Hello all, dropping new function of the week I guess lol
Spoiler (Click to View)
This is a neat function, mostly for game developers, but can most certainly be useful for people who would use it as some sort of spreadsheet, etc.
Spoiler (Click to View)
You could create a lot of different type of boxes/grids with this function. You could use it to create a maze, a map for games, a spreadsheet, a puzzle, etc. It's really up to your imagination.
The below example displays :grid /F 4 "3x5"
Parameter1 = number of boxes horizontally from /A-Z
Paremeter2 = number of stacks tall these boxes are
Parameter3 = "HeightxWidth" of each individual box
Parameter4 = /s to show data of grid, and echo %ol% to do so.
Quickview: Controls W S E D R F and Q.
Q prompts for alphabet letter
Spoiler (Click to View)
This is a neat function, mostly for game developers, but can most certainly be useful for people who would use it as some sort of spreadsheet, etc.
Spoiler (Click to View)
You could create a lot of different type of boxes/grids with this function. You could use it to create a maze, a map for games, a spreadsheet, a puzzle, etc. It's really up to your imagination.
The below example displays :grid /F 4 "3x5"
Code
. A B C D E F
.#####################################
.# # # # # # #
1# # # # # # #
.# # # # # # #
.#####################################
.# # # # # # #
2# # # # # # #
.# # # # # # #
.#####################################
.# # # # # # #
3# # # # # # #
.# # # # # # #
.#####################################Parameter1 = number of boxes horizontally from /A-Z
Paremeter2 = number of stacks tall these boxes are
Parameter3 = "HeightxWidth" of each individual box
Parameter4 = /s to show data of grid, and echo %ol% to do so.
Quickview: Controls W S E D R F and Q.
Q prompts for alphabet letter
Code
@echo off & setlocal enableDelayedExpansion
mode con: lines=50 cols=70
set a=A
set j=1
set h=1
set k=1
:main
set q=
cls
echo CONTROLS: Q W S E D R F
call :grid /!a! !j! "!h!x!k!" /s
if defined ol echo %ol%
call :display
for /f "tokens=*" %%a in ('choice /c:qwsedrf /n') do (
if /i "%%~a" equ "Q" set /p "a=: "
if /i "%%~a" equ "W" set /a "j+=1"
if /i "%%~a" equ "S" if !j! geq 1 set /a "j-=1"
if /i "%%~a" equ "E" set /a "h+=1"
if /i "%%~a" equ "D" if !h! geq 2 set /a "h-=1"
if /i "%%~a" equ "R" set /a "k+=1"
if /i "%%~a" equ "F" if !k! geq 2 set /a "k-=1"
)
goto :main
:display
echo.
for /l %%a in (1,1,%gridMaxHeight%) do echo=!line[%%a]!
goto :eof
:grid
for /l %%a in (0,1,%gridMaxHeight%) do set "line[%%a]="
for %%a in (gHeight gWidth gridMaxHeight gridMaxWidth bHeight bWidth i g s d z) do set "%%a="
set "_t=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
set /a "gHeight=%2"
set "z=%1" & set "z=!z:~1,1!"
for %%a in (%_t%) do set /a "i+=1" & if /i "%%a" equ "%z%" set "gWidth=!i!"
for /f "tokens=1,2 delims=x" %%a in ("%~3") do set /a "bHeight=%%a + 1", "bWidth=%%b"
set /a "g=((gWidth * bWidth) + bWidth)", "gridMaxHeight=(gHeight * bHeight) + 1"
set /a "gridMaxWidth=g - bWidth + gWidth + 1"
for /l %%a in (1,1,%bWidth%) do set "s=!s! "
for /l %%a in (1,%bWidth%,%g%) do set "d=!d!!s!#"
for /l %%a in (1,1,%gridMaxHeight%) do set "line[%%a]=#!line[%%a]!!d:~0,-%bWidth%!"
for /l %%a in (1,1,%gridMaxWidth%) do set "line[0]=!line[0]!#"
for /l %%a iN (1,%bHeight%,%gridMaxHeight%) do set "line[%%a]=!line[0]!"
if "%~4" equ "/s" set "ol=GRID: %gridMaxHeight%x%gridMaxWidth%/[A-%z%] x %gHeight%. - %~3 boxes"
goto :eof

![[Image: 0ebdfa128106e608ece3b5d903f226f4.gif]](https://gyazo.com/0ebdfa128106e608ece3b5d903f226f4.gif)