Show sourcecode
The following files exists in this folder. Click to view.
webbserv1-dice/exercises/dice4/
CDice.php
CHistogram.php
dice-4.php
CDice.php
46 lines ASCII Unix (LF)
<?php
/**
* A CDice class to play around with a dice.
*
*/
class CDice {
/**
* Properties
*
*/
public $rolls = array();
/**
* Roll the dice
*
*/
public function Roll($times) {
$this->rolls = array();
for($i = 0; $i < $times; $i++) {
$this->rolls[$i] = rand(1, 6);
}
}
/**
* Get the total from the last roll(s).
*
*/
public function GetTotal() {
return array_sum($this->rolls);
}
/**
* Get the average from the last roll(s).
*
*/
public function GetAverage() {
return round(array_sum($this->rolls) / count($this->rolls), 1);
}
}
?>
