Game server and admin dashboard for TerranQuest.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Energy.lib.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. class Energy {
  8. private $energy = 0;
  9. private $maxenergy = 0;
  10. public function __construct(int $energy, int $max) {
  11. if ($energy < 0) {
  12. $energy = 0;
  13. }
  14. if ($max < $energy) {
  15. $energy = $max;
  16. }
  17. $this->energy = $energy;
  18. $this->maxenergy = $max;
  19. }
  20. public function getEnergy(): int {
  21. return $this->energy;
  22. }
  23. public function setEnergy(int $energy) {
  24. if ($energy <= 0) {
  25. $energy = 0;
  26. }
  27. if ($energy > $this->maxenergy) {
  28. $energy = $this->maxenergy;
  29. }
  30. $this->energy = $energy;
  31. }
  32. public function getMaxEnergy(): int {
  33. return $this->maxenergy;
  34. }
  35. public function setMaxEnergy(int $maxenergy) {
  36. if ($maxenergy < 0) {
  37. $maxenergy = 0;
  38. }
  39. if ($this->energy > $maxenergy) {
  40. $this->energy = $maxenergy;
  41. }
  42. $this->maxenergy = $maxenergy;
  43. }
  44. }