aboutsummaryrefslogtreecommitdiffstats
path: root/inc/perso.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/perso.inc')
-rw-r--r--inc/perso.inc27
1 files changed, 27 insertions, 0 deletions
diff --git a/inc/perso.inc b/inc/perso.inc
index f455173..c81b72b 100644
--- a/inc/perso.inc
+++ b/inc/perso.inc
@@ -1,17 +1,39 @@
<?php
+/**
+ * Manages player's stats: life, experience, level.
+ *
+ * @author Alexandre Renoux
+ * @author Pierre-Emmanuel Novac
+ */
+/**
+ * Returns all player's stats after initializing them if needed.
+ *
+ * @return int[] arrays containing player's stats
+ */
function sendPerso() {
if(empty($_SESSION["perso"]))
initPerso();
return $_SESSION["perso"];
}
+/**
+ * Increases a player's stat.
+ *
+ * @param int $prop stat to increase
+ * @return void
+ */
function increasePerso($prop, $num) {
if(empty($_SESSION["perso"]))
initPerso();
$_SESSION["perso"][$prop] += $num;
}
+/**
+ * Copies stats given in POST request to session.
+ *
+ * @return void
+ */
function updatePerso(){
$hp = $_POST["hp"];
$xp = $_POST["xp"];
@@ -21,6 +43,11 @@ function updatePerso(){
$_SESSION["perso"]["lv"] = +$lv;
}
+/**
+ * Initializes the player's stats.
+ *
+ * @return void
+ */
function initPerso(){
$_SESSION["perso"]["hp"] = 5;
$_SESSION["perso"]["xp"] = 0;