evocation
08-02-2003, 03:26 AM
Try running this code in perl, making sure you have an ANSI driver installed first...ANSI.SYS might work.
This code has been tested on ActivePERL under WINDOWS ME and works fine. I am only after advice on how to improve the speed.
here is the first part of the code:
#!c:\perl\bin\perl.exe
use Win32::Console; #Windows specific
sub drawscreen
{
print "\e[1;1H"; # ANSI Escape Seq - requires Windows 95 ANSI.SYS driver to be installed
my $a;
my $b;
$a = 0;
$b = 0;
while($a<16)
{
while($b<64)
{
if($s_map[$a][$b] eq "empty")
{
print " ";
}
else
{
print " ";
}
$b++;
}
print "\n";
$a++;
$b = 0;
}
print "\e[17;1" . "H";
print "\e[K";
print " EN: ";
print "\e[17;6" . "H";
print "$ps_energy";
print "\e[17;11" . "H";
print " HP: ";
print "\e[17;16" . "H";
print int($ps_hpnow) . "/$ps_hpmax";
print "\e[17;23" . "H";
print " AC: ";
print "\e[17;28" . "H";
print "$ps_ac";
print "\e[17;33" . "H";
print " DC: ";
print "\e[17;38" . "H";
print "$ps_dc";
print "\e[17;43" . "H";
print " Level: ";
print "\e[17;51" . "H";
print "$s_level/$s_xp";
print "\e[19;1" . "H";
foreach (@x_message)
{
print "> $_\n";
}
print "\e[$s_atrow;$s_atcol" . "H";
print "@";
print "\e[$s_atrow;$s_atcol" . "H";
}
sub Win32ReadKey
{
return(undef) if(!$win32_keybrd->GetEvents);
my @event;
@event = $win32_keybrd->Input();
return(undef) if(!defined($event[0]) || ($event[0] ne "1") || !$event[1] || !$event[5]);
return(chr($event[5]));
}
# Define globals / defaults
$|=1;
$win32_keybrd;
$win32_mod = "Win32::Console";
die if (eval "use $win32_mod");
$win32_keybrd = Win32::Console->new(Win32::Console->STD_INPUT_HANDLE);
$x_points=16;
@x_message;
$x_message[0]="";$x_message[1]="";$x_message[2]="";$x_message[3]="";$x_message[4]="";
$ps_ac=50;
$ps_dc=0;
$ps_energy=500;
$ps_hpmax=10;
$ps_hpnow=10;
$ps_metab=0.01;
$ps_agility=10;
$ps_endurance=10;
$ps_perception=10;
$ps_strength=10;
$ps_agility_max=18;
$ps_endurance_max=18;
$ps_perception_max=18;
$ps_strength_max=18;
$ps_agility_min=3;
$ps_endurance_min=3;
$ps_perception_min=3;
$ps_strength_min=3;
$s_level=1;
$s_turn=0;
$s_xp=0;
$s_atcol = "1";
$s_atrow = "1";
@s_map;
# Load game from file or create raw map
{
my $a;
my $b;
$a = 0;
$b = 0;
while($a<16)
{
while($b<64)
{
$s_map[$a][$b] = "empty";
$b++;
}
$a++;
$b = 0;
}
}
# Input game character stats
{
my $x_select;
$x_select=1;
CHARAA:
print "\e[2J";
print "\e[2;4H";
print " Character points:";
print "\e[2;28H";
print $x_points;
print "\e[4;4H";
print "a. Agility:";
print "\e[4;28H";
print $ps_agility;
print "\e[5;4H";
print "b. Endurance:";
print "\e[5;28H";
print $ps_endurance;
print "\e[6;4H";
print "c. Perception:";
print "\e[6;28H";
print $ps_perception;
print "\e[7;4H";
print "d. Strength:";
print "\e[7;28H";
print $ps_strength;
if($x_select == 1) { print "\e[4;2H" . "\e[7m" . "x" . "\e[0m" . "\e[4;4H"; }
if($x_select == 2) { print "\e[5;2H" . "\e[7m" . "x" . "\e[0m" . "\e[5;4H"; }
if($x_select == 3) { print "\e[6;2H" . "\e[7m" . "x" . "\e[0m" . "\e[6;4H"; }
if($x_select == 4) { print "\e[7;2H" . "\e[7m" . "x" . "\e[0m" . "\e[7;4H"; }
if($x_points == 0) { print "\e[24;4H" . "Press space to continue"; }
CHARAB:
$keypress;
$keypress="";
for(;;)
{
$keypress=Win32ReadKey();
last unless($keypress eq "");
}
if($keypress == 8)
{
if($x_select == 1)
{
if($ps_agility < $ps_agility_max && $x_points > 0)
{
$ps_agility+=1;
$x_points--;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 2)
{
if($ps_endurance < $ps_endurance_max && $x_points > 0)
{
$ps_endurance+=1;
$x_points--;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 3)
{
if($ps_perception < $ps_perception_max && $x_points > 0)
{
$ps_perception+=1;
$x_points--;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 4)
{
if($ps_strength < $ps_strength_max && $x_points > 0)
{
$ps_strength+=1;
$x_points--;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
}
elsif($keypress == 2)
{
if($x_select == 1)
{
if($ps_agility > $ps_agility_min)
{
$ps_agility-=1;
$x_points++;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 2)
{
if($ps_endurance > $ps_endurance_min)
{
$ps_endurance-=1;
$x_points++;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 3)
{
if($ps_perception > $ps_perception_min)
{
$ps_perception-=1;
$x_points++;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 4)
{
if($ps_strength > $ps_strength_min)
{
$ps_strength-=1;
$x_points++;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
}
elsif($keypress eq "a")
{
$x_select = 1;
goto CHARAA;
}
elsif($keypress eq "b")
{
$x_select = 2;
goto CHARAA;
}
elsif($keypress eq "c")
{
$x_select = 3;
goto CHARAA;
}
elsif($keypress eq "d")
{
$x_select = 4;
goto CHARAA;
}
elsif($keypress eq " " && $x_points == 0)
{
goto GAMERU;
}
else
{
goto CHARAB;
}
}
This code has been tested on ActivePERL under WINDOWS ME and works fine. I am only after advice on how to improve the speed.
here is the first part of the code:
#!c:\perl\bin\perl.exe
use Win32::Console; #Windows specific
sub drawscreen
{
print "\e[1;1H"; # ANSI Escape Seq - requires Windows 95 ANSI.SYS driver to be installed
my $a;
my $b;
$a = 0;
$b = 0;
while($a<16)
{
while($b<64)
{
if($s_map[$a][$b] eq "empty")
{
print " ";
}
else
{
print " ";
}
$b++;
}
print "\n";
$a++;
$b = 0;
}
print "\e[17;1" . "H";
print "\e[K";
print " EN: ";
print "\e[17;6" . "H";
print "$ps_energy";
print "\e[17;11" . "H";
print " HP: ";
print "\e[17;16" . "H";
print int($ps_hpnow) . "/$ps_hpmax";
print "\e[17;23" . "H";
print " AC: ";
print "\e[17;28" . "H";
print "$ps_ac";
print "\e[17;33" . "H";
print " DC: ";
print "\e[17;38" . "H";
print "$ps_dc";
print "\e[17;43" . "H";
print " Level: ";
print "\e[17;51" . "H";
print "$s_level/$s_xp";
print "\e[19;1" . "H";
foreach (@x_message)
{
print "> $_\n";
}
print "\e[$s_atrow;$s_atcol" . "H";
print "@";
print "\e[$s_atrow;$s_atcol" . "H";
}
sub Win32ReadKey
{
return(undef) if(!$win32_keybrd->GetEvents);
my @event;
@event = $win32_keybrd->Input();
return(undef) if(!defined($event[0]) || ($event[0] ne "1") || !$event[1] || !$event[5]);
return(chr($event[5]));
}
# Define globals / defaults
$|=1;
$win32_keybrd;
$win32_mod = "Win32::Console";
die if (eval "use $win32_mod");
$win32_keybrd = Win32::Console->new(Win32::Console->STD_INPUT_HANDLE);
$x_points=16;
@x_message;
$x_message[0]="";$x_message[1]="";$x_message[2]="";$x_message[3]="";$x_message[4]="";
$ps_ac=50;
$ps_dc=0;
$ps_energy=500;
$ps_hpmax=10;
$ps_hpnow=10;
$ps_metab=0.01;
$ps_agility=10;
$ps_endurance=10;
$ps_perception=10;
$ps_strength=10;
$ps_agility_max=18;
$ps_endurance_max=18;
$ps_perception_max=18;
$ps_strength_max=18;
$ps_agility_min=3;
$ps_endurance_min=3;
$ps_perception_min=3;
$ps_strength_min=3;
$s_level=1;
$s_turn=0;
$s_xp=0;
$s_atcol = "1";
$s_atrow = "1";
@s_map;
# Load game from file or create raw map
{
my $a;
my $b;
$a = 0;
$b = 0;
while($a<16)
{
while($b<64)
{
$s_map[$a][$b] = "empty";
$b++;
}
$a++;
$b = 0;
}
}
# Input game character stats
{
my $x_select;
$x_select=1;
CHARAA:
print "\e[2J";
print "\e[2;4H";
print " Character points:";
print "\e[2;28H";
print $x_points;
print "\e[4;4H";
print "a. Agility:";
print "\e[4;28H";
print $ps_agility;
print "\e[5;4H";
print "b. Endurance:";
print "\e[5;28H";
print $ps_endurance;
print "\e[6;4H";
print "c. Perception:";
print "\e[6;28H";
print $ps_perception;
print "\e[7;4H";
print "d. Strength:";
print "\e[7;28H";
print $ps_strength;
if($x_select == 1) { print "\e[4;2H" . "\e[7m" . "x" . "\e[0m" . "\e[4;4H"; }
if($x_select == 2) { print "\e[5;2H" . "\e[7m" . "x" . "\e[0m" . "\e[5;4H"; }
if($x_select == 3) { print "\e[6;2H" . "\e[7m" . "x" . "\e[0m" . "\e[6;4H"; }
if($x_select == 4) { print "\e[7;2H" . "\e[7m" . "x" . "\e[0m" . "\e[7;4H"; }
if($x_points == 0) { print "\e[24;4H" . "Press space to continue"; }
CHARAB:
$keypress;
$keypress="";
for(;;)
{
$keypress=Win32ReadKey();
last unless($keypress eq "");
}
if($keypress == 8)
{
if($x_select == 1)
{
if($ps_agility < $ps_agility_max && $x_points > 0)
{
$ps_agility+=1;
$x_points--;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 2)
{
if($ps_endurance < $ps_endurance_max && $x_points > 0)
{
$ps_endurance+=1;
$x_points--;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 3)
{
if($ps_perception < $ps_perception_max && $x_points > 0)
{
$ps_perception+=1;
$x_points--;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 4)
{
if($ps_strength < $ps_strength_max && $x_points > 0)
{
$ps_strength+=1;
$x_points--;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
}
elsif($keypress == 2)
{
if($x_select == 1)
{
if($ps_agility > $ps_agility_min)
{
$ps_agility-=1;
$x_points++;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 2)
{
if($ps_endurance > $ps_endurance_min)
{
$ps_endurance-=1;
$x_points++;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 3)
{
if($ps_perception > $ps_perception_min)
{
$ps_perception-=1;
$x_points++;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
if($x_select == 4)
{
if($ps_strength > $ps_strength_min)
{
$ps_strength-=1;
$x_points++;
goto CHARAA;
}
else
{
goto CHARAB;
}
}
}
elsif($keypress eq "a")
{
$x_select = 1;
goto CHARAA;
}
elsif($keypress eq "b")
{
$x_select = 2;
goto CHARAA;
}
elsif($keypress eq "c")
{
$x_select = 3;
goto CHARAA;
}
elsif($keypress eq "d")
{
$x_select = 4;
goto CHARAA;
}
elsif($keypress eq " " && $x_points == 0)
{
goto GAMERU;
}
else
{
goto CHARAB;
}
}