Advertisement
Guest User

Cochons

a guest
May 23rd, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.45 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. my $end = undef;
  5. my $scoreRobot = 0;
  6. my $scorePlayer = 0;
  7. my $pointsManche = 0;
  8. my $scoreManche = 0;
  9.  
  10. my $stat1Point = 0.2097907;
  11. my $stat5Points = 0.409295 + $stat1Point;
  12. my $stat10Points = 0.07171503 + $stat5Points;
  13. my $stat15Points = 0.03024561 + $stat10Points;
  14. my $stat20Points = 0.07119105 + $stat15Points;
  15. my $stat25Points = 0.0005468955 + $stat20Points;
  16. my $stat40Points = 0.0007401518 + $stat25Points;
  17. my $stat60Points = 0.0001006128 + $stat40Points;
  18. my $stat0Point = 0.2025406 + $stat60Points;
  19. my $statBanqueroute = 0.003833333 + $stat0Point;
  20.  
  21. sub lanceDeDes {
  22.   my $rand = rand();
  23.   my $points = 0;
  24.   if ($rand < $stat1Point) {
  25.     $points = 1;
  26.   } elsif ($rand < $stat5Points) {
  27.     $points = 5;
  28.   } elsif ($rand < $stat10Points) {
  29.     $points = 10;
  30.   } elsif ($rand < $stat15Points) {
  31.     $points = 15;
  32.   } elsif ($rand < $stat20Points) {
  33.     $points = 20;
  34.   } elsif ($rand < $stat25Points) {
  35.     $points = 25;
  36.   } elsif ($rand < $stat40Points) {
  37.     $points = 40;
  38.   } elsif ($rand < $stat60Points) {
  39.     $points = 60;
  40.   } elsif ($rand < $stat0Point) {
  41.     $points = 0;
  42.   } else {
  43.     $points = -1;
  44.   }
  45.   return $points;
  46. }
  47.  
  48.  
  49.  
  50. print "Bienvenue dans le jeu du cochon!\n\n";
  51. while (!$end) {
  52.  
  53.   print "\nAppuyez sur Entree pour lancer les des, une autre touche pour passer\n";
  54.  
  55.   my $input = <STDIN>;
  56.   chomp $input;
  57.   if ($input eq "") {
  58.     $pointsManche = lanceDeDes();
  59.     if ($pointsManche > 0) {
  60.       print "Vous avez fait " . $pointsManche . " point\n";
  61.       $scorePlayer += $pointsManche;
  62.       if ($scorePlayer >= 100) {
  63.         print "Vous avez fait 100 points, vous avez gagné !\n\n";
  64.         $end = 1;
  65.       }
  66.     } else {
  67.       print "Vous avez fait faillite, vous avez perdu !\n";
  68.       $scorePlayer = 0;
  69.       $end = 1;
  70.     }
  71.  
  72.     print "Scores: " . $scorePlayer . " pour vous, " . $scoreRobot . " pour la machine.\n";
  73.  
  74.  
  75.   } else {
  76.     $scoreManche = 0;
  77.     while (!$end && $scoreManche < 15) {
  78.       $pointsManche = lanceDeDes();
  79.       if ($pointsManche < 0) {
  80.         print "L'ordinalteur a fait faillite, vous avez gagné !\n";
  81.         $end = 1;
  82.       } else {
  83.         $scoreManche += $pointsManche;
  84.         $scoreRobot += $pointsManche;
  85.         if ($scoreRobot >= 100) {
  86.           print "L'ordinateur a gagné !\n";
  87.           $end = 1;
  88.         }
  89.         print "Scores: " . $scorePlayer . " pour vous, " . $scoreRobot . " pour la machine.\n";
  90.       }
  91.     }
  92.   }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement