Källkod
Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.
webbserverprogrammering/exercises/classes_dice/
10 filer
Dice.php
DiceImage.php
Histogram.php
dice_1.php
dice_2.php
dice_3.php
dice_4.php
dice_5.php
dice_6.php
dice_7.php
DiceImage.php
Histogram.php
dice_1.php
dice_2.php
dice_3.php
dice_4.php
dice_5.php
dice_6.php
dice_7.php
dice_4.php
66 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Tärning 4</title>
<meta charset="utf-8">
<style type="text/css">
body {
font-family: Arial;
}
#histogram {
position: absolute;
top: 23vh;
left: 23vw;
font-family: Monospace;
}
.histogram-label {
white-space: pre;
}
</style>
</head>
<body>
<h2>En tärning</h2>
<?php
include("Dice.php");
include("Histogram.php");
if (isset($_GET["roll"]) && $_GET["roll"] > 0)
$rollCount = $_GET["roll"];
else
$rollCount = 6;
echo "<p>En tärning med 6 sidor kastas $rollCount gånger.</p>";
?>
Kasta: <a href="?roll=3">3 gånger</a>, <a href="?roll=6">6 gånger</a>, <a href="?roll=11">11 gånger</a>, <a href="?roll=26">26 gånger</a>.
Default är 6 gånger. Alla heltal större än 0 är tillåtna.
<?php
$myDice = new Dice(); // default is 6 faces
$myDice->roll($rollCount); // roll X times
$myDice->printRolls();
// parameters are the values & maximum possible value
// the highest roll might not be the maximum possible value, it is recommended to use both parameters.
// Default value of "max possible value" is the actual highest value in values-array
Histogram::getHistogram($myDice->getRolls(), $myDice->getFaces());
?>
<p><strong>Summa:</strong> <?= $myDice->getSumOfRolls() ?></p>
<p><strong>Medelvärde:</strong> <?= $myDice->getAverageRoll() ?></p>
</body>
</html>