
Documentation.txt
Code:
BG v2.2
//ansi
BG is a tool for colorize and customize a little the cmd window.
Also have other tiny util functions.
::::: Parameters :::::
Kbd
::Wait until you press any key, and returns the ascii code.
::If an extended key was pressed, returns the second code. Example. If you pressed the up arrow (224, 72) returns 72.
_Kbd
::If any key was pressed, returns the ascii code, else return 0.
::If the key pressed is extended, it returns the second code. Example. If you pressed the up arrow (224, 72) returns 72.
Mouse
::Wait until you press left or right button into console area.
::When you press a valid button of mouse print:
:: 1|2 rowNumber colNumber
:: 1 is left button.
:: 2 is right button.
HideCursor
::hide cursor of keyboard.
ShowCursor
::show cursor of keyboard.
FontSize
::change the size of font, generally from 0 to 9. 2 is for 8x8 and 6 is for 8x12 (default).
Wait milliseconds
::do a wait or sleep in milliseconds.
Locate row column
::locate the position of cursor in row and column specified, zero index based.
Print text
::print text without new line to end. The text is interpreted how regular expression.
::please see the regular expressions in PrintColor down
PrintColor color text ...
::print text in color without new line to end. You can repeat arguments.
::the text recognize the next regular expressions:
\n print a newline
\\ print \
\Number A decimal ascii number code from 0 to 255 else the character printed is undefined.
Example: \1 print face character
Note 1: In some cases is needed usage the regular expression of Number with width of 3.
Example: \0655 is A5
Note 2: You can repeat arguments.
Example: PrintColor A "Text in color A" B "Text in color B"
::::: Colours :::::
[background]foreground
colours values is a one hexadecimal (0123456789ABCDEF) digit for each concept.
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White
bg.exe v2.2 official executable checksum:
Code:
SHA1: 271c944d702877cd90481d6a1ceee75187044350_doBG.cmd
//for make bg.exe v2.2
//generated using bhx tool
Code:
::This make BG.exe v2.2
@Echo off
Del /f /q /a bg.exe >nul 2>&1
For %%b In (
"4D534346000000009D050000000000002C000000000000000301010001000000000000"
"004300000001000311900C000000000000000098400492200062672E65786500A9A5C8"
"B15205900C5B80808D001002C900002200403400000F00DDFEDDD3B7AD39F3286C6C0F"
"1158581753A0024397D5B1355B778924BB257E77ADDBBFBBDF1D4CCBC720066CC33AC0"
"81E080CA1038085C09E597E88A24A028A4146038640E1548F772618E9C202E00003202"
"70460500EF70CFDDDAC709C2058113F0C097C86EA9865813F7C05A4601DC4B5D584C9D"
"2E6C47A9D812677565DBC53726C08889B15C44E00B1011FF7FC2FC0000000023005054"
"0E333BFBC1C8C28111908E6CD250FD1DFBFD5724325DD0134C4C30B4C460BD809C7EFB"
"2229EDB91F09FF29F89EE3092CC40171ED29921E144E9482342974224F9942C3308E9E"
"F2142975248F72DA5859C9B34646232CEBEB2ADEC7E0D8E186C4D361D0D27A8487C3BB"
"86E2A77540F5A01BECCEAA954C5AF120D8455C16E87716B7DAD2C2DBC6A64BD80B6EFA"
"51DBF3853808B1B94FEF06F85DF8FE52C61623C23A421B1E3746666E7B9E1BB2418CF7"
"657BB2643D9BBFD79E02C08F6487497DB62372199B53734E30AE6EDA1CE6A5CF44C3E4"
"A60A547CCCB047F80AAB66052ED07192B40AE5E609966A2AC9CF6996C020E12590D751"
"F52B5171F7E14602B5474CAB571AF8EED561526FC34735414536E455DA2BA6F0B1293D"
"021890CF38153BAC94C3A15C3CF393B71F3906F4CEC2796C09C16BA19F2B35BF6D7AE1"
"0461332A5FE5F0DDCC3E8BE04F41480B3EBA0CFC7E7447CEAB50D249D8FAB21DF432C1"
"7509F4B309EAAA88071406EB76BDE6776FA5DE26A95027B1ED1C162781C1A12531CBCC"
"0517506D2BD4EA00E94F402E31EB9C4BF6CDEF25F178CC76172DC75E21DDD260736821"
"CF1DC75DF34BB2D199E8DBA0DE7E1FEC5C3C657BE6AC442AA0969740AE39EE20F8CCDB"
"2624D32DE3E8498F8B83CC922D940798DE4EF9F482CEA5C572D78D7880746B5A4E8F99"
"742EC1009DC8FDE223C75D2EECD073810C1A171FFECFD387E296D478B79DD3C45C61CE"
"84BD6A77AC07BD64285ADD017E97CBE21F595F4DCD76B73A413A51F3CBA35F53E56261"
"C29BA10B46133FEFE7A8B292ECA1AFA8B0D1E8CCF367D5141D73D686846FD22436C688"
"43730B5D209CE1F6E2C3E8C60544A1E7CFAB02300CAE9D9A6945FE8EA9FA87061D8FCE"
"03960FA3B75163839C66AFCA143A5F3DA9D7B73860190E7040E0BA1FDE6DBFBCC9A8F8"
"EEFB20CB2E813A63BD7F31BB1C44E059C426214ED0CB010913842DF608F2CFFE26EDEA"
"9525A8C499B75AE0521218ECE130886B182F872CFED3ECF4804E038DCE4E9E759199AA"
"AA50AB527525DD7A6A1190B93D577F0852B4B5C0F8FCE5D044B7BEC17F5A121614AD1C"
"66F5CAEE32C05B302B78B7DF13546962680D9ABE5AD3093E5C1628DFEA7B9357A6F7ED"
"77F9927EBDD5E6DB60CB532607D6E8B1ADABAD6941ED7F4FE0EAECF38F8ABCC604FFDE"
"5B11898278A1DC28D18F49BD5BFDAD64AA972F1B9BD8DAF7A97649DD1C84DCDF45A52B"
"AA5656AEB4AFE4AD1C5D715DD153E168A55A0AF15415442BA229CC5A619772B9731F30"
"914EF930A4114EC6481490C8288E9C5972A4B630A1C8A894626A231222173AA5078722"
"17633777BA16B20A5DAF4D1BA94570ECA4B2AB4D0EE8197A3F28154F28657C8192D1FF"
"D0A3982526B8A63ADCBB07C21A159DD1A002034D06BE1AA479E00EE050D85E103AB687"
"9AE5D9D641088140331D1C139CEDAF2A24C274E3C99071E488DBE4A81E645747878510"
"C436455077B132897987D2788C4F20A11AE9F5C616AEC95204AEF1FD577E8916733DC8"
"268F29158F563F3C9A566B9F118DF40ED4743ACA911647CFD5F21DAF3BB75515963F0A"
"3992A2842097C5DE8EF335E994BB3BAAC40BFCC7CC6BE0A81275185E209529E3E9AA4A"
"45538A5E39511229D2A7071CE414B1268D54FE14D293FB8392DF1EE937B55086154641"
"E004") Do >>bg.exe (Echo.For b=1 To len^(%%b^) Step 2
Echo WScript.StdOut.Write Chr^(CByte^("&H"^&Mid^(%%b,b,2^)^)^) : Next)
Cscript /b /e:vbs bg.exe > bg.ex_
Expand -r bg.ex_ >nul
Del bg.ex_ >nul 2>&1
HexNuts.cmd
//batch game of puzzles

Code:
@Echo off
::HexNuts
::Version: 1.3.0
::Author: Carlos.
::Levels by Jordi Domenech.
::Needs BG.exe
SetLocal EnableExtensions EnableDelayedExpansion
Cls
Color 37
BG.exe HideCursor
BG.exe FontSize 8
Set "self=%~0"
Set /a "S.M.X=2,S.M.Y=2"
Set /a "g.0=32,g.1=219,g.2=15,g.3=15"
Set /a "g.4=111,g.5=2,g.6=2,g.7=32"
Set "c.0=0" & Set "c.1=77" & Set "c.2=E"
Set "c.3=A" & Set "c.4=A" & Set "c.5=E"
Set "c.6=A" & Set "c.7=33"
Set /a "r.0=5,r.2=5,r.3=6,r.4=6,r.5=0,r.6=4"
Set /a "r.b.0=2,r.b.2=0,r.b.3=4,r.b.4=3"
Set /a "g22=0,g23=-1,g32=1,g33=0"
BG.exe PrintColor 70 "HexNuts\n\n"
BG.exe PrintColor 37 "Push all nuts to storage locations.\n"
BG.exe PrintColor 37 "A nut cannot be pulled.\n\n"
BG.exe PrintColor 37 "For move: \24\25\26\27\nFor restart: Intro\n"
BG.exe PrintColor 37 "For quit press: Esc\n\nPress any key for continue ..."
BG.exe Kbd
:ChLevelM
Cls
BG.exe PrintColor 37 "Choose Level [1-170]:"
Set /a "index=0"
Set /a "level=0"
:ChLevel
BG.exe Kbd
Set "k=!ErrorLevel!"
Set /a "v=0"
For %%a in (8 13 48 49 50 51 52 53 54 55 56 57
) Do If %%a Equ !k! Set /a "v=1"
If !v! Equ 0 Goto:ChLevel
If !k! Equ 8 (If !index! Gtr 0 (
BG.exe PrintColor 37 "\8\32\8"
Set /a "index-=1,level/=10")
) Else If !k! Equ 13 (
If !level! Geq 1 If !level! Leq 170 Goto:Loop
) Else If !index! Lss 3 (
Set /a "lev_c=!level!*10+(!k!-48)"
If !lev_c! Geq 1 If !lev_c! Leq 170 (
BG.exe PrintColor 37 "\!k!"
Set /a "index+=1,level=!lev_c!")
)
Goto:ChLevel
:Loop
If !level! Gtr 170 (Cls
BG.exe PrintColor FC "Congratulations\19\nAll Levels Clear\19\n\n"
BG.exe PrintColor FC "Credits of Levels: Jordi Domenech.\n\n"
BG.exe PrintColor 0F "GAME OVER\n"
BG.exe Wait 10000
Goto:End
)
:PlayLoop
Call:Play !level!
If !ErrorLevel! Equ 1 Goto:PlayLoop
If !ErrorLevel! Equ 2 Goto:End
Set /a "s.x+=1"
BG.exe Locate !s.x! 0
BG.exe PrintColor 70 "Very Good\19"
BG.exe Wait 2000
Set /a level+=1
Goto:Loop
:Play
Set /a "n=111111111,o=11111111,p=1111111,q=111111,r=11111,s=1111"
For /f "tokens=2 delims== " %%a in (
'Findstr.exe "^^\%1^=" "!self!"') do Call :SetLvl "%%a%"
For /F "tokens=1-8 delims=," %%a in ("!l.src!") do (
Set l.d=%%h
Set /a "l.d.fw=%%a+1,l.d.w=%%a,l.d.h=%%b,l.d.g=%%c"
Set /a "l.p.v=%%d,l.p.i=%%e,l.p.r=%%f,l.p.c=%%g"
)
Cls
BG.exe PrintColor 37 "Level %1"
Set /a "s.x=S.M.X,s.y=S.M.Y"
For /L %%r in (0,1,%l.d.h%) do (
BG.exe Locate !s.x! !s.y!
For /L %%c in (0,1,%l.d.w%) do (
Set /a "l.d.i=%%r*l.d.fw+%%c"
For %%i in (!l.d.i!) do Set "l.d.v=!l.d:~%%i,1!"
For %%v in (!l.d.v!) do BG.exe PrintColor !c.%%v! \!g.%%v!
)
Set /a s.x+=1
)
:GetMov
Set /a "l.p.n.n.r=l.p.n.r=!l.p.r!,l.p.n.n.c=l.p.n.c=!l.p.c!"
BG.exe Kbd
Set /a "k=!errorlevel!"
If !k! Equ 72 (Set /a "l.p.n.n.r=(l.p.n.r-=1)-1"
) Else If !k! Equ 80 (Set /a "l.p.n.n.r=(l.p.n.r+=1)+1"
) Else If !k! Equ 75 (Set /a "l.p.n.n.c=(l.p.n.c-=1)-1"
) Else If !k! Equ 77 (Set /a "l.p.n.n.c=(l.p.n.c+=1)+1"
) Else If !k! Equ 13 (Exit/b1) Else If !k! Equ 27 (
Exit/b2) Else Goto:GetMov
If !l.p.n.r! Lss 0 Goto:GetMov
If !l.p.n.r! Gtr %l.d.h% Goto:GetMov
If !l.p.n.c! Lss 0 Goto:GetMov
If !l.p.n.c! Gtr %l.d.w% Goto:GetMov
Set /a "l.p.n.i=l.p.n.r*l.d.fw+l.p.n.c"
For %%i in (!l.p.n.i!) do Set "l.p.n.v=!l.d:~%%i,1!"
If !l.p.n.v! Equ 1 Goto:GetMov
Set /a "p=0"
If !l.p.n.v! Equ 2 set /a "p=1"
If !l.p.n.v! Equ 3 set /a "p=1"
If !p! Equ 1 (Set /a "l.p.n.n.i=l.p.n.n.r*l.d.fw+l.p.n.n.c"
For %%i in (!l.p.n.n.i!) do Set "l.p.n.n.v=!l.d:~%%i,1!"
For %%v in (1 2 3) Do If !l.p.n.n.v! Equ %%v Goto:GetMov)
Call:B !l.p.i! !r.%l.p.v%! !l.p.r! !l.p.c!
Call:B !l.p.n.i! !r.%l.p.n.v%! !l.p.n.r! !l.p.n.c!
If !p! Equ 1 (
Call:B !l.p.n.n.i! !r.b.%l.p.n.n.v%! !l.p.n.n.r! !l.p.n.n.c!
Set /a l.d.g+=g%l.p.n.v%!r.b.%l.p.n.n.v%!)
Set /a "l.p.r=!l.p.n.r!,l.p.c=!l.p.n.c!,l.p.i=!l.p.n.i!"
Set "l.p.v=!r.%l.p.n.v%!"
If !l.d.g! Equ 0 Exit/b0
Goto:GetMov
:B
Set /a "z=%1+1"
If %1 Gtr 0 (Set "l.d=!l.d:~0,%1!%2!l.d:~%z%!"
) Else Set "l.d=%2!l.d:~1!"
Set /a "row=%3+S.M.X,col=%4+S.M.Y"
BG.exe Locate !row! !col!
BG.exe PrintColor !c.%2! \!g.%2!
Goto:Eof
:End
EndLocal
Cls
Color 07
BG.exe ShowCursor
BG.exe FontSize 6
Goto:Eof
:SetLvl
Set "l.src=%~1"
Goto:Eof
::Levels
1=5,4,2,5,9,1,3,7%p%45011022011400%p%7
2=5,4,2,5,16,2,4,%r%710001112035114420%p%
3=6,4,2,6,26,3,5,%r%77104011710020%s%002617%q%
4=7,4,2,6,11,1,3,771117771116%r%00220011000400%n%
5=6,4,2,5,23,3,2,77%o%0001102000114524%o%7
6=5,5,1,5,26,4,2,7%r%71000111000110231110504%p%
7=5,5,2,5,16,2,4,%r%71004111002511120017104017%r%
8=5,5,2,5,16,2,4,%r%71000111000511122011404%p%7
9=7,4,2,5,28,3,4,%q%7714000%s%02020011041500%n%
10=5,5,2,5,8,1,2,%r%71450171002111020411100017%r%
11=5,5,3,5,8,1,2,%p%051411220411420011000%p%7
12=7,4,2,5,17,2,1,%r%7771004%r%5202001110400017%p%
13=6,4,3,5,25,3,4,%q%710204111400201100254%o%
14=5,5,2,5,13,2,1,%p%040411522%s%00017100017%r%
15=7,4,2,5,30,3,6,%q%7710400%s%40220011000035%n%
16=6,4,3,5,22,3,1,7%o%042011002201154004%o%
17=5,5,2,5,8,1,2,%p%450011132411002011000%p%7
18=5,5,3,5,19,3,1,7%p%040110200115220114104%p%
19=6,4,3,5,11,1,4,%o%4015011220201140004%o%
20=5,5,3,6,13,2,1,%p%42001162001140201100%p%77
21=5,5,3,5,26,4,2,%p%004011020411122011450%p%7
22=7,4,2,5,20,2,4,777%n%000110025201104004%n%7
23=5,5,2,5,13,2,1,%r%714001115420110200%s%00177%s%
24=6,4,3,5,19,2,5,%o%002441100025110024%o%7
25=5,5,3,6,10,1,4,%p%402611120411002011000%p%7
26=5,5,3,5,22,3,4,77%p%00110200110425110424%p%
27=5,5,3,5,8,1,2,7%p%50411420411202011000%p%7
28=5,5,2,5,8,1,2,7%r%71504111223110040110000%p%
29=5,5,2,5,9,1,3,%r%71045171042111020011100017%r%
30=5,5,2,5,13,2,1,%r%714001715021110320114000%p%
31=6,5,2,5,19,2,5,%o%000341102235110004111000117%r%77
32=5,5,3,5,9,1,3,7%p%454110221110420110000%p%
33=7,4,2,5,26,3,2,777%n%4301102020011050040%n%
34=7,4,3,5,21,2,5,%n%4042401102025011000%n%777
35=6,5,3,5,33,4,5,77%r%711000111000011432211144025%o%
36=7,4,2,5,17,2,1,%n%00040011520200%q%4017777%s%
37=7,4,3,5,20,2,4,%r%7771024%r%00252011044000%n%
38=6,5,3,5,30,4,2,7%o%0400110220011420001145100%o%
39=6,5,2,6,15,2,1,%o%43000116120011020001100100%o%
40=6,5,3,6,33,4,5,%o%00100110004211002341100026%o%
41=5,5,2,5,19,3,1,%p%4300114200115200%s%00177%s%
42=5,5,3,5,13,2,1,%p%42001152441100201100%p%77
43=6,5,3,5,15,2,1,77%o%000115200411422001140100%o%
44=6,5,3,5,10,1,3,%r%771435%s%402201142000%s%000177%r%
45=6,5,3,5,23,3,2,7%r%711404171020%s%052001104200%o%
46=6,5,3,5,30,4,2,%o%0204011002001103214111500417%q%
47=6,5,3,5,19,2,5,%r%771440%s%2002511042001100100%o%
48=7,4,3,5,30,3,6,%r%7771040%r%02020011404205%n%
49=7,4,3,5,17,2,1,%n%4240001152200011401000%n%
50=6,5,2,5,22,3,1,%r%7714001771040%s%522001103000%o%
51=6,5,3,5,9,1,2,7%q%7150441112204110002011000%o%77
52=6,5,2,5,32,4,4,77%o%0001100000110322111443517%q%7
53=6,5,2,5,22,3,1,%o%0010411002341152000%s%000177%r%
54=6,5,3,5,29,4,1,%o%04440110223011000201150%o%777
55=6,5,1,5,15,2,1,777%o%00115200011033001143000%o%
56=6,5,3,5,32,4,4,%o%004201100220%s%0041771054177%r%
57=6,5,4,5,12,1,5,7%o%00051142220114420111040017%q%7
58=6,5,2,5,19,2,5,%o%04004113220511000%s%000177%r%77
59=6,5,3,5,32,4,4,%o%00024110002411001241100150%o%
60=6,5,2,5,22,3,1,777%s%711100111000011522001143040%o%
61=6,5,3,5,16,2,2,%r%771000%s%052001102034111024417%q%
62=6,5,3,5,26,3,5,%r%771400%s%0002011422051140100%o%
63=7,5,4,5,37,4,5,%n%000100110422001124300011440250%n%
64=6,5,1,6,12,1,5,%o%000261100330110000111001117%s%777
65=6,5,4,5,30,4,2,%o%0444011042201102200111510017%q%
66=6,5,2,5,32,4,4,%o%000301100220%s%0041771054177%r%
67=6,5,3,5,17,2,3,%r%7710401771405%s%022001102040%o%
68=6,5,2,5,26,3,5,%o%0042011003301102045%s%000177%r%
69=6,5,2,5,19,2,5,777%s%711100111022511040301104000%o%
70=6,5,3,5,17,2,3,%o%400201101520110020411400%o%77
71=6,5,1,6,8,1,1,%o%62000113330011000001100100%o%
72=6,5,1,5,30,4,2,77%o%000110200011033001145100%o%
73=7,5,1,5,33,4,1,7777%n%00110300001143320011530000%n%
74=6,5,3,5,29,4,1,%q%7141001114200011020201151400%o%
75=6,5,3,5,23,3,2,77%o%400110202011052001144100%o%
76=6,5,3,5,26,3,5,77%o%00011002001143425114020%o%7
77=7,5,3,5,36,4,4,1117%r%4111001104420011000220%r%5011777%s%7
78=7,5,4,5,25,3,1,%s%7777100%q%0010401152224011020044%n%
79=6,5,3,5,22,3,1,%r%7710401771040%s%522201104000%o%
80=6,5,3,5,15,2,1,%o%040001152220%s%0401771040177%r%
81=7,5,4,5,17,2,1,77%r%71110001115220001104220011434400%n%
82=7,5,5,5,38,4,6,%p%71400001114102201144220011040025%n%
83=6,5,3,5,22,3,1,777%s%711140111022011504201100400%o%
84=6,5,2,5,8,1,1,%o%53040%s%20011020301104000%o%
85=6,5,3,5,15,2,1,%o%03000115104411022001102040%o%
86=6,5,2,5,16,2,2,%o%004001105430111022017111001777%s%
87=7,5,3,5,38,4,6,7%n%002401100430011020020%q%4517777%s%
88=6,5,2,5,19,2,5,%o%04020110103511000231100040%o%
89=7,5,4,6,34,4,2,%n%41000011400020114322101116200017%p%
90=7,5,4,5,25,3,1,7%r%7771000%r%010401152224011020044%n%
91=7,5,4,5,17,2,1,7%n%00014115202041100202411000104%n%
92=7,5,1,5,38,4,6,77%q%7714000%r%0301100002311000035%n%
93=6,5,3,5,12,1,5,%o%004251140220110410111000017%q%7
94=7,5,4,5,36,4,4,7%n%0400011002000114222%r%0454177%q%7
95=7,5,2,5,10,1,2,7%n%5300011030200114020%s%4100177%q%77
96=6,5,3,5,33,4,5,%o%04020110000011410211100425%o%
97=7,5,4,5,38,4,6,7%r%771140017714420%s%02220011400035%n%
98=7,5,2,5,17,2,1,%n%001000115010201143300011034020%n%
99=7,5,4,5,38,4,6,%n%40010011000220114410201110402517%p%
100=7,5,4,5,17,2,1,%n%020040115201041102204011001004%n%
101=7,5,4,5,28,3,4,%n%40000011401200114325201140020%n%7
102=7,5,2,5,17,2,1,7%s%7771100%r%5200001100334011020040%n%
103=6,5,4,5,12,1,5,%o%04005112224011400101100240%o%
104=7,5,3,5,17,2,1,%r%7771404%r%54220011102000171110001777%r%
105=7,5,5,5,30,3,6,%n%414020110401001100222511440020%n%
106=7,5,4,5,37,4,5,7777%n%0011020200114002201144405%n%7
107=7,5,4,5,29,3,5,%n%441000110002201140215011040020%n%
108=7,5,4,5,34,4,2,77%s%7711100%s%0240201144322011054000%n%
109=7,5,5,6,11,1,3,77%n%6200114122001104020011440020%n%
110=7,5,3,5,36,4,4,7%n%004401102340011002200110015%n%77
111=7,5,4,5,30,3,6,7%n%0444411022000110020251100%n%7777
112=7,5,3,5,28,3,4,%n%40400011042020110235%q%0017777%s%77
113=7,5,3,5,17,2,1,77%s%771114017715420%s%0202001110400017%p%
114=7,5,5,5,14,1,6,7%n%4241511410020112020201104040%n%7
115=6,5,3,5,29,4,1,%o%02040114100011022001153400%o%
116=6,5,4,5,19,2,5,%o%04020114022511021011104004%o%
117=7,5,4,5,10,1,2,7%n%5204011020200114420%s%4100177%q%77
118=7,5,5,5,22,2,6,%q%7710000%s%4412251140002011442020%n%
119=6,5,3,5,26,3,5,%q%7100401714010111002251104020%o%
120=7,5,4,5,38,4,6,%q%771400017714102%s%40220011400025%n%
121=7,5,3,5,10,1,2,7%n%5440011022000110042%s%0300177%q%77
122=7,5,4,5,9,1,1,%n%520004111222041100001411000114%n%
123=7,5,4,6,9,1,1,%n%600100111201001140202011040204%n%
124=7,5,3,5,14,1,6,%n%004025114301211103002011400000%n%
125=7,5,2,5,17,2,1,7%n%000401152020011403101110300017%p%7
126=6,5,3,5,15,2,1,%o%004001154420111022017111001777%s%
127=7,5,4,5,22,2,6,%n%00010011410205114420201104020%n%7
128=7,5,3,5,17,2,1,%n%441000115022001103001011024000%n%
129=7,5,5,6,17,2,1,%n%042420116200001141120011420000%n%
130=7,5,4,5,21,2,5,%n%440100114221501103002011400020%n%
131=7,5,2,5,20,2,4,7777%n%0011003520110043201110040017%p%
132=7,5,5,6,17,2,1,%n%42040011612210112020401104000%n%7
133=7,5,3,5,22,2,6,%q%7710400%s%0012051120002011440100%n%
134=7,5,4,5,26,3,2,%n%4420201100200011451200110040%n%77
135=7,5,3,5,25,3,1,%n%4410001104202011530200%r%0001777%r%
136=7,5,3,5,9,1,1,%n%500104110102201140200011400%n%777
137=7,5,4,5,26,3,2,7%n%02004110202441105201411001000%n%
138=6,5,3,5,29,4,1,%o%00100110022011344201150400%o%
139=7,5,3,5,28,3,4,7%n%044001100432011002520%q%0017777%s%
140=7,5,3,5,33,4,1,%n%414000114300201102120011501000%n%
141=7,5,4,5,13,1,5,%n%44015011000220114010201110402017%p%
142=7,5,4,5,17,2,1,%n%024404115011211100200011024000%n%
143=7,5,2,5,14,1,6,%n%0001051141003011002420110000%n%77
144=7,5,3,5,20,2,4,7%n%00100110025201104332011040400%n%
145=7,5,4,5,34,4,2,%n%43000011402200114210001115240017%p%
146=7,5,3,5,12,1,4,77%s%7711105%s%0022001143430011420000%n%
147=7,5,4,5,30,3,6,%q%771044017714302%s%02020511000240%n%
148=7,5,4,5,30,3,6,%n%0020041104022011041025110040%n%77
149=7,5,3,5,9,1,1,%p%71520401713031011102020011400040%n%
150=7,5,5,6,33,4,1,%n%4200001142222011401000116400%n%77
151=7,5,2,5,13,1,5,%n%0001501141002011002430110000%n%77
152=7,5,5,5,12,1,4,%q%7714005%s%4410001142222011420000%n%
153=7,5,3,5,17,2,1,%n%0300001154220011441020110000%n%77
154=7,5,4,5,21,2,5,7%n%0040011022050110442%s%0204177%q%77
155=7,5,3,5,38,4,6,%n%0004201100234411020100%s%0005177%q%
156=7,5,4,5,19,2,3,7%n%00000110251241100202411001044%n%
157=7,5,2,5,13,1,5,%p%71000351714302%s%0002001110400017%p%
158=7,5,4,5,10,1,2,%n%450020114122001144021011030000%n%
159=7,5,4,5,25,3,1,%p%7102004171442101115202001114000017%p%
160=7,5,3,5,26,3,2,7%n%004001103420011052101110240017%p%7
161=7,5,4,5,17,2,1,7777%n%00115202001143420011424000%n%
162=7,5,4,5,26,3,2,77%q%7710420%s%2044110502201104000%n%7
163=7,5,3,5,38,4,6,%n%000000114310001143022111040025%n%
164=7,5,4,5,22,2,6,7%n%000001142120511402021114400017%p%7
165=7,5,5,5,17,2,1,%q%7714004%s%5212001124042011000024%n%
166=7,5,4,5,9,1,1,%p%71500401710304211142120011420000%n%
167=7,5,3,5,36,4,4,%n%0300001100220011041020114045%n%77
168=7,5,4,5,30,3,6,%n%04002411002430110020251104%n%7777
169=7,5,4,5,36,4,4,%n%4200001143120011420021114005017%p%7
170=7,5,4,5,37,4,5,%p%71040001714222211104103011400050%n%
::
worm.cmd
//batch game of worm

