View sourcecode

The following files exists in this folder. Click to view.

CDice.php

1 lines ASCII Unix (LF)
1
<?php
/**
 * A CDice class to play around with a dice.
 *
 */
class CDice {

  /**
   * Properties
   *
   */
  private $lastRoll = array();



  /**
   * Constructor
   *
   */
  public function __construct() {
    ;
  }



  /**
   * Roll the dice
   *
   */
  public function Roll($times) {
    $this->lastRoll = array();
    for($i = 0; $i < $times; $i++) {
      $this->lastRoll[] = rand(1, 6);
    }
  }



  /**
   * Get the array that contains the last roll(s).
   *
   */
  public function GetResults() {
    return $this->lastRoll;
  }



  /**
   * Get the total from the last roll(s).
   *
   */
  public function GetTotal() {
    return array_sum($this->lastRoll);
  }

}