Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function printResult(int $dice, string $landedOn, int $position): void
- {
- echo sprintf("%d - %s%d\n", $dice, $landedOn, $position);
- }
- function playGame(int $maxScore): void
- {
- $position = 1;
- while ($position < $maxScore) {
- $dice = rand(1, 6);
- if ($position + $dice > $maxScore) {
- printResult($dice, '', $position);
- continue;
- }
- $position += $dice;
- if ($position % 9 == 0) {
- $position -= 3;
- printResult($dice, 'snake', $position);
- continue;
- }
- if (in_array($position, [25, 55])) {
- $position += 10;
- printResult($dice, 'ladder', $position);
- continue;
- }
- printResult($dice, '', $position);
- sleep(1);
- }
- }
- playGame(100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement