1PERLTETRIS(1) User Contributed Perl Documentation PERLTETRIS(1)
2
3
4
6 tetris - A tetris game
7
9 perl tetris.pl
10
12 The configuration file should be the file with name ".tetris" under
13 HOME directory. Another option is using Tetris/Config.pm in any
14 directory of @INC.
15
16 Here is an example of configuration:
17 # -*- perl -*-
18 %Config = (
19 %Config,
20 'start_level' => 3,
21 'down_step' => 2,
22 'keybindings' => {
23 %{$Config{keybindings}},
24 ord('j') => \&move_left,
25 ord('l') => \&move_right,
26 ord('k') => \&rotate,
27 ord('n') => \&new_game,
28 }
29 );
30 push @$shapes, shape_from_string(<<SHAPE);
31 0 0 8 0 0 8 0 0 0 8 8 8 0 0 0 8
32 0 0 8 0 0 8 8 8 0 0 8 0 0 8 8 8
33 0 8 8 8 0 8 0 0 0 0 8 0 0 0 0 8
34 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
35 SHAPE
36
37 push @$shapes, shape_from_string(<<SHAPE);
38 0 0 9 0 0 0 0 0 0 0 0 0 0 0 9 0
39 0 0 9 9 0 0 9 9 0 9 9 0 0 9 9 0
40 0 0 0 0 0 0 9 0 0 0 9 0 0 0 0 0
41 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
42 SHAPE
43
44 The key specification can get from this script:
45
46 use Gtk2::Gdk::Keysyms;
47 use Glib qw/TRUE FALSE/;
48 use Gtk2 -init;
49
50 my $window = Gtk2::Window->new ('toplevel');
51 $window->signal_connect (delete_event => sub { Gtk2->main_quit });
52 $window->signal_connect('key-press-event' => \&show_key);
53
54 my $label = Gtk2::Label->new();
55 $label->set_markup("<span foreground=\"blue\" size=\"x-large\">Type something on the keyboard!</span>");
56
57 $window->add ($label);
58 $window->show_all;
59 $window->set_position ('center-always');
60
61 Gtk2->main;
62
63 sub show_key {
64 my ($widget,$event,$parameter)= @_;
65 my $key_nr = $event->keyval();
66 foreach my $key (keys %Gtk2::Gdk::Keysyms) {
67 my $key_compare = $Gtk2::Gdk::Keysyms{$key};
68 if ($key_compare == $key_nr) {
69 print "'$key' => $key_nr,\n";
70 }
71 }
72 return FALSE;
73 }
74
75 Code to run after the GUI setup, add to code ref $after_load_function.
76
77
78
79perl v5.36.0 2022-07-22 PERLTETRIS(1)