Skip to content

Instantly share code, notes, and snippets.

@susanBuck
Created October 13, 2023 02:36
Show Gist options
  • Save susanBuck/38c993877b2ee38658ebb94c3ace6c3c to your computer and use it in GitHub Desktop.
Save susanBuck/38c993877b2ee38658ebb94c3ace6c3c to your computer and use it in GitHub Desktop.
Example for nolinanna
<h2>Results</h2>
<ul>
<?php foreach($results as $player => $result) { ?>
<li><?php echo $player ?></li>
<ul>
<?php for($i = 1; $i <= 3; $i++) { ?>
<li>
Turn <?php echo $i; ?>:
Rolled <?php echo implode(', ', $result['turn'.$i]) ?>
with a max of <?php echo $result['maxTurn'.$i]; ?></li>
<?php } ?>
<li>Sum: <?php echo $result['sum']?></li>
</ul>
<?php } ?>
<li>
Results:
<?php if($winner == 'Tie') { ?>
It was a tie.
<?php } elseif($winner == 'Player A') { ?>
Player A won
<?php } else { ?>
Player B won
<?php } ?>
</li>
</ul>
<?php
$players = ['Player 1', 'Player 2'];
foreach($players as $player) {
$turns = [
'turn1' => [rand(1, 6), rand(1, 6), rand(1, 6)],
'turn2' => [rand(1, 6), rand(1, 6)],
'turn3' => [rand(1, 6)]
];
$turns['maxTurn1'] = max($turns['turn1']);
$turns['maxTurn2'] = max($turns['turn2']);
$turns['maxTurn3'] = max($turns['turn3']);
$turns['sum'] = $turns['maxTurn1'] + $turns['maxTurn2'] + $turns['maxTurn3'];
$results[$player] = $turns;
}
if($results['Player 1']['sum'] == $results['Player 2']['sum']) {
$winner = 'Tie';
} elseif($results['Player 1']['sum'] > $results['Player 2']['sum']) {
$winner = 'Player 1';
} else {
$winner = 'Player 2';
}
require 'index-view.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment