Monday, November 27, 2006

Hi. Sorry it has been so long, all 0 of my readers. This is almost an online diary. Lately I have been tied up in school, but I managed to write a simple program to roll dice. It's currently in 'beta' but should be opperable. Here, let me post it. (It is programmed in Perl, entirely by ME)
#!/usr/bin/perl
my ($numbertimes, $if, $input, $howmany, $numsides, $modifier, $appliestoall, $while, $random, $total);
$numsides = 0;
$modifier = 0;
$appliestoall = "";
$while = 0;
$numbertimes = 1;
$total = 0;
$input = "";
while ($input ne "quit")
{
$total = "0";
print "What should I roll?:";
$input = ;
chomp $input;
if ($input =~ m/^(\d*)d(\d+)([-+]\d+)?(a)?(x)?(\d+)?$/i)
{
($howmany, $numsides, $modifier, $appliestoall, $unused, $numbertimes)=($1, $2, $3, $4, $5, $6);
if (!defined($modifier)) { $modifier = 0; }
if ($howmany eq "") { $howmany = 1; }
if ($numbertimes eq "") { $numbertimes = 1; }
for (1..$numbertimes)
{
if (lc($appliestoall) eq "a")
{
for (1..$howmany)
{
$random = (int rand $numsides) + 1 + $modifier;
if ($random > 0)
{
print "$random\n";
$total += $random;
}
else
{
$howmany++;
}
}
print "The total is $total\n";
}
else
{
for (1..$howmany)
{
$random = (int rand $numsides) + 1;
if ($random > 0)
{
print "$random\n";
$total += $random;
}
else
{
$howmany++;
}
}
$total += $modifier;
print "The total is $total\n";
}
}
}
elsif ($input !~ m/quit/)
{
print "Try something like 5d12+2ax3.\n";
}
}
It is made to roll DnD format rolls, like 1d2+18. It will keep going untill you tell it to roll 'quit'. I programmed this entirely in my freee time after Math. It took about... 5 minutes. My 3-years-older-than-me -brother made his own version. It has two modes. One for him, and one for everyone else. His used to say things like "What shall I roll My lord and master?" Now it says something like "You want me to roll this dead meat!?!?!" Hehehe. It's all thanks to sibling rivalry. Well I guess I'll post his.
#!/usr/bin/perl
print "Do you want to roll dice?";
$input = ;
chomp $input;
if ($input eq "n" or "no")
{
end;
}

my $strings = { "rollplease" => ["Tell me what to roll foolish mortal.", "Tell me what to roll oh sad and stinky leader."]

};

while ($input !~ m/quit/)
{
while ($input !~ m/I am Greg/i)
{
print $strings->{"rollplease"}[0];
$input = ;
chomp $input;
print "How many times do you wish to make this foolish move?";
$timestoroll = ;
chomp $timestoroll;
if ($input =~ m/^(\d*)d(\d+)([+-]\d+)?$/i)
{
($numdice,$dietype,$bonus) = ($1,$2,$3)
}
$numdice2 = $numdice;
if ($timestoroll eq "")
{
$timestoroll = "1";
}
if ($timestoroll < 1 or 99999 < $timestoroll)
{
print "That number is not in range try again fool.\n";
print "How many times do you wish to make this foolish move?";
$timestoroll = ;
chomp $timestoroll;
}
print "$timestoroll x $numdice d $dietype $bonus\n";
print "Is this your pitiful choice?";
$isthisright = ;
chomp $isthisright;
if ($isthisright += m/y/i)
{
$input = "quit"
}
}
while ($input =~ m/I am Greg/i)
{
print $strings->{"rollplease"}[1];
$input = ;
chomp $input;
print "How many times do you wish to roll this absolutly terrible choice, my shortness?";
$timestoroll = ;
chomp $timestoroll;
if ($input =~ m/^(\d*)d(\d+)([+-]\d+)?$/i)
{
($numdice,$dietype,$bonus) = ($1,$2,$3)
}
$numdice2 = $numdice;
if ($timestoroll eq "")
{
$timestoroll = "1";
}
if ($timestoroll + 0 ne $timestoroll)
{
print "You broke it.\n";
print "How many times can I roll this dead meat?";
$timestoroll = ;
chomp $timestoroll;
}
print "Here it is. The worst choice ever:";
print "$timestoroll x $numdice d $dietype $bonus\n";
$isthisright = ;
chomp $isthisright;
if ($isthisright eq "y" or "yes")
{
$input = "quit"
}
}
}
while ($timestoroll > 0)
{
$output = 0;
while ($numdice > 0)
{
$random = (int rand $dietype) +1;
print "$random\n";
$output += $random;
$numdice += -1;
}
$numdice = $numdice2;
$output = $output + $bonus;
print "the total is $output\n";
$timestoroll += -1
}
His is also in 'beta'. Thanks for reading. NOT!!! I haven't a single reader:(

No comments:

Post a Comment