Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- use strict;
- use v5.32.1;
- my $scoreBoard = 10;
- #our $rounds = 3;
- my $limit = 20;
- my $hiddenNumber = int(rand($limit));
- my $name;
- my $number = 0;
- sub welcome_screen() {
- say "\tWelcome to find the Hidden Number";
- while(!$name) {
- say "Please provide your name : ";
- $name = <STDIN>;
- }
- print "Okay ", ucfirst($name), " let\'s start the game.";
- print q\
- You will try entering the correct number that computer thinks.
- If you nailed it, you will get the full score of 10.
- If you failed to guess it, the game will end.\, "\n\n";
- }
- sub main_program{
- while($number != $hiddenNumber) {
- say "Type the hidden number:";
- chomp($number = <STDIN>);
- if($number > $limit) {
- $scoreBoard = $scoreBoard - 3;
- say "It's too high!";
- } elsif ($number < $hiddenNumber){
- $scoreBoard = $scoreBoard - 1;
- say "It's too low!";
- }
- if($scoreBoard == 0 or $scoreBoard < 0) {
- say "GAME OVER";
- say "The Secret Number is :", $hiddenNumber ;
- last;
- } elsif($number == $hiddenNumber and $scoreBoard == 10) {
- say "YOU WON THE GAME! CONGRATULATIONS!";
- say "Total Score : ", $scoreBoard;
- say "The Secret Number is :", $hiddenNumber;
- last;
- } elsif($number == $hiddenNumber) {
- say "You did a good job ", ucfirst($name), $hiddenNumber ," is the secret number.";
- say "Total Score : ", $scoreBoard;
- }
- }
- }
- welcome_screen();
- main_program();
Add Comment
Please, Sign In to add comment