Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Creating a drag and drop game to memorize

by kartik.sh89 (Initiate)
on Feb 28, 2013 at 12:18 UTC ( [id://1021046]=perlquestion: print w/replies, xml ) Need Help??

kartik.sh89 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

In my books, I have too many tables which I have to memorize. I just want to create a game so that I can memorize it through the game.

I am very new to perl. I want to create a game having a main window. It will contain two frames f1 and f2. f1 will be having a table(5*5) which is blank and don't have anything. f2 will have 5*5=25 labels. Also, two buttons in the bottom to reset and exit.

Now, what I want is to drag and drop the label in its corresponding cell of the table. If i drag a label and drop it on the correct cell then it will accept the label and it will be placed properly from f2 to f1 at correct position. But, if the label is dropped on the incorrect cell on f1, then the label will be placed back at previous place i.e. in f1.Also, reset button will place all the labels back to their respective places in f2.

I want two tabs. One will be the game and other will have all the text-fields to set the labels. Please provide me with a solution as I have already confused with the drag and drop module and canvas. Thanks in advance.

  • Comment on Creating a drag and drop game to memorize

Replies are listed 'Best First'.
Re: Creating a drag and drop game to memorize
by punch_card_don (Curate) on Feb 28, 2013 at 13:06 UTC
    Unless this homework assignment specifically requires Perl, this sounds like a good job for jQuery.




    Time flies like an arrow. Fruit flies like a banana.
      Yes. But the thing is that I want to do it through Perl. This is my first project on Perl, I am highly confused. Please suggest me how to proceed.
Re: Creating a drag and drop game to memorize
by zentara (Archbishop) on Feb 28, 2013 at 18:10 UTC
    Here is a simple starting point using the Tk canvas. I only show you how to drag the text, but setting up 2 side by side rectangular grids should be easy enough. You would setup the grids with rectangular regions with the correct text information stored in a hash, and when text is released 'in' a region, you can test for its correctness, or return the text to its starting point. Just store all text position data in a hash, and resets ought to be easy.

    For a little primer on how to make nice clickable rectangles on a Canvas, see Tk ImageMap-color-zones

    #!/usr/bin/perl use warnings; use strict; use Tk; my ($dx,$dy); my $mw = Tk::MainWindow->new; $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=> 10); my $can = $mw->Scrolled('Canvas', -height => 400, -width => 400, -bg => 'black', -scrollbars => 'osoe', -highlightthickness=>0, -borderwidth =>0, )->pack( -fill =>'both',-expand=>1); my $realcan = $can->Subwidget('scrolled'); my $text = 'This is some text'; $can->createText(50,50, -text => $text, -fill =>'yellow', -anchor => 'nw', -font => 'big', -tags=> ['move'] ); $realcan->bind('move', '<1>', sub {&mobileStart();}); $realcan->bind('move', '<B1-Motion>', sub {&mobileMove();}); $realcan->bind('move', '<ButtonRelease>', sub {&mobileStop();}); MainLoop; sub mobileStart { my $ev = $realcan->XEvent; ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); $realcan->raise('current'); print "START MOVE-> $dx $dy\n"; } sub mobileMove { my $ev = $realcan->XEvent; $realcan->move('current', $ev->x + $dx, $ev->y +$dy); ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); print "MOVING-> $dx $dy\n"; } sub mobileStop{&mobileMove;}

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      That is helpful Zentara. I am working on it. Thanks a lot.
Re: Creating a drag and drop game to memorize
by thundergnat (Deacon) on Feb 28, 2013 at 20:08 UTC
      Yes.. Sorry but I am not able to understand from where should I start. This is going to be my first Perl project. I am still struggling with the canvas and drag&drop module.

      Please suggest me some road-map that how can I achieve this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1021046]
Approved by Sinistral
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found