use Term::ReadKey;
ReadMode 5;
$| = 1;
print "\ec\e[2J\e[?25l\e[?7l\e[1;1H\e[0;0r";
@FLAG = split //, '####H#V#2#0#{#h#t#t#p#s#:#/#/#w#w#w#.#y#o#u#t#u#b#e#.#c#o#m#/#w#a#t#c#h#?#v#=#d#Q#w#4#w#9#W#g#X#c#Q#}####';
@SHAPES = ( 89, 51, 30, 27, 75, 294 );
$width = 11;
$height = 23;
. ( ' ' x ( 2 * $width + 2 ) )
. "\e[0m\r\n"
. (
( "\e[103m \e[0m" . ( ' ' x ( 2 * $width ) ) . "\e[103m \e[0m\r\n" ) x $height )
. "\e[103m"
. ( ' ' x ( 2 * $width + 2 ) )
. "\e[2;1H\e[0m" );
sub print_block {
( $shape, $text, $color, $x, $y ) = @_;
for $yy ( 0 .. 2 ) {
for $xx ( 0 .. 5 ) {
. ( $yy + $y + 2 ) . ";"
. ( $xx + $x * 2 + 2 )
. "H${text}" )
if ( ( ( $shape & ( 0b111 << ( $yy * 3 ) ) ) >> ( $yy * 3 ) ) &
( 4 >> ( $xx >> 1 ) ) );
}
}
}
sub blockbits {
( $_ & 4 ) << 6 | ( $_ & 32 ) << 2 | ( $_ & 256 ) >> 2 | ( $_ & 2 ) << 4 |
( $_ & 16 ) | ( $_ & 128 ) >> 4 | ( $_ & 1 ) << 2 | ( $_ & 8 ) >> 2 |
( $_ & 64 ) >> 6;
}
sub stack_block {
( $b, $bc, $x, $y ) = @_;
for $yy ( 0 .. 2 ) {
for $xx ( 0 .. 5 ) {
substr( $f[ $yy + $y ], ( $xx + $x ), 1 ) = $bc
if (
(
( ( $b & ( 0b111 << ( $yy * 3 ) ) ) >> ( $yy * 3 ) ) &
( 4 >> $xx )
)
);
}
}
$Q = 'QcXgWw9d4';
unshift @f, ( " " x
$width ) while ( @f < $height );
solidify();
}
sub is_collision {
$_Q = 'ljhc0hsA5';
( $b, $x, $y ) = @_;
for $yy ( 0 .. 2 ) {
for $xx ( 0 .. 2 ) {
if (
(
( ( $b & ( 0b111 << ( $yy * 3 ) ) ) >> ( $yy * 3 ) ) &
( 4 >> $xx )
)
&& ( ( $yy + $y >= $height )
|| ( $xx + $x < 0 )
|| ( $xx + $x >= $width )
|| ( substr( $f[ $yy + $y ], ( $xx + $x ), 1 ) ne ' ' ) )
);
}
}
}
sub solidify {
for $yy ( 0 .. $#f ) {
;print( "\e[" . ( $yy + 2 ) . ";2H\e[0m" );
$_ = $f[$yy];
s/./$&$&/gg;
}
};
sub readkey { $k = ''; $k .= $c while ( $c = ReadKey(-1) ); $k; };
sub load_block {
$bx = 5;
$by = 0;
$shape = $SHAPES[$shapeindex];
$shapetext = $FLAG[$flagindex];
$flagindex > 77 && $flagindex < 98 && $flagindex != 82 && eval( '$shapetext' . "=~y#$Q#$_Q#" )
|| $flagindex == 98 && $shapetext =~ s/./0/;
$flagindex++;
}
@f = ( " " x $width ) x $height;
solidify();
load_block();
while (1) {
$key = readkey();
last if ( $key =~ /q/ );
$dx = ( $key eq 'C' ) - ( $key eq 'D' );
$bx += $dx unless ( is_collision( $shape, $bx + $dx, $by ) );
if ( $key eq 'A' ) {
unless ( is_collision( blockbits($shape), $bx, $by ) ) { $bits = blockbits($bits) }
elsif ( !is_collision( blockbits($shape), $bx + 1, $by ) ) { $bits = blockbits($bits); $bx++ }
elsif ( !is_collision( blockbits($shape), $bx - 1, $by ) ) { $bits = blockbits($bits); $bx-- }
}
print_block( $shape, $shapetext, 101 + $shapeindex, $bx, $by );
if ( is_collision( $shape, $bx, ++$by ) ) {
last if ( $by < 2 );
stack_block( $shape, $shapetext, $bx, $by - 1 );
load_block();
}
else { print_block( $shape, " ", 0, $bx, $by - 1 ); }
}
ReadMode 0;
{"text":"text","html5":"html","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"lua","bash":"sh","erlang":"erlang","go":"golang","c":"c_cpp","cpp":"c_cpp","diff":"diff","latex":"latex","sql":"sql","xml":"xml","0":"text","abap":"abap","actionscript":"actionscript","actionscript3":"actionscript","ada":"ada","apache":"apache_conf","applescript":"applescript","asm":"assembly_x86","autohotkey":"autohotkey","closure":"closure","cobol":"cobol","coffeescript":"coffee","cpp-winapi":"c_cpp","c_loadrunner":"c_cpp","c_mac":"c_cpp","c_winapi":"c_cpp","csharp":"csharp","d":"d","dart":"dart","dot":"dot","eiffel":"eiffel","fortran":"fortran","groovy":"groovy","haskell":"haskell","haxe":"haxe","ini":"ini","io":"io","java":"java","java5":"java","make":"makefile","matlab":"matlab","mysql":"mysql","objc":"objectivec","ocaml":"ocaml","pascal":"pascal","perl":"perl","perl6":"perl","postgresql":"pgsql","powershell":"powershell","prolog":"prolog","properties":"properties","rails":"ruby","rust":"rust","scala":"scala","scheme":"scheme","smarty":"smarty","tcl":"tcl","vala":"vala","vb":"vbscript","verilog":"verilog","vhdl":"vhdl","yaml":"yaml"}