NAME
TUI::Gadgets::PuzzleView - view of a sliding tile puzzle
HIERARCHY
TObject
TView
TPuzzleView
SYNOPSIS
use TUI::Objects;
use TUI::Gadgets;
my $puzzle = TPuzzleView->new(
bounds => TRect->new( ax => 1, ay => 1, bx => 19, by => 5 )
);
$window->insert( $puzzle );
DESCRIPTION
TPuzzleView shows a 4x4 sliding tile puzzle with the tiles A to O and one blank. The view starts with a scrambled board. The number of moves is shown next to the label Move.
The view is selectable. A tile is moved into the blank by clicking it with the mouse or by pressing a cursor key, which moves the blank in the opposite direction. Once the tiles are in order, the view is marked as solved, and the next key press or mouse click scrambles the board again.
CONSTRUCTOR
new
my $puzzle = TPuzzleView->new( bounds => $bounds );
Creates the puzzle view and scrambles the board.
new_TPuzzleView
my $puzzle = new_TPuzzleView( $bounds );
Factory-style constructor using a positional bounds argument.
METHODS
draw
$puzzle->draw();
Draws the board, the label Move and the number of moves.
getPalette
my $palette = $puzzle->getPalette();
Returns the palette of the view.
handleEvent
$puzzle->handleEvent( $event );
Handles mouse clicks on tiles and cursor keys to move the tiles, and starts a new game after the puzzle has been solved.
moveKey
$puzzle->moveKey( $key );
Moves the tile next to the blank into the blank. The key selects the direction in which the blank moves: kbDown, kbUp, kbRight or kbLeft.
moveTile
$puzzle->moveTile( $point );
Moves the tile at the given point, in view coordinates, into the blank if it is adjacent to it.
scramble
$puzzle->scramble();
Resets the move counter and shuffles the board with random moves.
winCheck
$puzzle->winCheck();
Marks the puzzle as solved if the tiles are in order.
SEE ALSO
AUTHORS
Borland International (original Turbo Vision design)
J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)
COPYRIGHT AND LICENSE
Copyright (c) 1990-1994, 1997 by Borland International
Copyright (c) 2026 the "AUTHORS" as listed above.
This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).