Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2.  
  3. function printResult(int $dice, string $landedOn, int $position): void
  4. {
  5. echo sprintf("%d - %s%d\n", $dice, $landedOn, $position);
  6. }
  7.  
  8. function playGame(int $maxScore): void
  9. {
  10. $position = 1;
  11.  
  12. while ($position < $maxScore) {
  13. $dice = rand(1, 6);
  14.  
  15. if ($position + $dice > $maxScore) {
  16. printResult($dice, '', $position);
  17. continue;
  18. }
  19.  
  20. $position += $dice;
  21.  
  22. if ($position % 9 == 0) {
  23. $position -= 3;
  24. printResult($dice, 'snake', $position);
  25. continue;
  26. }
  27.  
  28. if (in_array($position, [25, 55])) {
  29. $position += 10;
  30. printResult($dice, 'ladder', $position);
  31. continue;
  32. }
  33.  
  34. printResult($dice, '', $position);
  35. sleep(1);
  36. }
  37. }
  38.  
  39. playGame(100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement