yet another program made as exercise for my classes...
it was designed for console, but since not all systems have console palette changes
i'm presenting as gfx screen with console commands.
(this is how it looks in 'Another World' game it's "same" password as well :P)
(https://retrocoders.phatcode.net/proxy.php?request=http%3A%2F%2Fi.pinimg.com%2Foriginals%2F3a%2F66%2Fd3%2F3a66d39bc487119e50a9a58c8f274f5b.gif&hash=7bfa29727fc5e523e3618c21acd5bb81b4bc8aaa))
'#define UseRealConsole
#ifdef UseRealConsole
'#include "MyTDT/ConsoleAuxiliar.bas"
#ifndef ConsolePalette
#error " ConsolePalette(I,R,G,B) must be implemented (platform specific)"
#endif
width 80,25
const FontWid=1,FontHei=1
#else
const FontWid=8,FontHei=16
screenres 80*FontWid,25*FontHei
width 80,25
#define ConsolePalette(I,R,G,B) palette I,R,G,B
#endif
dim shared as string senha
sub DrawButton( Linha as long , Coluna as long , Texto as string , Pressed as long )
if Pressed<>0 then Pressed=-3
locate Linha+0,Coluna : color 8+Pressed,9+Pressed
print chr(219); : color 9+Pressed,7+Pressed
print chr(223,223,223,223,223,219);
locate Linha+1,Coluna : color 8+Pressed,7+Pressed
print chr(219, 32, 32, 32, 32, 32); : color 9+Pressed,8+Pressed : print chr(219);
locate Linha+2,Coluna : color 8+Pressed,7+Pressed
print chr(219,220,220,220,220,220); : color 9+Pressed,8+Pressed : print chr(219);
color 0,7+Pressed
locate Linha+1,Coluna+(5-len(Texto))\2+1 : print Texto;
end sub
function ButtonClickEvent( sBotao as string ) as long
dim as integer N
'when a button for a number is pressed add it to the password (max 6 chars)
if sBotao>="0" and sBotao<="9" then
if len(senha)<6 then senha=senha & sBotao
endif
'clear password
if sBotao="Clear" then senha=""
'verify if correct password
'if so, return true but change leds to green
if sBotao="Enter" then
if senha="239115" then '2391154
ConsolePalette(1,0,255,0)
return true
end if
senha=""
for N = 1 to 5
if (N mod 2) then
ConsolePalette(1,0,0,255)
else
ConsolePalette(1,255,0,0)
end if
sleep 100,1
next N
endif
'update LEDs state
locate 3,28 : print space(3*8);
locate 3,28 : color 1
for N = 1 to len(senha)
print chr(219,219,219,32);
next N
return false
end function
'palette for normal button
ConsolePalette(7,96,80,128)
ConsolePalette(8,64,64,80)
ConsolePalette(9,176,144,176)
'palette for pressed button
ConsolePalette(4,240,240,176)
ConsolePalette(6,208,176,112)
ConsolePalette(5,208,208,144)
'palette for indicator leds
ConsolePalette(1,0,0,255)
locate ,,0 'hide cursor
dim as long BotLin(1 to 12) = { 13, 13, 13, 9, 9, 9, 5, 5, 5, 17, 17 , 17 }
dim as long BotCol(1 to 12) = { 28, 36, 44, 28, 36, 44, 28, 36, 44, 28, 36 , 44 }
dim as string BotTxt(1 to 12) = {"1","2","3","4","5","6","7","8","9","0","Clear","Enter"}
dim as integer N
dim as integer lin,col,bot,clique
'draw starting screen
For N=1 to 12
DrawButton(BotLin(N),BotCol(N),BotTxt(N), False)
next N
'main loop for security keypad
do
getmouse col,lin,,bot
col \= FontWid : lin \= FontHei
'button pressed
if bot=1 and clique=0 then
clique=-1
For N=1 to 12
if lin>=botlin(N) and lin<(botlin(N)+3) then
if col>=botcol(N) and col<(botcol(N)+7) then
DrawButton(BotLin(N),BotCol(N),BotTxt(N), True)
clique=N
end if
end if
next N
end if
'while cliqued keep it pressed only while hovering it
'(bad practice since we're using the temporary variable N to store a semi-permanent state)
#if 1
if clique>=1 then
if lin>=botlin(clique) and lin<(botlin(clique)+3) and col>=botcol(clique) and col<(botcol(clique)+7) then
if N <> clique then
N = clique
DrawButton(BotLin(N),BotCol(N),BotTxt(N), True)
end if
else
if N = clique then
DrawButton(BotLin(N),BotCol(N),BotTxt(N), False)
N = 0
end if
end if
end if
#endif
'released button
if bot=0 and clique<>0 then
if clique>=1 then
N = clique
DrawButton(BotLin(N),BotCol(N),BotTxt(N), False)
locate 1,1: color 7,0 : print space(32)
if lin>=botlin(N) and lin<(botlin(N)+3) then
if col>=botcol(N) and col<(botcol(N)+7) then
'process cliqued button and if it return true
'it means that keylock was unblocked, so exit our main loop
if ButtonClickEvent( BotTxt(N) ) <> 0 then exit do
end if
end if
end if
clique=0
end if
loop
sleep 1000,1 : color 10,2 : cls
print "Welcome professor!"
sleep