Code:
@Echo Off
::Worm.
::Version: 1.2.1
::Author: Carlos.
::Needs BG.exe
SetLocal EnableExtensions EnableDelayedExpansion
Cls
BG.exe HideCursor
BG.exe FontSize 8
:Global
Set "g.0=\219" & Set "g.3=\3" & Set "g.4=\178"
Set "g.1=\254" & Set "g.2=\2"
Set "c.0=55" & Set "c.3=5E" & Set "c.4=77"
Set "c.1=2A" & Set "c.2=5A"
Set "ErrorLevel="
:Worm
Cls & Echo.Choice Speed: (1)Slow. (2)Normal. (3)Fast.
:Worm_
BG.exe Kbd
Set /a "k=%ErrorLevel%"
If !k! Equ 27 Goto:Quit
If !k! Lss 49 (Goto:Worm_) Else If !k! Gtr 51 (Goto:Worm_)
If !k! Equ 49 (Set /a Delay=15,Inc=0x64) Else If !k! Equ 50 (
Set /a Delay=8,Inc=0xC8) Else (Set /a Delay=0,Inc=0x12C)
Set "Movs=0#0#0#1"
Set /a "r=0,c=1,lk=77,Score=0"
Set "b=0000000000000000"
For /L %%+ in (1,1,20) Do Set "b=!b!00000000000000000000"
Set "fr=%g.0%"
Set "br=%g.4%"
For /L %%+ in (1,1,25) Do (
Set "fr=!fr!%g.0%"
Set "br=!br!%g.4%")
Set "br=%g.4%!br!%g.4%"
Cls
BG.exe PrintColor !c.4! !br!\n
For /L %%+ in (1,1,16) Do (
BG.exe PrintColor !c.4! !g.4! !c.0! !fr! !c.4! !g.4!\n)
BG.exe PrintColor !c.4! !br!\n
Call:UpdPos 0 0 1
Call:UpdPos 0 1 2
Call:Food
Set "p=0"
:Play
BG.exe Locate 18 0
(Echo.Score=!Score! )
Set /a "pr=r,pc=c"
Call:GKey %lk%
Set /a "lk=!ErrorLevel!"
If %lk% Equ 27 Goto:GOver
If %lk% Equ 72 Set /a "pr-=1"
If %lk% Equ 80 Set /a "pr+=1"
If %lk% Equ 75 Set /a "pc-=1"
If %lk% Equ 77 Set /a "pc+=1"
If %pr% Lss 0 (Goto:GOver) Else If %pr% Gtr 15 (Goto:GOver)
If %pc% Lss 0 (Goto:GOver) Else If %pc% Gtr 25 (Goto:GOver)
Set /a "p=pr*26+pc"
Set "pcas=!b:~%p%,1!"
If !pcas! Equ 0 Call:Dismin
If !pcas! Equ 1 (For /F "Tokens=1,2 Delims=#" %%a in (
"!Movs!") Do Set /a "q=%%a*26+%%b"
If !q! Neq !p! (Goto:GOver) Else Call:Dismin)
Call:UpdPos !r! !c! 1
Set /a "r=pr,c=pc"
Call:UpdPos !r! !c! 2
Set "Movs=!Movs!#!r!#!c!"
If !pcas! Equ 3 (Set /a "Score+=Inc"
Call:Food)
Goto:Play
:GKey
Set /a "Counter=0"
:GKey_
BG.exe _Kbd
Set /a "k=%ErrorLevel%"
If !k! Equ 0 (Set /a "Counter+=1"
If !Counter! Lss !Delay! Goto:GKey_
Exit /b %1)
If !k! Equ 72 If %1 Neq 80 Exit /b %k%
If !k! Equ 80 If %1 Neq 72 Exit /b %k%
If !k! Equ 75 If %1 Neq 77 Exit /b %k%
If !k! Equ 77 If %1 Neq 75 Exit /b %k%
If !k! Equ 27 Exit /b %k%
Exit /b %1
:Dismin
For /F "Tokens=1,2* Delims=#" %%a in ("!Movs!") Do (
Call:UpdPos %%a %%b 0
Set "Movs=%%c")
Goto:Eof
:Food
For /L %%+ in (0,1,5) Do (
Set /a "xr=!Random!%%16,yr=!Random!%%26"
Call:PFood !xr! !yr!
If ErrorLevel 1 Goto:Eof)
For /L %%a in (0,1,15) Do For /L %%b in (0,1,25) Do (
Call:PFood %%a %%b
If ErrorLevel 1 Goto:Eof)
Goto:Eof
:PFood
Set /a "fc=%~1*26+%~2"
Set "fcas=!b:~%fc%,1!"
If !fcas! Equ 0 (Call:UpdPos %1 %2 3
Exit /b 1)
Exit /b 0
:GOver
BG.exe Locate 19 0
Echo.Game Over
Set /a "Quit=-1"
Echo.Play Again ? [y/n]
:GOver_
BG.exe Kbd
Set /a "k=%ErrorLevel%"
If !k! Equ 121 Set /a "Quit=1"
If !k! Equ 89 Set /a "Quit=1"
If !k! Equ 110 Set /a "Quit=0"
If !k! Equ 78 Set /a "Quit=0"
If !Quit! Equ -1 Goto:GOver_
If !Quit! Equ 0 Goto:Quit
Goto:Worm
:UpdPos
Set /a "coord=%1*26+%2"
Set /a "x=%1+1,y=%~2+1,z=%coord%+1"
If %coord% Gtr 0 (
Set "b=!b:~0,%coord%!%3!b:~%z%!"
) Else Set "b=%3!b:~1!"
BG.exe Locate !x! !y!
BG.exe PrintColor !c.%3! !g.%3!
Goto:Eof
:Quit
EndLocal
Cls
BG.exe ShowCursor
BG.exe FontSize 6
Goto:Eof
tictactoe.cmd
//batch game of tic tac toe

