#!/usr/bin/perl use strict; use warnings; my ($diff, $wood, $food); my $maxRNG = 6; my $RNG = rand($maxRNG); print "May I have your name please?\n"; chomp(my $name = <>); print "Thank you $name.\n"; print "Please enter a difficulty level: easy, or hard.\n"; chomp($diff = <>); print "you chose $diff.\n"; if ($diff eq "easy"){ $wood = 120; } elsif ($diff eq "hard"){ $wood = 75; } if ($diff eq "easy"){ $food = 50; } elsif ($diff eq "hard"){ $food = 20; } print "You have crash landed on a strange alien planet and must find a way to get back to earth.\n"; print "\n"; print "You have $wood wood and $food food.\n"; print "You can:\n"; if($wood >= 10){ print "BUILD a HUT with 10 wood\n"; } #### if ($diff eq "easy"){ $wood = 120; $food = 50; } elsif ($diff eq "hard"){ $wood = 75; $food = 20; } #### #!/usr/bin/perl use strict; use warnings; my %inventory; my $maxRNG = 6; my $RNG = rand($maxRNG); my $name = ""; while($name eq "") { print "May I have your name please? "; chomp($name = <>); } print "Thank you $name.\n"; while(1) { print "Please enter a difficulty level: easy or hard? "; chomp(my $diff = <>); if ($diff eq "easy"){ $inventory{wood} = 120; $inventory{food} = 50; last; } elsif ($diff eq "hard"){ $inventory{wood} = 75; $inventory{food} = 20; last; } else { next; } print "You chose $diff.\n"; } print "You have crash landed on a strange alien planet and must find a way to get back to earth.\n"; print "\n"; print "You have:\n"; foreach my $item (sort keys %inventory) { print " $inventory{$item} $item\n"; } print "You can:\n"; if($inventory{wood} >= 10){ print "BUILD a HUT with 10 wood\n"; } #### #!/usr/bin/perl use strict; use warnings; use AlienInit; my $maxRNG = 6; my $RNG = int(rand($maxRNG)+1); my $name = AlienInit::getUsername(); my ($diff, %inventory) = AlienInit::getInventory(); print "You have crash landed on a strange alien planet and must find a way to get back to earth.\n"; print "\n"; print "You have:\n"; foreach my $item (sort keys %inventory) { print " $inventory{$item} $item\n"; } print "You can:\n"; if($inventory{wood} >= 10){ print "BUILD a HUT with 10 wood\n"; } #### package AlienInit; use strict; use warnings; sub getUsername { my $name = ""; while($name eq "") { print "May I have your name please? "; chomp($name = <>); } print "Thank you $name.\n"; return $name; } sub getInventory { my ($diff, %inventory); while(1) { print "Please enter a difficulty level: easy or hard? "; chomp($diff = <>); if ($diff eq "easy"){ $inventory{wood} = 120; $inventory{food} = 50; last; } elsif ($diff eq "hard"){ $inventory{wood} = 75; $inventory{food} = 20; last; } else { next; } print "You chose $diff.\n"; } return ($diff, %inventory); } 1;