Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Tk Game: Spell the picture (for kids)

by sanPerl (Friar)
on Feb 08, 2007 at 18:58 UTC ( #599086=CUFP: print w/replies, xml ) Need Help??

Dear All,
Here is a game for Kids. Aged 5 yrs.
The installing instructions are very easy.
1) Save this code as '', say at 'C:\Game'
2) Create a folder 'Guess_letters' inside 'C:\Game'
3) Save gif images of different pictures, in the folder ''C:\Game\Guess_letters' (for e.g. Egg, Hut, Hat, Rat .... etc.). Sorry this game can be played with max 4 lettred words.
4) While saving.. save the images with their real spelling (for e.g. egg.gif, Hut.gif, hat.gif, rat.gif...etc.)
5) Now come back to the parent folder ('C:\Game') Save two pictures 'smiley20.gif' (Smiley face) and 'smiley33.gif' (Angry Face) ..approx 40 x 40.
6) If possible (This step is optional, but it adds more fun to this game) create two wav files
(better in your voice, child like his Mom/dad's voice).
      a) 'right.wav' (Saying something like '<Name of Child> You are Correct').
      b) 'wrong.wav' (saying something like '<Name of Child> please try again').
Save these files in 'C:\Game'. If you want to skip this step then you can comment 'use Win32::Sound;' from the script.
5) run command 'perl'

This will show different images on the screen. Child has to create spelling by clicking correct alphabets. He/She has to click on 'OK?' button then. if correct, it will play 'right.wav' and show smily20.gif. If wrong it will play 'wrong.wav' and show 'smiley33.gif'.

Once again I apologize for Not commenting it correctly. I created this game in hurry for my Kid. My last post Tk: pair matching game . I received nice instructions for improvement but I am sorry I have Not implemented those here.
#!/usr/local/bin/perl -w use strict; use Tk; use Win32::Sound; use List::Util qw( shuffle ); my $mw = MainWindow->new; ################### my @filearray; opendir( DIR, 'Guess_letters' ) or die "Can't open images DIR $!"; while ( my $entry = readdir( DIR ) ) { my $type = ( -d "Guess_letters\\$entry" ) ? "dir" : "file"; push @filearray, "Guess_letters\\$entry" if (($type eq "file") + && ($entry =~ /\.gif$/)); #print "$type\t$entry\t@filearray\n"; } closedir( DIR ); #################### @filearray = shuffle (@filearray); my $next_image_num=0; my $full_image_path= $filearray[$next_image_num]; my ($image_name) = $full_image_path=~ m/\\(.*?)\z/s; my $photo= $mw->Photo(-format => 'gif', -file=> $full_image_path); my $photo_correct=$mw->Photo(-format => 'gif', -file=> 'smiley20.gif') +; my $photo_wrong=$mw->Photo(-format => 'gif', -file=> 'smiley33.gif'); my $button_image = $mw->Button(-width=>15, -height=>5, -image=> $photo +); my $button = $mw->Button(-width=>15, -height=>5); my @letters=('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L', +'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', 'RES'); my $counter=0; my $clicked_letter_col=4; my $clicked_letter_row=5; #my $nil_image =$mw->Photo(-format => 'bmp', -file=> "small\\NIL.bmp") +; my @my_spelling; my $myclicks=0; ################### for my $x (1..4) { for my $y (1..8) { print $letters[$counter],"\n"; if ($counter <= 26) { my $button_text = $mw->Button(-width=>15, -height=>5, -tex +t=>$letters[$counter], -background=> 'white', -command=>sub{click_me( +\$mw->gridSlaves(-row=>$x,-column=>$y))}); $button_text->grid(-column=>$y,-row=>$x); } $counter++; } } my $myimage= $mw->Label(-image => $photo)->grid(-row=> 5,-column => 1, + -columnspan=>7, -rowspan=>4); my $button_text = $mw->Button(-width=>15, -height=>5, -text=> 'OK?', - +command=>sub{check(\$mw->gridSlaves(-row=>4,-column=>3))}); $button_text->grid(-column=>8,-row=>6); sub click_me() { my ($clicked_button)=@_; $clicked_letter_col++; my $myletter= ${$clicked_button}->cget(-text); push @my_spelling, $myletter; my $mytext= $mw->Label(-text => $myletter)->grid(-row=> 4,-column +=> $clicked_letter_col); $myclicks++; } sub check($) { my ($result_button)=@_; my $my_spell= "@my_spelling"; $my_spell =~ s/\s+//gs; my ($correct_word) = $image_name =~ m/^(\w+)/s; $correct_word = uc($correct_word); print $correct_word; print $my_spell; if ($correct_word eq $my_spell) { print "Correct\n"; if (-e 'right.wav') { Win32::Sound::Play("right.wav"); Win32::Sound::Stop(); } $button->configure(-text=>'Hey'); ${$result_button}->configure(-image=>$photo_correct, -width=>5 +0,-height=>50); ${$result_button} -> after (450, [\&hide, ${$result_button} ]) +; call_next_image(\$myimage); } else { print "InCorrect\n"; if (-e 'wrong.wav') { Win32::Sound::Play("wrong.wav"); Win32::Sound::Stop(); } ${$result_button}->configure(-image=>$photo_wrong, -width=>50, +-height=>50); ${$result_button} -> after (600, [\&hide, ${$result_button} ]) +; } for (1..$myclicks) { $mw->Label(-text => ' ')->grid(-row=> 4,-column => $clicked_le +tter_col--); } @my_spelling = undef; $myclicks=0; } sub call_next_image() { my ($image)=@_; $next_image_num++; $full_image_path= $filearray[$next_image_num]; ($image_name) = $full_image_path=~ m/\\(.*?)\z/s;; $photo= $mw->Photo(-format => 'gif', -file=> $full_image_path); \$myimage->configure(-image => $photo); } sub hide { shift -> configure (-width => 15, -height =>5, -state=>'normal',-i +mage => undef); } sub fisher_yates_shuffle { my $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } } MainLoop;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://599086]
Approved by chargrill
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2017-01-23 10:50 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (192 votes). Check out past polls.