Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. <?php
  2. class Player {
  3. var $name;
  4. var $exp = 1;
  5. var $xp = 0;
  6. var $max_xp = 100;
  7. var $wealth = 0;
  8. var $health = 100;
  9. function __construct($name) {
  10. $this->name = $name;
  11. }
  12. function initXp() {
  13. $factor = 1.11;
  14. $this->max_xp *= $factor;
  15. }
  16. function raiseXp($amount) {
  17. $this->xp += $amount;
  18. if ($this->xp >= $this->max_xp) {
  19. $this->levelUp($this->xp - $this->max_xp);
  20. }
  21. }
  22. function levelUp($leftover) {
  23. $reward = 5 * $this->rank;
  24. $this->exp++;
  25. $this->xp = $leftover;
  26. $this->initXp();
  27. }
  28. function setHealth($value) {
  29. if ($value > 0 && $value < 101) {
  30. $this->health = $value;
  31. }
  32. }
  33. function increaseHealth($amount) {
  34. if (100 - $this->health >= $amount) {
  35. $this->health += $amount;
  36. } else {
  37. $this->health = 100;
  38. }
  39. }
  40. function decreaseHealth($amount) {
  41. $this->health -= $amount;
  42. if ($this->health <= 0) {
  43. $this->goToHospital();
  44. }
  45. }
  46. function goToHospital() {
  47. $this->setHealth(70);
  48. $this->forceDecreaseWealth(300);
  49. }
  50. function increaseWealth($amount) {
  51. $this->wealth += $amount;
  52. }
  53. function decreaseWealth($amount) {
  54. if ($this->wealth >= $amount) {
  55. $this->wealth -= $amount;
  56. } else {
  57. // Error
  58. }
  59. }
  60. function forceDecreaseWealth($amount) {
  61. if ($this->wealth >= $amount) {
  62. $this->wealth -= $amount;
  63. } else {
  64. $this->wealth -= $amount;
  65. $debt = $this->wealth - $this->wealth * 2;
  66. }
  67. }
  68. }
  69. ?>
  70.  
  71. <?php
  72. // Include controllers
  73. include "controller/player.php";
  74.  
  75. // Start session handler
  76. session_start();
  77.  
  78. // Check if there's a login session active
  79. if (isset($_SESSION["player"])) {
  80. $player = $_SESSION["player"];
  81. } else {
  82. $_SESSION["player"] = new Player('Testspeler');
  83. $player = $_SESSION["player"];
  84. }
  85. ?>
  86.  
  87. <?php
  88. class Crime {
  89. var $reward;
  90. var $xp_boost;
  91. var $probability;
  92. function __construct($reward, $xp_boost, $probability) {
  93. $this->reward = $reward;
  94. $this->xp_boost = $xp_boost;
  95. $this->probability = $probability;
  96. }
  97. function commit() {
  98. $result = mt_rand(0, 101);
  99. if ($result <= $this->probability) {
  100. return true;
  101. } else {
  102. return false;
  103. }
  104. }
  105. }
  106. $crimes = array(
  107. "Winkelwagens stelen" => new Crime(1, $player->rank, 80)
  108. );
  109. ?>
  110.  
  111. <table>
  112. <tr>
  113. <th colspan="100%">Misdaden</th>
  114. </tr>
  115. <tr>
  116. <th>Misdaad</th>
  117. <th>XP</th>
  118. <th>Geld</th>
  119. <th>Waarschijnlijkheid</th>
  120. <th></th>
  121. </tr>
  122. <?php foreach ($crimes as $x => $y) : ?>
  123. <tr>
  124. <td><?php echo $x; ?></td>
  125. <td><?php echo $y->xp_boost; ?></td>
  126. <td><?php echo $y->reward; ?></td>
  127. <td><?php echo $y->probability; ?></td>
  128. <td><!-- Somehow call $y->commit() when the user clicks? --></td>
  129. </tr>
  130. <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement