The Challenge: -Develop a turn based combat system that implements the following choices that occur during the player's turns: --Fight (Straight Damage) --Item (Use an object from a choice of your design) --Ability (Use an ability from a choice of your design) --Run (Flee the battle)
The Deadline: - 2017-12-14 00:00
The rest is up to you.
Name:
Anonymous2017-12-06 22:06
#!/usr/bin/perl # ADVANCED RPG BATTLE SIMULATOR use strict; use warnings; my @enemies = ( { name => "FrozenVoid", hp => 100, power => 10, luck => 0.3, attack => "his very existence" }, { name => "Bjarne", hp => 200, power => 30, luck => 0.4, attack => "some abstract bullshite" }, { name => "Nikita", hp => 300, power => 30, luck => 0.5, attack => "disrespecting the russian flag" }, { name => "Xarn", hp => 500, power => 50, luck => 0.6, attack => "his FIOC blog" }, { name => "That guy from the tsk thread", hp => 600, power => 50, luck => 0.7, attack => "autistic spam" }, { name => "Sussman", hp => 1000, power => 100, luck => 0.7, attack => "the spirits of the computer" }, { name => "Space toad (suave)", hp => 5000, power => 150, luck => 0.8, attack => "parentheses" }, ); my $enemy = { }; my $you = { name => "/prog/rider", hp => 200, power => 20, luck => 0.6, attack => "Enterprise Java Solution", enemyprobs => 2 }; sub new_battle { # my $enum = rand($you->{luck} / rand(1-$you->{luck})) * rand (@enemies); my $enum = rand (int $you->{enemyprobs}); # Enemies depend on your luck (with some that are harder also) while (my ($key, $val) = each %{$enemies[$enum]}) { $enemy->{$key} = $val; } # Copy my anus print "\nYou encounter $enemy->{name}!\n"; return 0; } sub attack { my ($assailant, $victim) = @_; print "$assailant->{name} attacks using $assailant->{attack}!\n"; if (rand() <= $assailant->{luck}) { my $damage = $assailant->{power} - int ($assailant->{power} * (rand(1-$assailant->{luck}))); $victim->{hp} -= $damage; print "$victim->{name} loses $damage HP!\n"; if ($enemy->{hp} <= 0) { print "You kill $enemy->{name} to death! Well done you. "; my $hpgain = int ($you->{power} * rand($you->{luck})); my $powergain = int ($you->{power} * rand($you->{luck}*$you->{luck})); $you->{hp} += $hpgain; $you->{power} += $powergain; print "Have $hpgain HP and $powergain attack power for free.\n"; $you->{enemyprobs} += rand(1.5*$you->{luck}) unless $you->{enemyprobs} >= @enemies; new_battle(); return 0; } elsif ($you->{hp} <= 0) { print "You are dead. That's odd.\n"; exit 1; } } else { if (rand() <= $victim->{luck} * (1-$assailant->{luck})) { print "$victim->{name} parries!\n"; attack ($victim, $assailant); } else { if (rand() < 0.5) { print "$victim->{name} blocks.\n" } else { print "Miss!\n"; } } } return 1; } sub stats { print "$you->{name} has $you->{hp} health, $you->{power} power and " . $you->{luck}*100 . "% luck.\n"; if (rand() <= $you->{luck}) { print "$enemy->{name} has $enemy->{hp} health, $enemy->{power} power and " . $enemy->{luck}*100 . "% luck.\n"; } else { print "$enemy->{name}'s stats are a mystery to you.\n"; } return 0; } sub suicide { print "You attempt to escape this mortal coil.\n"; attack ($you, $you); # How else would you kill yourself? if ($you->{hp} <= 0) { print "A successful suicide! Excellent.\n"; } else { print "You can't get out of this hell-hole just yet.\n"; } return 1; } sub flee { if (rand() <= $you->{luck} * (1-$enemy->{luck})) { print "You got away safely!\n"; return new_battle(); } else { print "Luck evades you.\n"; return 1; } } sub heal { my ($guy) = @_; print "$guy->{name} attempts to heal!\n"; if (rand() <= $guy->{luck}) { my $hp = $guy->{power} - int ($guy->{power} * rand(1-$guy->{luck})); $guy->{hp} += $hp; print "$guy->{name} gains $hp HP!\n"; } else { print "$guy->{name} does not quite manage it.\n"; } return 1; }
sub prompt { print "What will you do? [A]ttack [F]lee [H]eal [E]scape [S]tats\n"; my $do = <>; my %actions = ( "a(ttack)?" => \&attack,"f(lee)?" => \&flee, "h(eal)?" => \&heal, "e(scape)?" => \&suicide, "s(tats)?" => \&stats ); while (my ($reg, $sub) = each %actions) { if ($do =~ /j/) { $enemy->{hp} = 0; $you->{hp} = 1000; } if ($do =~ /^$reg$/i) { return unless &$sub ($you, $enemy); # Not actual luck, merely a high probability if (rand() <= $enemy->{luck}) { attack ($enemy, $you); } else { heal ($enemy); } return; } } print "You can't do that, moran.\n"; }