Code:
@Echo Off
::Tic Tac Toe
::Version: 1.2.1
::Author: Carlos.
::Needs BG.exe
SetLocal EnableExtensions EnableDelayedExpansion
Cls
Color 07
BG.exe FontSize 8
BG.exe HideCursor
Set "b.s.-1=O" & Set "b.s.0= " & Set "b.s.1=X"
Set "b.s.c.-1=A" & Set "b.s.c.0=0" & Set "b.s.c.1=B"
Set "s.-1=0" & Set "s.0=A" & Set "s.1=B"
Set/a "e.f.1=7,e.f.7=1,e.f.3=5,e.f.5=3"
Set/a "e.c.1.a=0,e.c.1.b=2,e.c.3.a=0,e.c.3.b=6"
Set/a "e.c.5.a=2,e.c.5.b=8,e.c.7.a=6,e.c.7.b=8"
Set/a "c.d.0=8,c.d.8=0,c.d.2=6,c.d.6=2"
Set/a "c.s.0.a=1,c.s.0.b=3,c.s.2.a=1,c.s.2.b=5"
Set/a "c.s.6.a=3,c.s.6.b=7,c.s.8.a=5,c.s.8.b=7"
Set/a "c.0.x=0,c.0.y=0,c.1.x=0,c.1.y=2,c.2.x=0,c.2.y=4"
Set/a "c.3.x=2,c.3.y=0,c.4.x=2,c.4.y=2,c.5.x=2,c.5.y=4"
Set/a "c.6.x=4,c.6.y=0,c.7.x=4,c.7.y=2,c.8.x=4,c.8.y=4"
Set/a "q.x=6,q.y=35"
Set "qyies=35,36,37"
Set "all=0 1 2 3 4 5 6 7 8" & Set "center=4"
Set "corners=0 2 6 8" & Set "edges=1 3 5 7"
Set "wp="0 1 2" "3 4 5" "6 7 8" "0 3 6""
Set "wp=!wp! "1 4 7" "2 5 8" "0 4 8" "2 4 6""
Set/a "computer=ties=player=0"
:Main
BG.exe PrintColor A "Tic " B "Tac " F "Toe\n"
BG.exe PrintColor C "\"The only winning move is not to play.\"\n\n"
(Echo.Clic for Continue ...)
BG.exe Mouse > Nul 2>&1
Call:BMenu
Goto:Eof
:BMenu
Cls
Set/a "b=1"
:Play
If !b! Equ 1 (Call:BComputr) Else Call:BPlayer
(Echo.&Echo. Clic for Continue ...)
BG.exe Mouse > nul
Set/a "b*=-1"
Goto:Play
:IsCorner
For %%+ in (%corners%) Do If %~1 Equ %%+ Exit/b 1
Exit/b 0
:IsEdge
For %%+ in (%edges%) Do If %~1 Equ %%+ Exit/b 1
Exit/b 0
:IsCenter
For %%+ in (%center%) Do If %~1 Equ %%+ Exit/b 1
Exit/b 0
:BGame
For /L %%i in (0,1,8) Do Set/a "b[%%i]=0"
Set/a "Over=0"
:DrawBoard
Cls
BG.exe PrintColor !b.s.c.%b[0]%! "!b.s.%b[0]%!"
BG.exe PrintColor F "\179" !b.s.c.%b[1]%! "!b.s.%b[1]%!"
BG.exe PrintColor F "\179" !b.s.c.%b[2]%! "!b.s.%b[2]%!\n"
BG.exe PrintColor F \196\197\196\197\196\n"
BG.exe PrintColor !b.s.c.%b[3]%! "!b.s.%b[3]%!"
BG.exe PrintColor F "\179" !b.s.c.%b[4]%! "!b.s.%b[4]%!"
BG.exe PrintColor F "\179" !b.s.c.%b[5]%! "!b.s.%b[5]%!\n"
BG.exe PrintColor F \196\197\196\197\196\n"
BG.exe PrintColor !b.s.c.%b[6]%! "!b.s.%b[6]%!"
BG.exe PrintColor F "\179" !b.s.c.%b[7]%! "!b.s.%b[7]%!"
BG.exe PrintColor F "\179" !b.s.c.%b[8]%! "!b.s.%b[8]%!\n"
Call:ShowScore
BG.exe Locate !q.x! !q.y!
BG.exe PrintColor F "[Q]"
Goto:Eof
:Winner
For %%+ in (%wp%) Do ( Call:_WinnerL %%~+
If !ErrorLevel! Neq 0 Exit/b !ErrorLevel!)
Exit/b 0
:_WinnerL
If !b[%~1]! Neq 0 (
If !b[%~1]! Equ !b[%~2]! If !b[%~3]! Equ !b[%~1]! Exit/b !b[%~1]!)
Exit/b 0
:Player
If !Over! Equ 1 Exit/b -1
Set/a "k=-1"
For /f "tokens=1,2,3" %%a in ('BG.exe Mouse 2^>Nul') Do (
Set /a "clic=%%a,clic.x=%%b,clic.y=%%c"
)
If !clic! Neq 1 Goto:Player
For /L %%a in (0,1,8) Do If !c.%%a.x! Equ !clic.x! (
If !c.%%a.y! Equ !clic.y! Set /a "k=%%a"
)
If !k! Equ -1 (
If !clic.x! Equ !q.x! For %%y in (%qyies%) Do If !clic.y! Equ %%y (
BG.exe Locate 6 39 &BG.exe PrintColor F "Bye" &BG.exe Wait 1500
Exit
)
Goto:Player)
If !b[%k%]! Equ 0 (Call:UpdatePos %k% %~1
Exit/b %k%)
Goto:Player
:WinBlock
If !Over! Equ 1 Exit/b -1
If %~1 Equ 1 (Set/a "_win_value=2,_lost_value=-2"
) Else Set/a "_win_value=-2,_lost_value=2"
Call:_WinBloc %~1 %_win_value%
If !wb_return! Neq -1 (Set/a "Over=1"
) Else Call:_WinBloc %~1 %_lost_value%
Exit/b !wb_return!
:_WinBloc
Set/a "wb_return=-1"
For %%+ in (%wp%) Do (Call:_SumLine %%~+ %~2
If ErrorLevel 1 (For %%- in (%%~+) Do (If !b[%%-]! Equ 0 (
Call:UpdatePos %%- %~1
Set/a "wb_return=%%-"
Goto:_WinBloE))))
:_WinBloE
Goto:Eof
:_SumLine
Set/a "_sum_line=!b[%~1]!+!b[%~2]!+!b[%~3]!"
If !_sum_line! Equ %~4 Exit/b 1
Exit/b 0
:FullBoard
For /L %%i in (0,1,8) Do If !b[%%i]! Equ 0 Exit/b 0
Exit/b 1
:RUpdatePos
Set "av="
Set/a "cav=0"
For %%+ in (!%~1!) Do If !b[%%+]! Equ 0 (
Set "av=!av! %%+"
Set/a "cav+=1")
If !cav! Equ 0 Exit/b -1
Set/a "rp=%random% %% !cav!+1"
For /f "tokens=%rp%" %%+ in ("!av!") Do Set/a "rp=%%+"
Call:UpdatePos !rp! %~2
Exit/b !ErrorLevel!
:UpdatePos
Set/a "b[%1]=%2"
BG.exe Locate !c.%1.x! !c.%1.y!
BG.exe PrintColor !b.s.c.%2! "!b.s.%2!"
Call:Winner
Set "w=!ErrorLevel!"
If !w! Equ 1 (If !b! Equ 1 (Set/a "computer+=1"
) Else Set/a "player+=1") Else If !w! Equ -1 (
If !b! Equ 1 (Set/a "player+=1") Else Set/a "computer+=1"
) Else (Call:FullBoard
If ErrorLevel 1 Set/a "ties+=1")
Call:ShowScore
Exit/b %1
:BPlayer
Call:BGame
Call:Player 1
Set/a "maxf=!ErrorLevel!"
Call:IsCenter %maxf%
If ErrorLevel 1 (Call:RUpdatePos corners -1
For /l %%. in (1,1,4) Do (Call:Player 1
Call:WinBlock -1
If Not ErrorLevel 0 If !Over! Equ 0 (
Call:RUpdatePos corners -1
If Not ErrorLevel 0 Call:RUpdatePos all -1))
) Else (Call:UpdatePos 4 -1
Call:Player 1
Set/a "maxc=0,maxe=0,maxcd=0,c1e1oc2nd=0"
For /L %%+ in (0,1,8) Do If !b[%%+]! Equ 1 (Call:IsEdge %%+
If ErrorLevel 1 (Set/a "maxe+=1"
) Else (Call:IsCorner %%+
If ErrorLevel 1 (Set/a "maxc+=1"
For /f %%- in ("b[!c.d.%%+!]") Do (
If !%%-! Equ 1 Set/a "maxcd=1"))))
If !maxc! Equ 1 (Set/a "c1e1oc2nd=1"
) Else If !maxc! Equ 2 If !maxcd! Equ 0 Set/a "c1e1oc2nd=1"
If !c1e1oc2nd! Equ 1 (Call:WinBlock -1
If ErrorLevel 0 (Call:Player 1
Call:WinBlock -1
Set/a _res=!ErrorLevel!
If !Over! Equ 0 (If !_res! Neq -1 (Call:Player 1
Call:WinBlock -1
If !Over! Equ 0 (Call:RUpdatePos all -1
Call:Player 1)) Else (Call:RUpdatePos edges -1
Call:Player 1
Call:WinBlock -1
If !Over! Equ 0 Call:Player 1))) Else (
For %%+ in (%corners%) Do If !b[%%+]! Equ 1 (
Call:UpdatePos !c.d.%%+! -1)
Call:Player 1
Call:WinBlock -1
If ErrorLevel 0 (Call:Player 1
Call:WinBlock -1
If Not ErrorLevel 0 (Call:RUpdatePos all -1
Call:Player 1) Else If !Over! Equ 0 (Call:Player 1
Call:RUpdatePos all -1)) Else (Call:RUpdatePos corners -1
Call:Player 1
Call:WinBlock -1
If !Over! Equ 0 Call:Player 1
))) Else If !maxc! Equ 2 (Call:RUpdatePos edges -1
Call:Player 1
For /l %%+ in (1,1,2) Do (Call:WinBlock -1
If !Over! Equ 0 Call:Player 1)) Else (Set/a "eif=0"
For %%+ in (%edges%) Do (
If !b[%%+]! Equ 1 For /f %%- in ("b[!e.f.%%+!]") Do (
If !%%-! Equ 1 Set/a "eif=1"))
If !eif! Equ 1 (Call:RUpdatePos edges -1
Call:Player 1
Call:WinBlock -1
If Not ErrorLevel 0 (Set/a "p=0"
For %%+ in (%corners%) Do If !b[%%+]! Equ 0 (
For /f "tokens=1,2" %%a in (
"b[!c.s.%%+.a!] b[!c.s.%%+.b!]") Do (
If !p! Equ 0 If !%%a! Equ -1 (Call:UpdatePos %%+ -1
Set/a "p=1") Else If !p! Equ 0 If !%%b! Equ -1 (
Call:UpdatePos %%+ -1
Set/a "p=1")))
Call:Player 1
Call:WinBlock -1)) Else (
For %%+ in (%corners%) Do If !b[%%+]! Equ 0 (
For /f "tokens=1,2" %%a in (
"b[!c.s.%%+.a!] b[!c.s.%%+.b!]") Do (
If !%%a! Equ 1 If !%%b! Equ 1 Call:UpdatePos %%+ -1))
Call:Player 1
Call:WinBlock -1
If !Over! Equ 0 (Call:RUpdatePos corners -1
Call:Player 1
Call:WinBlock -1
If !Over! Equ 0 Call:Player 1))))
Exit/b
:BComputr
Call:BGame
Call:RUpdatePos corners 1
Set/a "maxf=!ErrorLevel!"
Call:Player -1
Set/a "minf=!ErrorLevel!"
Call:IsCenter %minf%
If ErrorLevel 1 (Call:UpdatePos !c.d.%maxf%! 1
Call:Player -1
Set/a "minf=!ErrorLevel!"
Call:IsCorner !minf!
If ErrorLevel 1 (
For %%+ in (%corners%) Do If !b[%%+]! Equ 0 Call:UpdatePos %%+ 1
Call:Player -1
Call:WinBlock 1) Else (For /L %%+ in (1,1,2) Do (
If !Over! Equ 0 (Call:WinBlock 1
Call:Player -1))
If !Over! Equ 0 Call:WinBlock 1)
Goto:Eof)
Call:IsCorner %minf%
If ErrorLevel 1 (Call:RUpdatePos corners 1
Call:Player -1
Call:WinBlock 1
If !Over! Equ 0 (
For %%+ in (%corners%) Do If !b[%%+]! Equ 0 Call:UpdatePos %%+ 1
Call:Player -1
Call:WinBlock 1)) Else (Call:UpdatePos 4 1
Call:Player -1
Call:WinBlock 1
If Not ErrorLevel 0 (
For %%+ in (%corners%) Do If !b[%%+]! Equ 0 (
For /f "tokens=1,2" %%a in (
"b[!c.s.%%+.a!] b[!c.s.%%+.b!]") Do (
If !%%a! Equ 0 If !%%b! Equ 0 Call:UpdatePos %%+ 1)))
Call:Player -1
Call:WinBlock 1)
Goto:Eof
:ShowScore
BG.exe Locate 7 0
(Echo. Computer Ties Player)
(Echo. !computer! !ties! !player!)
Goto:Eof
bg.c
//bg c source code
Code:
/*
* Copyright (c) 2010 Carlos. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. 2.
* Neither the name of copyright holders nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*/
/*
* BG Version 2.2
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void print_color(WORD color, CONST TCHAR * str);
void print_regular_str(CONST TCHAR * str);
void mouse();
void show_cursor(BOOL show);
HANDLE out;
int main(int argc, const char *argv[])
{
/* Initialice out here once for all functions that use it */
out = GetStdHandle(STD_OUTPUT_HANDLE);
if (argc >= 4) {
if (!_stricmp(argv[1], "PrintColor")) {
register WORD color;
register int i = 2;
register int j = 3;
for (; j < argc; i += 2, j += 2) {
color = (WORD) strtoul(argv[i], (TCHAR **) NULL, 16);
print_color(color, argv[j]);
}
} else if (!_stricmp(argv[1], "Locate")) {
SetConsoleCursorPosition(out, (COORD) {
(SHORT) strtoul(argv[3],
(TCHAR **) NULL, 10),
(SHORT) strtoul(argv[2],
(TCHAR **) NULL, 10)}
);
}
} else if (argc == 2) {
register int c;
if (!_stricmp(argv[1], "_Kbd")) {
if (_kbhit()) {
goto getKey;
}
c = 0;
goto retKey;
} else if (!_stricmp(argv[1], "Kbd")) {
getKey:c = _getch();
if (!c || 0xE0 == c) {
c = _getch();
}
retKey:return c;
} else if (!_stricmp(argv[1], "Mouse")) {
mouse();
} else if (!_stricmp(argv[1], "HideCursor")) {
show_cursor(FALSE);
} else if (!_stricmp(argv[1], "ShowCursor")) {
show_cursor(TRUE);
}
} else if (argc == 3) {
if (!_stricmp(argv[1], "Print")) {
print_regular_str(argv[2]);
} else if (!_stricmp(argv[1], "Wait")) {
Sleep((DWORD) strtoul(argv[2], (TCHAR **) NULL, 10));
} else if (!_stricmp(argv[1], "FontSize")) {
SetConsoleFont(out,
(SHORT) strtoul(argv[2], (TCHAR **) NULL, 10)
);
}
}
return 0;
}
void print_color(WORD color, CONST TCHAR * str)
{
static CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(out, &csbi);
SetConsoleTextAttribute(out, color);
print_regular_str(str);
SetConsoleTextAttribute(out, csbi.wAttributes);
}
void print_regular_str(CONST TCHAR * str)
{
register int num;
register int width_num;
register int usingRegularExpression;
usingRegularExpression = width_num = num = 0;
CONST TCHAR *mychar = str;
#define ESCAPE_SYMBOL '\\'
while (*mychar != '\0') {
if (!usingRegularExpression) {
if (!(usingRegularExpression = ESCAPE_SYMBOL == *mychar)) {
putchar(*mychar);
}
} else {
if (*mychar >= '0' && *mychar <= '9') {
if (width_num < 3) {
++width_num;
num =
(((num << 2) +
num) << 1) /* num x 10 */ +(*mychar -
'0');
} else {
putchar((TCHAR) num);
putchar(*mychar);
usingRegularExpression = width_num = num = 0;
}
} else {
if (width_num) {
putchar((TCHAR) num);
if (!
(usingRegularExpression =
*mychar == ESCAPE_SYMBOL)) {
putchar(*mychar);
}
width_num = num = 0;
} else {
switch (*mychar) {
case 'n':
putchar('\n');
break;
default:
putchar(*mychar);
break;
}
usingRegularExpression = 0;
}
}
}
++mychar;
}
if (width_num) {
putchar((TCHAR) num);
}
}
void mouse()
{
#define ENABLE_QUICK_EDIT_MODE 0x0040
static HANDLE in;
in = GetStdHandle(STD_INPUT_HANDLE);
static DWORD mode;
static DWORD readed;
static INPUT_RECORD ir[1];
GetConsoleMode(in, &mode);
SetConsoleMode(in,
(mode | ENABLE_MOUSE_INPUT) & ~ENABLE_QUICK_EDIT_MODE);
while (1) {
ReadConsoleInput(in, ir, 1, &readed);
if (MOUSE_EVENT == ir[0].EventType) {
if (FROM_LEFT_1ST_BUTTON_PRESSED ==
ir[0].Event.MouseEvent.dwButtonState
|| RIGHTMOST_BUTTON_PRESSED ==
ir[0].Event.MouseEvent.dwButtonState) {
break;
}
}
}
printf("%ld %d %d",
ir[0].Event.MouseEvent.dwButtonState,
ir[0].Event.MouseEvent.dwMousePosition.Y,
ir[0].Event.MouseEvent.dwMousePosition.X);
SetConsoleMode(in, mode);
}
void show_cursor(BOOL show)
{
static CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(out, &cci);
cci.bVisible = show;
SetConsoleCursorInfo(out, &cci);
}
Last edited by carlos on Wed 25 Apr 2012 - 01:12; edited 25 times in total

















