perlfangkuai.pl man page

tetris — A tetris game

Synopsis

perl tetris.pl

Configuration

The configuration file should be the file with name ".tetris" under HOME directory. Another option is using Tetris/Config.pm in any directory of @INC.

Here is an example of configuration:
   # -*- perl -*-
   %Config = (
       %Config,
       'start_level' => 3,
       'down_step' => 2,
       'keybindings' => {
           %{$Config{keybindings}},
           ord('j') => \&move_left,
           ord('l') => \&move_right,
           ord('k') => \&rotate,
           ord('n') => \&new_game,
       }
   );
   push @$shapes, shape_from_string(<<SHAPE);
   0 0 8 0   0 8 0 0   0 8 8 8   0 0 0 8
   0 0 8 0   0 8 8 8   0 0 8 0   0 8 8 8
   0 8 8 8   0 8 0 0   0 0 8 0   0 0 0 8
   0 0 0 0   0 0 0 0   0 0 0 0   0 0 0 0
   SHAPE

    push @$shapes, shape_from_string(<<SHAPE);
    0 0 9 0   0 0 0 0   0 0 0 0   0 0 9 0
    0 0 9 9   0 0 9 9   0 9 9 0   0 9 9 0
    0 0 0 0   0 0 9 0   0 0 9 0   0 0 0 0
    0 0 0 0   0 0 0 0   0 0 0 0   0 0 0 0
    SHAPE

The key specification can get from this script:

    use Gtk2::Gdk::Keysyms;
    use Glib qw/TRUE FALSE/;
    use Gtk2 -init;
    
    my $window = Gtk2::Window->new ('toplevel');
    $window->signal_connect (delete_event => sub { Gtk2->main_quit });
    $window->signal_connect('key-press-event' => \&show_key);
        
        my $label = Gtk2::Label->new();
        $label->set_markup("<span foreground=\"blue\" size=\"x-large\">Type something on the keyboard!</span>");
        
    $window->add ($label);
    $window->show_all;
    $window->set_position ('center-always');
    
    Gtk2->main;

    sub show_key {
        my ($widget,$event,$parameter)= @_;
        my $key_nr = $event->keyval();
        foreach my $key (keys %Gtk2::Gdk::Keysyms) {
                my $key_compare = $Gtk2::Gdk::Keysyms{$key};
                if ($key_compare == $key_nr) {
                print "'$key' => $key_nr,\n";
            }
        }
        return FALSE;
    }

Code to run after the GUI setup, add to code ref $after_load_function.

Info

2017-02-11 perl v5.24.1 User Contributed Perl Documentation