Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Wizard v1.2

by void_Anthony() (Acolyte)
on May 16, 2005 at 15:03 UTC ( [id://457487]=sourcecode: print w/replies, xml ) Need Help??
Category: Fun Stuff
Author/Contact Info
Description: new monsters: demon, troll, orc, bats (varying in difficulty while some giving you more gold than others.) Toad spell replaced with fireball (does damage depending on wizard level * 2 instead of instantly killing enemies. You will always have a 50/50 chance of successfully casting it.) Cleaner code :). Run option is available during combat. Health goes up by 20 instead of 30 with 10 gold. Damage from enemies is random (Within a certain range, the higher the range with the harder the monsters.) I forget the rest :). Note: Initially, work on raising your damage level. The game will be much harder if you don't! Credit for modification ideas and code snippets goes to:wazoox, CountZero, Roy Johnson, deibyz, cbrandtfuffalo, holli,and eric256.
$wizard=50;
$wizardl=1;
$gold=10;
$damage=3;
$firedmg = $wizardl*2;
$diflvl=$wizardl-2;
print"Welcome to Wizard!  Type your wizard's name...";
$name=<STDIN>;
chomp ($name);
print "Welcome $name, to Wizard.  You are now in the Merlins castle.  
+You are surrounded  by other mages and disscussion flows back and for
+th.\n";
print "and forth in the room.   Suddenly Merlin stands up in front of 
+all and says, I need a powerful man to go out and slay all the monste
+rs that have been plauging my land.\n";
print "Which one of you can raise to the challenge.  Slowly all those 
+in the room rise, including yourself.\n\n";
print "Good, good merlin utters.  Then be off.\n\n\n";
sub die{
if($wizard<=0){
    print "Thanks for playing";
    die;
}
sub fireball {
     if($room==1){
         $monster = "bats";
         $newgold = 3;
     }elsif($room==2){
           $monster = "orcs";
           $newgold = 4;
      }elsif($room==3){
           $monster = "trolls";
           $newgold = 5;
      }elsif($room==6){
           $monster = "demons";
           $newgold = 6;
      } 
      $fireball = int (rand 2)+1;
      if($fireball==1){
          $goblin-=$firedmg;
          if($goblin<=0){
              print "The $monster have been torched to death!\n";
            $gold+=$newgold;
            print "You got $newgold gold!\n";
            &freedale;
          }elsif($goblin>0){
               print "The $monster took $firedmg damage!\n";
            print "$monster health: $goblin\t";
            print "$name's health: $wizard\t";
               &battle;
            
        }
    }elsif($fireball==2){
        print "Your spell failed!\n";
        print "Minus two health!\n";
        $wizard-=2;
        print "$name's health: $wizard\t";
        &battle;
    }
}
sub battle {
     my $monster="";
     print "What do you want to do...press 1 to use fireball, 2 for co
+mbat, or r to run.\n";
     $choice=<STDIN>;
     if($choice==1){
           &fireball;
    }elsif($choice=="r"){
        &run;
     }elsif($choice=="q"){
           &die;
     }elsif($choice==2){
        if($room==6){
               $monster = "demon";
               $newgold = 6;
          }elsif($room==3){
               $monster = "troll";
               $newgold = 5;
          }elsif($room==2){
               $monster = "orc";
               $newgold = 4;
          }elsif($room==1){
               $monster = "bat";
               $newgold = 3;
          }
     do{
          $goblin=$goblin-$damage;
          if($goblin<0){
              $goblin=0;
          }if($wizard<0){
              $wizard=0;
          }
          $dmg = int (rand $room +2);
          $wizard-=$dmg;
          print "wizard health: $wizard\t";
          print "$monster health: $goblin\n";
     }until($goblin<=0 || $wizard<=0);
      if($wizard>0){
           print "good job you got $newgold gold!\n";
           $gold+=$newgold;
           &freedale;
      }elsif($wizard<=0){
          &die;
    }
        }else{
              print "Please enter 1, 2, or q...\n";
              &battle;
        }
}
sub forest {
     $goblin = 10;
     print "The forest is dark and smells of old mold and rotton fish.
+ 
    + The foul waters have turned this once peaceful place in to a\n";
+    
    + print "dark evil place.\n";
     my $gobbo=int (rand 6)+1;
     if ($gobbo>=5){
          print "bats attack!\n";
          &battle;
     }elsif($gobbo!=5 || $gobbo!=6){
          print "There are no monsters here now.\n";
          &freedale
     }
}

sub mountain {
     $goblin = 14;
     print "Its pretty cold up here, but from this altitude you can se
+e
    + the whole town below you.\n"; 
     print "Although it is clear that you are not the first one here!\
+n
    +";
     my $gobbo=int (rand 6)+1;
     if ($gobbo>=4){
          print "orcs attack\n";
          &battle;
     }elsif($gobbo!=4 || $gobbo!=5 || $gobbo!=6){
           print "There are no monsters here now.\n";
           &freedale
     }
}

sub dungeon {
     $goblin = 17;
     print "There is a heavy feeling in the air, it's very dark and mu
+s
    +ty down here.\n"; 
     print "You can see clear signs that goblins have been here, and m
+a
    +ybe worse things!\n";
     my $gobbo=int (rand 6)+1;
     if ($gobbo>=3){
          print "trolls attack\n";
          &battle;
     }elsif($gobbo!=3 || $gobbo!=4 || $gobbo!=5 || $gobbo!=6){
          print "There are no monsters here now.\n";
          &freedale
     }
}

sub splane {
     $goblin = 20;
     print "This is a mysterious place full of horribly powerful monst
+ers.
    +..\n";
     print "You see tracks unlike any other you have encountered befor
+e.\n
    +";
     my $gobbo=int (rand 8)+1;
     if ($gobbo>=2){
          print "Demons attack!\n";
           &battle
      }elsif($gobbo!=2 || $gobbo!=3 || $gobbo!=4 || $gobbo!=5 ||      
+ $go
    +bbo!=6 || $gobbo!=7 || $gobbo!=8){
            print "There are no demons here now.\n";
            &freedale
     }
}

sub shop {
        print "Hello welcome to freedale market may I help you?\n";
        print "type 1 for 20 more health..............................
+...........10 gold\n";
        print "type 2 for daggers (increases damage per round by one).
+............................................15 gold\n";
        print "type 3 for magic wands(increases magic level by one)...
+..................................30 gold\n";
        print "type 4 to leave the shop\n";
    print "You have $gold gold\n";
    $shop=<STDIN>;
    chomp($shop);
    if($shop==1){
        if($gold>=10){
            $gold-=10;
            $wizard+=20;
            print "$name's health: $wizard\n";
            print "Gold: $gold\n";
            &freedale;
        }elsif($gold<$gold){
            print "You don't have enough gold!\n";
            $shop;
         }
    }elsif($shop==2){
         if($gold<15){
              print "you don't have enough gold\n";
              &freedale;
          }else{
             print "thank you\n";
             $gold=$gold-15;
             $damage=$damage + 1;
             &freedale;
         }
    }elsif($shop==3){
         if($gold<30){
              print "you don't have enough gold\n";
              &shop;
        }else{
             print "thank you\n";
             $gold=$gold-30;
             $wizardl=$wizardl+1;
             &freedale;
         }
    }elsif($shop==4){
         print "Thank you for coming!\n";
         &freedale;
    }else{
         print "Please enter a number between 1 and 4!\n";
         &freedale
    }
}

sub run{
    $chance = int (rand 2);
    if($chance==0){
        print "You failed to get away!\n";
        print "Minus two health!\n";
        $wizard-=2;
        print "$name's health: $wizard\t";
        print "$monster' health: $goblin\t";
        &battle;
    }elsif($chance==1){
        print "You managed to escape!\n";
        &freedale;
    }
}

sub cheat{
     $wizardl += 2;
     $wizard += 100;
     $gold += 60;
     &freedale
}

sub stat{
        print "health:\t$wizard\n";
        print "magic level:\t$wizardl\n";
        print "gold:\t$gold\n";
        print "damage:\t$damage\n";
        &freedale
}

sub freedale{
     if($gold < 0){
          $gold = 0;
          &freedale;
     }
     print "you are in freedale\n";
     print "where do you want to go\n";
     print "type 1 for the forest, 2 for the mountain, 3  for  the dun
+geon, 4 for the shop, 5 to view stats, 6 for the          Shadow Plan
+e, or q to quit.\n ";
     print "press q at anytime to quit.\n";
    $room=<STDIN>;
    if($room==1){
         &forest;
    }elsif($room==2){
         &mountain;
    }elsif($room==3){
         &dungeon;
    }elsif($room==4){
         &shop
    }elsif($room==5){
         &stat
    }elsif($room==6){
         if($wizardl < 3){
                print "You're level isn't high enough! You must have a
+ magic lvl o
            +f 3 to come here.\n";
                &freedale
            }elsif($wizardl => 3){
                 &splane
            }
    }elsif($room==7){
         &cheat
    }elsif($room=="q"){
         &die
    }else{
         print "Please enter a number between 1 and 6 or q to  quit!\n
+";
         &freedale;
            }
    }
}
&freedale

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://457487]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found