in reply to Re: Wizard v1.2
in thread Wizardv1.1

I've modified it a bit, adding a third number for the number of coins for each monster:

#!/usr/bin/perl # Version 1.2 ;) use strict; use warnings; my ( $room, $choice, $shop ); my $wizard = 50; my $wizardl = 1; my $gold = 10; my $damage = 3; # various monsters my @monsters = ( { 'name' => 'goblins', 'health' => 12, gold=>6 +}, { 'name' => 'orcs', 'health' = +> 14, gold=>7}, { 'name' => 'trolls', 'health' + => 13, gold=>6}, { 'name' => 'wolves', 'health' + => 10, gold=>5}, { 'name' => 'rats', 'health' = +> 6, gold=>3}, { 'name' => 'bats', 'health' = +> 5, gold=>2} ); print "Welcome to Wizard! Type your wizard's name..."; my $name = <STDIN>; chomp($name); print "Welcome $name to Wizard.\n You are now in Merlin's castle.\n You are +surrounded by other mages and disscussion flows back "; print "and forth in the room. Suddenly Merlin stands up in front of all an +d says:<< I need a powerful man to go out and slay all the monsters t +hat have been plauging my land.\n"; print "Which one of you can raise to the challenge?>> Slowly all those in th +e room rise, including yourself.\n\n"; print "<<Good, good...>> merlin utters. Then be off.\n\n\n"; print "(note: the higher the number you choose, the more often you will enco +uter enemies!)\n\n\n"; sub goodbye { print "Thanks for playing, $name.\n\n"; exit; } sub toad { my ($monster, $monsterhealth, $coins) = @_; if ( $room != 6 ) { my $toad = int( rand 4 ) + 1; if ( $toad <= $wizardl ) { print "The $monster have been zapped into toads!\n"; $gold = $gold + $coins; print "good job you got $coins gold!\n"; freedale(); } else { print "your spell has failed! -2 health\n"; $wizard = $wizard - 2; battle($monster, $monsterhealth, $coins); } } else { my $toad = int( rand 7 ) + 1; if ( $toad <= $wizardl ) { print "The demons have been zapped into toads!\n"; $gold = $gold + $coins; print "great job you got $coins gold!\n"; freedale(); } elsif ( $toad > $wizardl ) { print "your spell has failed! -2 health\n"; $wizard = $wizard - 2; battle($monster, $monsterhealth, $coins); } } } sub battle { my ($monster, $monsterhealth, $coins) = @_; print "What do you want to do?..press 1 to use spells or 2 for com +bat.\n"; $choice = <STDIN>; chomp $choice; if ( $choice eq '1' ) { toad($monster, $monsterhealth, $coins); } elsif ( $choice =~ "q" ) { goodbye(); } elsif ( $choice eq '2' ) { do { $monsterhealth = $monsterhealth - $damage; $wizard = $wizard - 2; print "wizard health: $wizard\t"; print "$monster health: $monsterhealth\n"; } until ( $monsterhealth <= 0 || $wizard <= 0 ); if ( $wizard > 0 ) { print "good job you got $coins gold!\n"; $gold = $gold + $coins; freedale(); } elsif ( $wizard <= 0 ) { goodbye(); } } else { print "You must choose 1, 2, or q!\n"; battle($monster, $monsterhealth, $coins); } } sub forest { 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 ) { my $randommonster=$monsters[int( rand 6 )]; print "$randommonster->{name} attack\n"; battle( $randommonster->{name}, $randommonster->{health}, $ran +dommonster->{gold} ); } else { print "There are no monsters here now.\n"; freedale(); } } sub mountain { print "Its pretty cold up here, but from this altitude you can see + 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 ) { my $randommonster=$monsters[int( rand 6 )]; print "$randommonster->{name} attack\n"; battle( $randommonster->{name}, $randommonster->{health}, $ran +dommonster->{gold} ); } else { print "There are no monsters here now.\n"; freedale(); } } + + sub dungeon { print "There is a heavy feeling in the air, it's very dark and mus +ty down here.\n"; print "You can see clear signs that goblins have been here, and ma +ybe worse things!\n"; my $gobbo = int( rand 6 ) + 1; if ( $gobbo >= 3 ) { my $randommonster=$monsters[int( rand 6 )]; print "$randommonster->{name} attack\n"; battle( $randommonster->{name}, $randommonster->{health}, $ran +dommonster->{gold} ); } else { print "There are no monsters here now.\n"; freedale(); } } sub splane { print "This is a mysterious place full of horribly powerful monste +rs...\n"; print "You see tracks unlike any other you have encountered before +.\n"; my $gobbo = int( rand 6 ) + 1; if ( $gobbo >= 2 ) { print "Demons attack!\n"; battle( 'demons', 18, 10 ); } else { 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 30 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"; $shop = <STDIN>; if ( $shop == 1 ) { if ( $gold < 10 ) { print "you don't have enough gold\n"; freedale(); } else { print "Thank you\n"; $gold = $gold - 10; $wizard = $wizard + 30; freedale(); } } 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"; freedale(); } 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 cheat { $wizardl = $wizardl + 2; $wizard = 100; $gold = 60; freedale(); } sub error { freedale(); } sub wizstat { print "health:\t$wizard\n"; print "magic level:\t$wizardl\n"; print "gold:\t$gold\n"; freedale(); } sub 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, or 3 for the dungeon, 4 +for the shop, 5 to view stats, 6 for the Shadow Plane, or q to quit. +\n "; print "press q at anytime to quit.\n"; $room = <STDIN>; chomp $room; if ( $room eq '1' ) { forest(); } elsif ( $room eq '2' ) { mountain(); } elsif ( $room eq '3' ) { dungeon(); } elsif ( $room eq '4' ) { shop(); } elsif ( $room eq '5' ) { wizstat(); } elsif ( $room eq '6' ) { if ( $wizardl < 3 ) { print "You're level isn't high enough! You must have a magic lvl of 3 to com +e here.\n"; freedale(); } elsif ( $wizardl => 3 ) { splane(); } } elsif ( $room eq '7' ) { cheat(); } elsif ( $room =~ "q" ) { goodbye(); } else { print "Please enter a number between 1 and 6 or q to quit!\n" +; error(); } } freedale()
Adding a variable damage could also be a good idea.

