<?php
class Auto
{
public $merk = 'onbekend';
public $kleur = 'onbekend';
public $nummerbord = 'on-be-kend';
protected $snelheid = 0;
protected $maxSnelheid = 150; //sneller dan dit mag de auto niet gaan
protected $lichten = false; //lichten standaard uit
public function __construct($merk, $kleur, $nummerbord)
{
$this->merk = $merk;
$this->kleur = $kleur;
$this->nummerbord = $nummerbord;
$this->lichten = rand(0, 1);
}
public function geefGas($snelheid = 5)
{
$this->snelheid += $snelheid; //Let op dat je hier niet in de war raakt!
if($this->snelheid > $this->maxSnelheid)
{
$this->snelheid = $this->maxSnelheid;
}
}
public function geefMinderGas($snelheid = 5)
{
$this->snelheid -= $snelheid; //natuurlijk kun je dit ook bereiken met de vorige method, bij een snelheid van -5 ;)
if($this->snelheid < 0-$this->maxSnelheid)
{
$this->snelheid = 0-$this->maxSnelheid;
}
}
public function kijkOpSnelheidsmeter()
{
return $this->snelheid;
}
public function handrem()
{
$snelheid = $this->snelheid; //de oude snelheid bewaren
$this->snelheid = 0;
$this->botsing($snelheid); //roep een andere method aan
}
public function switchLichten()
{
$this->lichten = !$this->lichten;
return $this->lichten;
}
private function botsing($beginsnelheid)
{
if(!rand(0, 9) || $beginsnelheid > 100 || $beginsnelheid < -100)
{
return true;
}
else
{
return false;
}
}
}
class Ferrari extends Auto
{
protected $maxSnelheid = 355;
public function geefGas($snelheid = 10) //door de 10 trekt de ferrari twee keer zo snel op!
{
$this->snelheid += $snelheid; //Let op dat je hier niet in de war raakt!
if($this->snelheid > $this->maxSnelheid)
{
$this->snelheid = $this->maxSnelheid;
}
}
}
class Audi extends Auto
{
protected $maxSnelheid = 76;
public function __construct($merk, $kleur, $nummerbord)
{
$this->merk = $merk;
$this->kleur = $kleur;
$this->nummerbord = $nummerbord;
//we willen niet dat hier de lichten aan kunnen gaan!
//$this->lichten = rand(0, 1);
}
public function switchLichten()
{
return false;
}
}
class BMW extends Auto
{
public function handrem(){} //geen handrem meer!
public function kijkOpSnelheidsmeter()
{
return $this->snelheid + rand(-10, 10);
}
}
?>