J
Joe C
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.
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.