Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # Programa de prueba para Tiempo de Tux <http://www.itimetux.com>
- # Por Demianx864
- # Eres libre de estudiar modificar y añadir nuevas cosas a el programa,que te diviertas :D
- use feature qw{ switch };
- system('clear');
- print "Nombre de jugador : ";
- my $nombre = <STDIN>; chop($nombre);
- my ($score,$score_cpu,$juegos) = (0,0,0);
- my ($nj,$e) = (undef,undef);
- my @cpu = ("piedra","papel","tijeras");
- print "Numero de juegos : ";
- while ($nj = <STDIN>) {
- chop $nj;
- given ($nj) {
- when(/\d/) { last; }
- when(/\D/) { print "Numero de juegos (numeros) : "; continue ;}
- default { continue; }
- } }
- &elejir();
- sub elejir {
- print "Piedra papel o tijeras : ";
- while (my $eleccion = <STDIN>) {
- chop($eleccion);
- given ($eleccion) {
- when(/piedra/i) { $e = 'piedra'; last; }
- when(/papel/i) { $e = 'papel'; last; }
- when(/tijeras/i) { $e = 'tijeras'; last; }
- default {
- print "Opcion incorrecta intenta de nuevo : "; continue }
- } }
- my @n = (0...2); my $i = $n[int rand @n];
- &juego($e,$cpu[$i]);
- }
- sub juego {
- my ($jugador,$pc) = @_;
- system ('clear');
- print "Resultado : \n\n";
- print "$nombre : $jugador " . "CPU : $pc";
- if ($jugador eq $pc) {
- print "\tEs un empate\n";
- } elsif ($jugador eq "piedra") {
- if ($pc eq "tijeras") {
- print "\t$nombre gana\n"; $score = $score + 1;
- } else {
- print "\tCPU gana\n"; $score_cpu = $score_cpu + 1;
- }
- } elsif ($jugador eq "papel") {
- if ($pc eq "piedra") {
- print "\t$nombre gana\n"; $score = $score + 1;
- } else {
- print "\tCPU gana\n"; $score_cpu = $score_cpu + 1;
- }
- } else {
- if ($pc eq "piedra") {
- print "\tCPU gana\n"; $score_cpu = $score_cpu + 1;
- } else {
- print "\t$nombre gana\n"; $score = $score + 1;
- }
- }
- $juegos = $juegos + 1;
- print "\n$nombre Score : $score CPU Score : $score_cpu\n\n";
- &volver();
- }
- sub volver {
- if ( $juegos == $nj ) {
- print "$nombre Score Final : $score CPU Score final : $score_cpu\n\n";
- if ( $score < $score_cpu ) {
- print "CPU Gana $score_cpu a $score\n";
- } elsif ( $score > $score_cpu ) {
- print "$nombre Gana $score a $score_cpu\n";
- } elsif ( $score == $score_cpu ) {
- print "Es un empate :O\n"
- } else { print "Error inesperado :("; }
- } else { &elejir; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement