Array of objects.

Discussion in 'Perl' started by Joe C, Jun 13, 2004.

  1. Joe C

    Joe C Guest

    I am trying to convert a program in C++ to Perl so that I can create a
    GUI with TK. My problem is that the program contains a grid of objects.


    I want to creat the equivelant of:

    space map[x][y];

    I have to create the space object then make a grid of it.

    map.func.new(char).

    I will post segments of what I have and hope I can get some advice.
    package Space;
    sub new{
    my $space = {
    spc => $_[0],
    chr => $chr,
    mon => $monst,
    wpn => @wpn,
    arm => @arms

    };

    print "$space->{spc}";

    bless $space, 'Space';
    return $space;
    }

    sub prtloc{

    print ".";

    if ($space->{chr} != 0){
    print "$space->{chr}->{sym}";
    return;
    }
    if ($space->{mon} != 0){
    print "$space->{chr}->{sym}";
    return;
    }
    if ($space->{wpn} != 0){
    print "$space->{wpn->[0]}->{sym}";
    return;
    }
    if ($space->{mon} != 0){
    print "$space->{arm->[0]}->{sym}";
    return;
    }
    print "$space->{spc}";

    }
    ********************************************************************88
    for ($l1=0; $l1 != $x; $l1++){
    for ($l2=0; $l2 != $y; $l2++){
    $grid[$l1][$l2] = Space::new($map1[$l1][$l2]);
    }
    }

    $map = {
    level => \@grid
    };
    **************************************************************8

    bless $map, 'Map';
    return $map;
    sub dmap { #draws the map 3x3 grid.
    my ($grd, $char) = @_;
    my $l;
    my $l1;
    for $l (($char->{y})-1 .. ($char->{y})+1) {
    for $l1 (($char->{x})-1 .. ($char->{x})+1) {
    $grd->[$l1][$l2]->{Space}->prtloc();
    } print "\n";
    }
    }


    Let me know if I need to add any any other comments or explanations.
     
    Joe C, Jun 13, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    385
    Victor Bazarov
    Mar 29, 2005
  2. John Machin
    Replies:
    2
    Views:
    289
    Reinhold Birkenfeld
    Sep 3, 2005
  3. 7stud
    Replies:
    11
    Views:
    700
    Dennis Lee Bieber
    Mar 20, 2007
  4. markspace
    Replies:
    1
    Views:
    388
    markspace
    Jun 25, 2009
  5. Roedy Green
    Replies:
    1
    Views:
    445
    Roedy Green
    Jun 25, 2009
Loading...

Share This Page