in reply to Re^3: Wizard v1.2
in thread Wizardv1.1
I've revamped the game quite a bit. I got rid of the recursion, in favor of (usually) redo. Freedale is like a main event loop, and everything else is called from there, and eventually returns to there. I introduced some randomness into how much gold you get, gave each zone a limited supply of monsters (and limited the types), got rid of the "you don't find any monsters" thing, added a couple of jokes, changed formatting, just bunches of stuff. Still, it's basically the same game.
#!/usr/bin/perl -lw # Version 1.3 ;) use strict; my $wizard = 50; my $wizardl = 1; my $gold = 10; my $damage = 3; # monsters names and health points my %monsters = ( Demons => 30, trolls => 20, orcs => 14, goblins => 12, wolves => 10, rats => 6, bats => 5, ); # Place descriptions my $forest_desc = <<'End Forest'; The forest is dark and smells of old mold and rotton fish. The foul waters have turned this once peaceful place in to a dark evil place. End Forest my $dungeon_desc = <<'End Dungeon'; There is a heavy feeling in the air, it's very dark and musty down here. You can see clear signs that goblins have been here, and maybe worse things! End Dungeon my $mountain_desc = <<'End Mountain'; Its pretty cold up here, but from this altitude you can see the whole town below you. Although it is clear that you are not the first one here! End Mountain # Lucy, you got some s_planing to do... my $s_plane_desc = <<'End S_plane'; This is a mysterious place full of horribly powerful monsters... You see tracks unlike any other you have encountered before. End S_plane # menu - location and handler routine my @menu = ( ['view stats', \&wizstat], ['shop', \&shop], ['forest', fightzone($forest_desc, qw(bats rats w +olves))], ['dungeon', fightzone($dungeon_desc, qw(rats gobli +ns))], ['mountain', fightzone($mountain_desc, qw(orcs trol +ls))], ['Shadow Plane', restricted_fightzone($s_plane_desc, 'D +emons')], ); print "Welcome to Wizard! Type your wizard's name..."; chomp(my $name = <STDIN>); print "Welcome, $name, to Wizard."; print <<'End_Welcome'; You are now in Merlin's castle. You are surrounded by other mages and discussion flows back and forth in the room. Suddenly Merlin stands up in front of all and says: <<I need a powerful man -->> some of the wizards snicker -- <<to go out and slay all the monsters that have been plaguing my land,>> he finishes, over the chortling. <<Which one of you can rise to the challenge?>> Slowly all those in the room rise, including yourself. <<Good, good...>> Merlin utters. <<Then be off.>> End_Welcome printf '[-- press return --]'; <STDIN>; freedale(); sub goodbye { print "Thanks for playing, $name.\n"; exit; } sub battle { my ($monster, $monsterhealth) = @_; my $winnings = int(rand $monsterhealth/4) + 2; { print 'What do you want to do?..press 1 to use spells or 2 for + combat.'; chomp(my $choice = <STDIN>); if ( $choice eq '1' ) { # Your chance of killing a monster is based on its health +points, now my $spell_power = (rand(3)+rand(6))*$wizardl; if ($spell_power > $monsterhealth) { print "The $monster have been zapped into toads!"; } else { if (my $damage = int($spell_power/2)) { $monsterhealth -= $damage; print "Your spell has failed (but you injured them +)!"; } else { print "Your spell has failed utterly!" } $wizard = $wizard - 2; printf "wizard health: $wizard\t"; print "$monster health: $monsterhealth"; redo; } } elsif ( $choice =~ /^q/i ) { goodbye(); } elsif ( $choice eq '2' ) { do { $monsterhealth = $monsterhealth - int($damage); $wizard = $wizard - 2; printf "wizard health: $wizard\t"; print "$monster health: $monsterhealth"; } until ( $monsterhealth <= 0 || $wizard <= 0 ); } else { print "You must choose 1, 2, or q!\n"; redo; } } if ( $wizard > 0 ) { print "Good job! You got $winnings gold!"; $gold = $gold + $winnings; } elsif ( $wizard <= 0 ) { goodbye(); } } sub restricted_fightzone { my $ok = fightzone(@_); return sub { if ($wizardl < 3) { print <<"End Warning"; You don't want to go there just yet, $name. There are powerful forces that would just suck the life right out of an inexperienced young mage like yourself. Increase your magical skills first. End Warning printf '[-- press return --]'; <STDIN>; } else { $ok->() } } } sub fightzone { my ($description, @monster_list) = @_; # Each zone can run out of monsters my $total_monsters = 40; return sub { print $description; my $randommonster = $monster_list[rand @monster_list]; --$total_monsters; if ($total_monsters < 1) { print "You have slain all the monsters in this area!"; print "(Although it is *thick* with toads!)"; return; } elsif ($total_monsters < 10) { print "It takes you quite a bit of searching to find anythin +g."; print "You must really be making a dent in the monster popul +ation."; } elsif ($total_monsters < 20) { print "It takes you a while to find any monsters. You're doi +ng a"; print "good job of clearing them out."; } print "$randommonster attack!"; battle($randommonster, $monsters{$randommonster}); } } sub shop { print <<'End ShopMenu'; Hello welcome to freedale market may I help you? type 1 for 30 more health................................10 gold type 2 for daggers (increases damage per round by one)...15 gold type 3 for magic wands(increases magic level by one).....30 gold type 4 to leave the shop without buying anything End ShopMenu my @stock = ( [], [10, sub { $wizard += 30}], [15, sub { $damage += 1}], [30, sub { $wizardl += 1}] ); my $shop; { $shop = <STDIN>; if ($shop < 1 or $shop > 4) { print "Please enter a number between 1 and 4!"; redo; } } if (@{$stock[$shop]}) { if ($gold < $stock[$shop][0]) { print "You haven't the gold!"; } else { $gold -= $stock[$shop][0]; print "A pleasure doing bi'ness wi' ye! (You have $gold go +ld left.)"; $stock[$shop][1](); } } } sub cheat { $wizardl = $wizardl + 2; $wizard = 100; $gold = 60; wizstat(); } sub error { freedale(); } sub wizstat { for ([health => $wizard], ['magic level' => $wizardl], [gold => $g +old]) { printf "%15s: %s\n", @$_; } printf '[-- press return --]'; <STDIN>; } sub freedale { { print 'You are in Freedale (town motto: "They will never take +our Freedale!").'; print "Where do you want to go? (higher numbers mean more dang +er)"; for (0..$#menu) { print "$_: $menu[$_][0]"; } print "Press q at anytime to quit.\n"; my $room = <STDIN>; if ($room =~ /^xyzzy/) { cheat(); redo; } elsif ($room =~ /^q/i) { goodbye(); } unless ($menu[$room]) { print "Please enter a number between 1 and 6 or q to quit +!\n"; } $menu[$room][1](); redo; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Wizard v1.2
by wazoox (Prior) on May 10, 2005 at 07:09 UTC |