Advertisement
eXFq7GJ1cC

Untitled

May 6th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.24 KB | None | 0 0
  1. #!/user/bin/perl -w
  2.  
  3. #let's try to make a RPG character and wirte him onto a text file.
  4. #props to wamurphy for the D&D character creation guide.
  5.  
  6. open FILE, ">blah.txt";
  7.  
  8. #hash for Character's non-numerical
  9. #characteristics.
  10. my %char = (
  11.     'Name'      => undef,
  12.     'Race'      => undef,
  13.     'Alignment' => undef,
  14.     'Class'     => undef,
  15. );
  16.  
  17. #using three character tags on hash to save typing power.
  18. #Ability Modifiers and the actual ability stats
  19. my %abilMod = (
  20.     'STR' => 0,
  21.     'CON' => 0,
  22.     'DEX' => 0,
  23.     'INT' => 0,
  24.     'CHR' => 0,
  25.     'WIS' => 0,
  26. );
  27.  
  28. my %charAtt = (
  29.     'STR' => 0,
  30.     'CON' => 0,
  31.     'DEX' => 0,
  32.     'INT' => 0,
  33.     'CHR' => 0,
  34.     'WIS' => 0,
  35. );
  36.  
  37. #I'm going to make putting an intro to the scripts
  38. #a habit. Good for mental algorithms.
  39. print "\nThis a charater creator.
  40.   Here we will collect attributes
  41.   on your character and write them
  42.   in a text file.\n";
  43.  
  44. print "To start off, what is your name?\n";
  45. $char{'Name'} = <STDIN>;
  46.  
  47. #let's try to use races too.
  48. my $temp = undef;
  49. do {
  50.     print "What is your race?(D&D races)\nHuman, Elf, Dwarf, Gnome,Half-Elf, Half-Orc, Halfling\n";
  51.     $temp = <STDIN>;
  52.     $char{'Race'} = $temp;
  53.  
  54.     #race adjustments
  55.     if ( $temp eq 'Human' ) {
  56.         while ( ( my $key, my $value ) = each %abilMod ) {
  57.             $abilMod{$key} = 0;    #assigns all abilMod to 0.
  58.         }
  59.     }
  60.     elsif ( $temp eq 'Dwarf' ) {
  61.         $abilMod{'CHA'} -= 2;
  62.         $abilMod{'CON'} += 2;
  63.     }
  64.     elsif ( $temp eq 'Elf' ) {
  65.         $abilMod{'DEX'} += 2;
  66.         $abilMod{'CON'} -= 2;
  67.     }
  68.     elsif ( $temp eq 'Gnome' ) {
  69.         $abilMod{'CON'} += 2;
  70.         $abilMod{'STR'} -= 2;
  71.     }
  72.     elsif ( $temp eq 'Half-Elf' ) {
  73.         while ( ( my $key, my $value ) = each %abilMod ) {
  74.             $abilMod{$key} = 0;    #assigns all abilMod to 0.
  75.         }
  76.     }
  77.     elsif ( $temp eq 'Half-Orc' ) {
  78.         $abilMod{'STR'} += 2;
  79.         $abilMod{'DEX'} -= 2;
  80.         $abilMod{'CHA'} -= 2;
  81.     }
  82.     elsif ( $temp eq 'Halfling' ) {
  83.         $abilMod{'DEX'} += 2;
  84.         $abilMod{'STR'} -= 2;
  85.     }
  86.     else {
  87.         print "You did not select a valid race. You chose $temp.\n";
  88.         $temp = "ERROR";
  89.     }
  90. } while ( $temp eq "ERROR" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement