<?php
<?php
interface Randomizer {
public function randomize();
}
class PHPRandRandomizer implements Randomizer {
public function randomize() {
return rand(1, 10);
}
}
class LetterRandomizer implements Randomizer {
private $letters = array('a','b','c','d','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
public function randomize() {
echo $this->letters[rand(1,24)];
}
}
class Matrix {
private $randomizer;
private $running = false;
private $counter = 0;
public function __construct(Randomizer $randomizer) {
$this->randomizer = $randomizer;
}
public function start() {
$this->running = true;
$this->run();
}
public function stop() {
$this->running = false;
}
public function run() {
while($this->running) {
$this->counter++;
// Alles in de console heel snel na elkaar uit echo'en om een matrix effect te creeƫren.
echo $this->randomizer->randomize();
if ($this->counter > 50000000) { // De matrix stopt na een x aantal keren.
$this->stop();
}
}
}
}
$matrix = new Matrix(new LetterRandomizer); // Hier gebruiken we een letter randomizer, maar je kan ook de PHPRandRandomizer gebruiken, met cijfertjes.
$matrix->start();