Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- start:
- $mynum = int(rand(100));
- $mynum = $mynum +1;
- print "Game started! \nThe objective of the game is to work out which number I'm thinking of. \nThe number is between 1 and 100. \nStart guessing!\n";
- print "For development purposes, the number is $mynum\n";
- userinput:
- $myguess = <>;
- if ($myguess =~ m/^\s*\d+\s*$/) {
- if ($myguess > $mynum) {
- print "Your guess was too high! \nTry a lower number.\n";
- goto userinput;
- }
- elsif ($myguess < $mynum) {
- print "Your guess was too low! \nTry a higher number.\n";
- goto userinput;
- }
- elsif ($myguess == $mynum) {
- print "That was the number I was thinking of!\n";
- playagain:
- print "Play again? (y/n)\n";
- yesno:
- $yesno = <>;
- if ($yesno != m/^\s*(y|n|yes|no)\s*$/i) {
- print "That's not a valid response\n";
- goto playagain;
- }
- elsif ($yesno =~ m/^\s*(y|yes)\s*$/i) {
- goto start;
- }
- elsif ($yesno =~ m/^\s*(n|no)\s*$/i) {
- exit 0;
- }
- }
- }
- else {
- print "That's not a valid input. \nPlease input a number between 1 and 100.\n";
- goto userinput;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement