App-SweeperBot

 view release on metacpan or  search on metacpan

lib/App/SweeperBot.pm  view on Meta::CPAN

package App::SweeperBot;

# minesweeper.pl
#
# Win32::Screenshot, Win32::GuiTest, and Image::Magick are needed for this
# program. Use ActivePerl's PPM to install the first two:
#   ppm> install Win32-GuiTest
#   ppm> install http://theoryx5.uwinnipeg.ca/ppms/Win32-Screenshot.ppd
#
# The version of Image-Magick used by this code can be found at
# http://www.bribes.org/perl/ppmdir.html .  Different ImageMagick
# distributions may result in different signature codes.
#
# 20050726, Matt Sparks (f0rked), http://f0rked.com

lib/App/SweeperBot.pm  view on Meta::CPAN

    $this->click($reset_x - FOCUS_X_OFFSET ,$reset_y);
    return;
}

=head2 capture_square

	my $image = $sweeperbot->capture_square($x,$y);

Captures the square ($x,$y) of the minesweeper board.  (1,1) is
the top-left of the grid.  No checking is done to see if the square
is actually on the board.  Returns the image as an L<Image::Magick>
object.

=head3 Bugs in capture_square

On failure to capture the image, this returns an empty
L<Image::Magick> object.  This is considered a bug; in the future
C<capture_square> will throw an exception on error.

C<capture_square> depends upon calibration routines that are
currently implemented in the L</value> method; calling it before
the first call to L</value> can result in incorrect or inconsistent
results.  In future releases C<capture_square> will automatically
calibrate itself if required.

=cut

# TODO GuiTest doesn't check the Image::Magick return codes, it
# just assumes everything works.  We should consider writing our
# own code that _does_ test, since these diagnostics are very
# useful when things go wrong.

sub capture_square {
    my($this, $sx,$sy)=@_;
    our($l,$t);
    my $image=CaptureRect(
        $l+SQUARE1X+($sx-1)*SQUARE_W,
        $t+$Square1Y+($sy-1)*SQUARE_H,



( run in 0.488 second using v1.01-cache-2.11-cpan-beeb90c9504 )