#!/usr/bin/perl -w use strict; use Tk; use Tk::Canvas; use Getopt::Std; my $width = 250; my $height = 250; my $units = 10; my $background = 'blue'; my $fill = 'yellow'; my %opts = (); getopts( 'W:H:b:f:u:h', \%opts ); if( $opts{W} ) { $width = $opts{W} ; } if( $opts{H} ) { $height = $opts{H} ; } if( $opts{b} ) { $background = $opts{b} ; } if( $opts{f} ) { $fill = $opts{f} ; } if( $opts{u} ) { $units = $opts{u} ; } my $dx = $width / $units; my $dy = $height / $units; # # $selected, $jumper and $jumpy are used # by the sub selectPeg below # my $selected = 0; my $jumper = -1; my $jumpy = -1; # # the game board # my $board = new board(); # # our Tk objects # my $top = MainWindow->new(); my $can = $top->Canvas( -width => $width, -height=> $height )->pack(); placePegs( $can, $board ); MainLoop; # # draw the pegs on the board based on the information # contained in the board object # sub placePegs { my $can = shift; my $board = shift; my $hole = 0; my $tag; my $radius = 10; $tag = "HOLE_$hole"; $can->create(oval => $dx*($units/2)-$radius, $dy-$radius, $dx*($units/2)+$radius, $dy+$radius, -fill => $board->{'holes'}[$hole]->{'peg'}, -tag => [$tag] ); $can->bind( $tag, '