Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. <?php
  2.  
  3. $pfc = ['pierre', 'feuille', 'ciseau'];
  4. $userChoice = readline("pierre, feuille ou ciseaux ? ");
  5.  
  6. if (!in_array($userChoice, $pfc)){
  7. echo "tu dois choisir pierre, feuille ou ciseaux\n";
  8. exit();
  9. }
  10. echo "tu peux jouer\n";
  11.  
  12. $pfc = ['pierre', 'feuille', 'ciseau'];
  13. $ordiChoice = $pfc[rand(0,2)];
  14. echo "Ton adversaire a choisi : $ordiChoice\n";
  15. if ($userChoice == $ordiChoice) {
  16. echo "egalité\n";
  17. exit();
  18. }
  19.  
  20. switch ($userChoice) {
  21. case 'pierre':
  22. if ($ordiChoice == 'ciseaux') {
  23. echo "Gagné\n";
  24. } else {
  25. echo "Perdu\n";
  26. }
  27. break;
  28. case 'feuille':
  29. if ($ordiChoice == 'pierre') {
  30. echo "Gagné\n";
  31. } else {
  32. echo "Perdu\n";
  33. }
  34. break;
  35. case 'ciseaux':
  36. if ($ordiChoice == 'feuille') {
  37. echo "Gagné\n";
  38. } else {
  39. echo "Perdu\n";
  40. }
  41. break;
  42. default:
  43. break;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement