No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

54 líneas
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;
}
}