Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Player {
- var $name;
- var $exp = 1;
- var $xp = 0;
- var $max_xp = 100;
- var $wealth = 0;
- var $health = 100;
- function __construct($name) {
- $this->name = $name;
- }
- function initXp() {
- $factor = 1.11;
- $this->max_xp *= $factor;
- }
- function raiseXp($amount) {
- $this->xp += $amount;
- if ($this->xp >= $this->max_xp) {
- $this->levelUp($this->xp - $this->max_xp);
- }
- }
- function levelUp($leftover) {
- $reward = 5 * $this->rank;
- $this->exp++;
- $this->xp = $leftover;
- $this->initXp();
- }
- function setHealth($value) {
- if ($value > 0 && $value < 101) {
- $this->health = $value;
- }
- }
- function increaseHealth($amount) {
- if (100 - $this->health >= $amount) {
- $this->health += $amount;
- } else {
- $this->health = 100;
- }
- }
- function decreaseHealth($amount) {
- $this->health -= $amount;
- if ($this->health <= 0) {
- $this->goToHospital();
- }
- }
- function goToHospital() {
- $this->setHealth(70);
- $this->forceDecreaseWealth(300);
- }
- function increaseWealth($amount) {
- $this->wealth += $amount;
- }
- function decreaseWealth($amount) {
- if ($this->wealth >= $amount) {
- $this->wealth -= $amount;
- } else {
- // Error
- }
- }
- function forceDecreaseWealth($amount) {
- if ($this->wealth >= $amount) {
- $this->wealth -= $amount;
- } else {
- $this->wealth -= $amount;
- $debt = $this->wealth - $this->wealth * 2;
- }
- }
- }
- ?>
- <?php
- // Include controllers
- include "controller/player.php";
- // Start session handler
- session_start();
- // Check if there's a login session active
- if (isset($_SESSION["player"])) {
- $player = $_SESSION["player"];
- } else {
- $_SESSION["player"] = new Player('Testspeler');
- $player = $_SESSION["player"];
- }
- ?>
- <?php
- class Crime {
- var $reward;
- var $xp_boost;
- var $probability;
- function __construct($reward, $xp_boost, $probability) {
- $this->reward = $reward;
- $this->xp_boost = $xp_boost;
- $this->probability = $probability;
- }
- function commit() {
- $result = mt_rand(0, 101);
- if ($result <= $this->probability) {
- return true;
- } else {
- return false;
- }
- }
- }
- $crimes = array(
- "Winkelwagens stelen" => new Crime(1, $player->rank, 80)
- );
- ?>
- <table>
- <tr>
- <th colspan="100%">Misdaden</th>
- </tr>
- <tr>
- <th>Misdaad</th>
- <th>XP</th>
- <th>Geld</th>
- <th>Waarschijnlijkheid</th>
- <th></th>
- </tr>
- <?php foreach ($crimes as $x => $y) : ?>
- <tr>
- <td><?php echo $x; ?></td>
- <td><?php echo $y->xp_boost; ?></td>
- <td><?php echo $y->reward; ?></td>
- <td><?php echo $y->probability; ?></td>
- <td><!-- Somehow call $y->commit() when the user clicks? --></td>
- </tr>
- <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement