Skip to content

Instantly share code, notes, and snippets.

@hugot
Last active February 28, 2017 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugot/72f8c37a04b5906e9071da7b05e0b667 to your computer and use it in GitHub Desktop.
Save hugot/72f8c37a04b5906e9071da7b05e0b667 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# This is a short script to play rock paper scissors
use strict;
use warnings;
my @rps = qw(rock paper scissors);
my %weakness = (rock => "paper", paper => "scissors", scissors => "rock");
my $score = 0;
my $npcscore = 0;
print "\nWelcome, how many rounds would you like to play?\nI would like to play best of:";
chomp(my $rounds = <>);
for (my $i=1; $i<=$rounds; $i++) {
print "\n-------ROUND $i\-----\n";
GETVALUE: print "Do you pick Rock, Paper or scissors?\nI pick:";
chomp(my $pick = <>);
unless($pick =~ /^rock$|^paper$|^scissors$/i){
print "$pick is not a valid argument\n";
goto GETVALUE;
}
my $npcpick=$rps[rand(3)];
if($pick =~ /$npcpick/i){
print "You both picked $pick";
}
elsif($weakness{lc($pick)} !~ /$npcpick/i){
$score++;
print "Enemy picks: $npcpick You win this round! Your score: $score\n";
}
else {
$npcscore++;
print "Enemy picks: $npcpick You lose this round! Npc score: $npcscore\n";
}
}
if ($score > $npcscore){
print "\nNpc score: $npcscore Your score: $score\n","-"x5,"YOU ARE VICTORIOUS!","-"x5,"\n";
}
else {
print "\nNpc score: $npcscore, Your score: $score\n","-"x5,"YOU WERE UTTERLY CRUSHED","-"x5,"\n";
}
@hugot
Copy link
Author

hugot commented Feb 28, 2017

@Bramsterdam
Copy link

Wow $o cool, give thi$ guy a job at $ilicon valley.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment