Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2. $weapons = ['fists', 'whip', 'gun', 'nuclear']; // don't change the order of weapon élément in the array
  3. $opponentWeapon = rand(0,count($weapons)-1);
  4.  
  5. echo 'The weapon of the opponent is <b>' . $weapons[$opponentWeapon] . '</b><br/><br/>';
  6.  
  7. switch ($opponentWeapon) {
  8. case 0:
  9. // The gun beats the fists
  10. $indyWeapon = 2;
  11. break;
  12. case 1:
  13. // The fists beat the whip
  14. $indyWeapon = 0;
  15. break;
  16. case 2:
  17. // The whip beats the gun
  18. $indyWeapon = 1;
  19. break;
  20. default:
  21. $indyWeapon = -1;
  22. break;
  23. }
  24.  
  25. if (-1 == $indyWeapon) // Yoga test -;)
  26. echo 'This case isn\'t considered';
  27. else
  28. echo 'Indy choose <b>' . $weapons[$indyWeapon] . '</b> to fight with the opponent';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement