Je kunt niet meer dan 25 onderwerpen selecteren Onderwerpen moeten beginnen met een letter of nummer, kunnen streepjes bevatten ('-') en kunnen maximaal 35 tekens lang zijn.

54 regels
1.2 KiB
PHP

<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
class Energy {
private $energy = 0;
private $maxenergy = 0;
public function __construct(int $energy, int $max) {
if ($energy < 0) {
$energy = 0;
}
if ($max < $energy) {
$energy = $max;
}
$this->energy = $energy;
$this->maxenergy = $max;
}
public function getEnergy(): int {
return $this->energy;
}
public function setEnergy(int $energy) {
if ($energy <= 0) {
$energy = 0;
}
if ($energy > $this->maxenergy) {
$energy = $this->maxenergy;
}
$this->energy = $energy;
}
public function getMaxEnergy(): int {
return $this->maxenergy;
}
public function setMaxEnergy(int $maxenergy) {
if ($maxenergy < 0) {
$maxenergy = 0;
}
if ($this->energy > $maxenergy) {
$this->energy = $maxenergy;
}
$this->maxenergy = $maxenergy;
}
}