Replies are listed 'Best First'.
Re^3: Wizard v1.2
by wazoox (Prior) on May 10, 2005 at 15:50 UTC
    Fine :) Actually I'd like to implement a more complete combat system with damage, armor, etc. Also I had started a system to build "places" such as a forest, a castle, a cave so you can wander around a little, find some tresures, etc. Then of course you'll need to be able to save the game state; then why not make it CGI-able, and what about multiplayer game? Mmmmh, i'm afraid it's about to become a real project :)

    Here's what I'm working out for the "place generator" :

    Forest, mountain, village, castle, cavern maze.
    • a forest is a group of connected "rooms" with very little "walls". You can almost always go whichever direction you want. There are some obstacles though : rivers, big trees, rocks.
    • mountain is a group of connected "rooms" with walls on a prefered axis (you can easily travel from north to south, but not from east to west) and a top (from which you can go all directions), some rocks and pits. Summit is the preferred place to finc treasures of course.
    • village is a village :), with some streets, some houses, with people, treasures or monsters inside, and perhaps shops.
    • castle is made of groups of rooms (towers) with several floors (some possibly underground), connected through corridors, with a dungeon (a bigger tower) where the monsters and treasures mostly are :)
    • a cavern maze is a maze, haunted by terrible monsters, perhaps even dragons. Wow, big treasures too!
    The game would generate a random "world" to be explored. I'd create a set of basic "quests", you'll end the quest by killing a group of defined monsters or finding a set of defined treasures; then it would generate another world, harder, with a new quest, etc.
    Yes, As I thought about it, it becames quite clear that this would be easily extended to aclient-server mode, so you can play with a command line, a browser (cgi) interface (possibly graphical) or even a graphic display, and why not, make it multiplayer.
    OK, be enthusiast enough and I'll make it :)
      Ok, I'll be enthusiast: "Do it!!" =o)
      I'd be interested in a project like that. I think I could manage to implement a battle system based on somewhat similar to D&D3rd, and maybe a magic system. But I think somethings should be considered before. What do you think?
        Oh oh oh, welcome friend, let's band together on a project that'll suck the few minutes of free time we managed to save from our bosses, wives and the rest :)
        We should defintetely consider what to do exactly, and in which order. For instance I just thought it to be nice if the monsters weren't static, but could move a bit around their "origin", flee when wounded, etc. Wow, so much to do...
        For the combat system, AD&D can be good enough (there's a version of the rules on the TSR site that can be freely implemented).
        Perhaps a fully object game system would be better, because it would be easier to extend the game (for instance to get it multiplayer or put a GUI on it). I think something like a quick turn-by-turn system (with a 3 seconds turn for instance) would be nice, because it will allow a very interactive gaming without the hurdle of a true real-time system (hard, especially for combats).
        OK, ok, I'll stop that now : I'm right now working on the "world generator" first, When I'll have something ready I'll post a brand new Code Catacomb node!
        Hey, can't this be useful? battle.pl

        update: and I didn't even talk about magic! I had this idea (let me know what you think of it) : it would be nice to be able to find scrolls (perhaps by killing some monsters, or as special rewards); then you could either use the scroll (for instance "fireball") once, and it'll be burnt out, destroyed, reduced to ashes; or you'd be able to LEARN the spell from the scroll (takes time, energy, mana, whatever) and then be able to use it as you like (but of course you then will need enough mana, etc). Wadyathink? I LIKE this idea.

      I think that would be an excellent idea. Although that's extremely complex for my level (a novice at the monastery as of this morning:)) I think it would be great for someone else to take it further than I could. In your case, you could take all the credit because besides for the original code, anything worth using would have been created by you (or someone else who is willing to tackle such a project.) So feel free.
        You may be a novice, but someday you may become a mighty saint :) Use Strict and Use Warnings, and Enlightment will come sooner than you expect :)
        BTW a novice may find it harder to contribute code, but code isn't all, there's ideas, arts, etc. And your code will improve over time anyway, so don't be shy: show your code, listen to advices, and you'll learn quickly.