1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?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;
- }
-
- }
|