求助:"石头,剪刀,布"代码

求助:"石头,剪刀,布"代码

#!/usr/bin/perl

sub YourGo
{
   my $Turn = 0;
print "Enter 1-rock, 2-paper, 3-scissors\n";
chomp($Turn = <STDIN>);

   while(($Turn < 1) || ($Turn > 3))
{
     print "Enter 1-rock, 2-paper, 3-scissors\n";
                               chomp($Turn = <STDIN>);
                                 }
   return $Turn;
}

sub MyGo
{
return int(rand(3));
}sub PrintIntro
{
  print "\nRock, paper, scissors\n";  print "---------------------\n\n";print "Rock beats scissors,\n";
print "Scissors beats paper, \n";print "Paper beats rock.\n\n";}

sub PrintScore
{
   my ($you, $me, $draw) = @_;

   print "You scored $you, I scored $me with $draw draws.\n";
   if($you > $me)   { print "You are winning.\n";}
if($you < $me)
                   {print "I am winning.\n";
   }   print "\n\n";
}

sub Results
{
  my($my, $your) = @_;

  my $Test = $my - $your; if($Test == 0)

  {
    $_[4]++;  print " Draw.\n";
  }
  elsif(($Test == 1) || ($Test == -2))
  {$_[2]++;
    print " You won.\n";
  }
  else{ $_[2]++;
    print " I won.\n";
}

sub Continue
{
  my $Answer; print "\nAnother game? ";
print "DEBUG 1 $Answer\n";
  while(($Answer ne "n") && ($Answer ne "y")){
                       print "(y/n) ";
     chomp(my $Answer = <STDIN>);$Answer = lc ($Answer);
print "DEBUG 2 $Answer\n";
  }

  return ($Answer eq "y");
                                 
}

my @options = ("rock", "scissors", "paper");
   
my ($You, $Me, $Draw) = (0,0,0); my($my_turn, $your_turn);
my $More = 1;
  
&PrintIntro(); while($More)
   
  
{  $my_turn = &MyGo();
  $your_turn = &YourGo();
  print "Me: $options[$my_turn], You: $options[$my_turn] -- ";
   
  &Results($my_turn, $your_turn, $You, $Me, $Draw);&PrintScore($You, $Me, $Draw);

  $More = &Continue();
}
exit;

一段错误很多的代码(一个美国小孩写的),自己用use strict;use warnings;找了些语法错误。
大家帮忙看看
看什么?


#!/usr/bin/perl

use strict;
use warnings;

our ($You, $Me, $Draw) = (0,0,0);
my @options = ("rock", "paper", "scissors");
my($my_turn, $your_turn);

PrintIntro();

while(1) {  
        $my_turn = MyGo();
        $your_turn = YourGo()-1;
       
        print "Me: $options[$my_turn], You: $options[$your_turn] -- ";
   
        Results($my_turn, $your_turn);
        PrintScore($You, $Me, $Draw);

        last unless Continue();
}

sub PrintIntro {
        print "\nRock, paper, scissors\n";  
        print "---------------------\n\n";
        print "Rock beats scissors,\n";
        print "Scissors beats paper, \n";
        print "Paper beats rock.\n\n";
}

sub MyGo { return int(rand(3)); }

sub YourGo {
    my $Turn = 0;
        print "Enter 1-rock, 2-paper, 3-scissors\n";
        chomp($Turn = <STDIN>);

        while(($Turn < 1) || ($Turn > 3)) {
                print "Enter 1-rock, 2-paper, 3-scissors\n";
        chomp($Turn = <STDIN>);
    }
   
        return $Turn;
}

sub PrintScore {
        print "You scored $You, I scored $Me with $Draw draws.\n";
       
        if($You > $Me) {
                print "You are winning.\n";
        }

        if($You < $Me) {
                print "I am winning.\n";
        }
       
        print "\n\n";
}

sub Results {
        my($my, $your) = @_;
        my $Test = $my - $your;
       
        if($Test == 0) {
                $Draw++;  
                print " Draw.\n";
        } elsif ($Test == -1) {
                $You++;
                print " You won.\n";
        }  elsif ($Test == 2) {
                $You++;
                print " You won.\n";
        } else {
                $Me++;
            print " I won.\n";
        }
}

sub Continue {
        print "\nAnother game?(y/n): ";
        my $answer;
        while (1) {
                $answer = <STDIN>;
                chomp $answer;
                last if (lc $answer eq 'y') || (lc $answer eq 'n');
        }

        return $answer eq 'y';
}

台长