home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / frozen bubble / fbinstaller.exe / {app} / lib / fb_stuff.pm < prev    next >
Encoding:
Perl POD Document  |  2003-03-17  |  5.5 KB  |  162 lines

  1. #*****************************************************************************
  2. #
  3. #                          Frozen-Bubble
  4. #
  5. # Copyright (c) 2000, 2001, 2002, 2003 Guillaume Cottenceau <guillaume.cottenceau at free.fr>
  6. #
  7. # Sponsored by MandrakeSoft <http://www.mandrakesoft.com/>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License version 2, as
  11. # published by the Free Software Foundation.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. #
  22. #
  23. #******************************************************************************
  24.  
  25. package fb_stuff;
  26.  
  27. use fb_c_stuff;
  28. use vars qw(@ISA @EXPORT $FPATH $FBLEVELS $colourblind %POS_1P %POS_2P $BUBBLE_SIZE $ROW_SIZE
  29.             $PI);
  30. @ISA = qw(Exporter);
  31. @EXPORT = qw($FPATH $colourblind $FBLEVELS %POS_1P %POS_2P $BUBBLE_SIZE $ROW_SIZE
  32.              $PI cat_ member difference2 any even odd sqr to_bool to_int if_
  33.              fold_left output append_to_file min max backtrace basename cp_af all);
  34.  
  35. $FPATH = '.';
  36.  
  37. %POS_2P = ( p1 => { left_limit => 30,  right_limit => 286, pinguin => { x => 168, 'y' => 437 }, malus_x => 308, scoresx => 293 },
  38.         p2 => { left_limit => 354, right_limit => 610, pinguin => { x => 32,  'y' => 437 }, malus_x => 331, scoresx => 341 },
  39.         top_limit => 40,
  40.         'initial_bubble_y' => 390,
  41.         next_bubble => { x => 112, 'y' => 440 },
  42.         'malus_y' => 408,
  43.         hurry => { x => 10, 'y' => 265 },
  44.         centerpanel => { x => 153, 'y' => 190 },
  45.         scoresy => 428,
  46.       );
  47.  
  48. %POS_1P = ( p1 => { left_limit => 190, right_limit => 446, pinguin => { x => 168, 'y' => 437 }, scoresx => 180 },
  49.         init_top_limit => 44,
  50.         'initial_bubble_y' => 390,
  51.         next_bubble => { x => 112, 'y' => 440 },
  52.         'malus_y' => 408,
  53.         hurry => { x => 10, 'y' => 265 },
  54.         centerpanel => { x => 149, 'y' => 190 },
  55.         pause_clip => { x => 263, 'y' => 212 },
  56.         scoresy => 432,
  57.         compressor_xpos => 321,
  58.       );
  59.  
  60. $FBLEVELS = "$FPATH/.fblevels";
  61.  
  62. $BUBBLE_SIZE = 32;
  63. $ROW_SIZE = $BUBBLE_SIZE * 7/8;
  64.  
  65. # -=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=--
  66. # This is extracted from MDK::Common, a helper library that
  67. # extends perl capabilities for very common use when programming
  68. # perl, especially with functional style programming (but what
  69. # other style one could decently adopt? ;p).
  70. #
  71. # This extract is provided here because only Mandrake distro
  72. # includes the whole MDK::Common, so you're not obliged to
  73. # install it.
  74. #
  75. # That said, if you're a perl programmer, I strongly advice you
  76. # to have a look at this library and use it, it would
  77. # dramatically increase the efficiency and readability of your
  78. # perl programs.
  79. #
  80. # Go to google and type in "perl-MDK-Common" if interested.
  81. #
  82. $PI = 3.1415926535897932384626433832795028841972;
  83. sub cat_ { local *F; open F, $_[0] or return; my @l = <F>; wantarray ? @l : join '', @l }
  84. sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 }
  85. sub difference2 { my %l; @l{@{$_[1]}} = (); grep { !exists $l{$_} } @{$_[0]} }
  86. sub any(&@) {
  87.     my $f = shift;
  88.     $f->($_) and return 1 foreach @_;
  89.     0;
  90. }
  91. sub even { $_[0] % 2 == 0 }
  92. sub odd  { $_[0] % 2 == 1 }
  93. sub sqr  { $_[0] * $_[0] }
  94. sub to_bool { $_[0] ? 1 : 0 }
  95. sub to_int { $_[0] =~ /(\d*)/; $1 }
  96. sub if_($@) {
  97.     my $b = shift;
  98.     $b or return ();
  99.     wantarray || @_ <= 1 or die("if_ called in scalar context with more than one argument " . join(":", caller()));
  100.     wantarray ? @_ : $_[0];
  101. }
  102. sub fold_left(&@) {
  103.     my ($f, $initial, @l) = @_;
  104.     local ($::a, $::b);
  105.     $::a = $initial;
  106.     foreach $::b (@l) { $::a = &$f() }
  107.     $::a
  108. }
  109. sub output { my $f = shift; local *F; open F, ">$f" or die "output in file $f failed: $!\n"; print F foreach @_; }
  110. sub append_to_file { my $f = shift; local *F; open F, ">>$f" or die "output in file $f failed: $!\n"; print F foreach @_; 1 }
  111. sub min { my $n = shift; $_ < $n and $n = $_ foreach @_; $n }
  112. sub max { my $n = shift; $_ > $n and $n = $_ foreach @_; $n }
  113. sub backtrace {
  114.     my $s;
  115.     for (my $i = 1; caller($i); $i++) {
  116.     my ($package, $file, $line, $func) = caller($i);
  117.     $s .= "$func() called from $file:$line\n";
  118.     }
  119.     $s;
  120. }
  121. sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ }
  122. sub cp_af {
  123.     my $dest = pop @_;
  124.  
  125.     @_ or return;
  126.     @_ == 1 || -d $dest or die "cp: copying multiple files, but last argument ($dest) is not a directory\n";
  127.  
  128.     foreach my $src (@_) {
  129.     my $dest = $dest;
  130.     -d $dest and $dest .= '/' . basename($src);
  131.  
  132.     unlink $dest;
  133.  
  134.     if (-d $src) {
  135.         -d $dest or mkdir $dest, (stat($src))[2] or die "mkdir: can't create directory $dest: $!\n";
  136.         cp_af(glob_($src), $dest);
  137.     } elsif (-l $src) {
  138.         unless (symlink((readlink($src) || die "readlink failed: $!"), $dest)) {
  139.         warn "symlink: can't create symlink $dest: $!\n";
  140.         }
  141.     } else {
  142.         local *F; open F, $src or die "can't open $src for reading: $!\n";
  143.         local *G; open G, "> $dest";
  144.         local $_; while (<F>) { print G $_ }
  145.         chmod((stat($src))[2], $dest);
  146.     }
  147.     }
  148.     1;
  149. }
  150. sub all {
  151.     my $d = shift;
  152.  
  153.     local *F;
  154.     opendir F, $d or return;
  155.     my @l = grep { $_ ne '.' && $_ ne '..' } readdir F;
  156.     closedir F;
  157.  
  158.     @l;
  159. }
  160. # -=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=--
  161.  
  162.