aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--craftmine.php3
-rw-r--r--data/monsters.xml9
-rw-r--r--inc/Monster.inc4
-rw-r--r--inc/craftmine.inc2
-rw-r--r--inc/dungeon.inc5
-rw-r--r--inc/perso.inc17
-rw-r--r--index.xhtml4
-rw-r--r--js/craftmine.js13
-rw-r--r--js/dungeon.js38
-rw-r--r--js/perso.js5
10 files changed, 83 insertions, 17 deletions
diff --git a/craftmine.php b/craftmine.php
index 43fdc66..d47989c 100644
--- a/craftmine.php
+++ b/craftmine.php
@@ -6,6 +6,7 @@ require_once("inc/shop.inc");
require_once("inc/craftmine.inc");
require_once("inc/dungeon.inc");
require_once("inc/savegame.inc");
+require_once("inc/perso.inc");
session_start(); // Must be placed *BEFORE* $_SESSION is actually used and *AFTER* all classes are imported
@@ -52,6 +53,8 @@ switch($op) {
case "launchDungeon" : launchDungeon(); break;
case "exitDungeon" : exitDungeon(); break;
case "sendDungeonProgress" : sendDungeonProgress(); break;
+ case "updatePerso" : updatePerso(); break;
+ case "sendPerso" : sendPerso(); break;
case "saveGame": saveGame(); break;
case "downSave": downSave(); break;
case "listSaves": listSaves(); break;
diff --git a/data/monsters.xml b/data/monsters.xml
index 630e83a..ab29364 100644
--- a/data/monsters.xml
+++ b/data/monsters.xml
@@ -5,18 +5,21 @@
<name>monster1</name>
<level>1</level>
<hp>3</hp>
+ <xp>1</xp>
<icon>m</icon>
</monster>
<monster >
<name>monster2</name>
<level>2</level>
<hp>3</hp>
+ <xp>2</xp>
<icon>m</icon>
</monster>
<monster>
<name>monster3</name>
<level>3</level>
<hp>4</hp>
+ <xp>3</xp>
<icon>m</icon>
</monster>
</floor>
@@ -25,18 +28,21 @@
<name>monster4</name>
<level>4</level>
<hp>5</hp>
+ <xp>4</xp>
<icon>m</icon>
</monster>
<monster>
<name>monster5</name>
<level>5</level>
<hp>6</hp>
+ <xp>5</xp>
<icon>m</icon>
</monster>
<monster>
<name>monster5</name>
<level>6</level>
<hp>7</hp>
+ <xp>6</xp>
<icon>m</icon>
</monster>
</floor>
@@ -45,18 +51,21 @@
<name>monster6</name>
<level>8</level>
<hp>9</hp>
+ <xp>8</xp>
<icon>m</icon>
</monster>
<monster>
<name>monster7</name>
<level>9</level>
<hp>10</hp>
+ <xp>9</xp>
<icon>m</icon>
</monster>
<monster>
<name>Boss</name>
<level>10</level>
<hp>12</hp>
+ <xp>10</xp>
<icon>m</icon>
</monster>
</floor>
diff --git a/inc/Monster.inc b/inc/Monster.inc
index fbb0fe9..c7063ec 100644
--- a/inc/Monster.inc
+++ b/inc/Monster.inc
@@ -5,12 +5,14 @@ class Monster {
public $icon = "";
public $desc = "";
public $hp = 1;
+ public $xp = 0;
public $level = 1;
- function __construct($name, $level, $hp, $icon) {
+ function __construct($name, $level, $hp, $xp, $icon) {
$this->name = $name;
$this->level = $level;
$this->hp = $hp;
+ $this->xp = $xp;
$this->icon = $icon;
}
diff --git a/inc/craftmine.inc b/inc/craftmine.inc
index 0d6a445..f5dbbb1 100644
--- a/inc/craftmine.inc
+++ b/inc/craftmine.inc
@@ -3,6 +3,7 @@
require_once("mine.inc");
require_once("shop.inc");
require_once("dungeon.inc");
+require_once("perso.inc");
function sendCraftMine() {
$data = array("gold" => sendMine(),
@@ -10,6 +11,7 @@ function sendCraftMine() {
"inventory" => Inventory::sendContent(),
"miners" => sendMiners(),
"dungeon" => sendDungeon(),
+ "perso" => sendPerso(),
);
echo json_encode($data);
}
diff --git a/inc/dungeon.inc b/inc/dungeon.inc
index ebe74b7..c023cf8 100644
--- a/inc/dungeon.inc
+++ b/inc/dungeon.inc
@@ -12,8 +12,9 @@ function generateMonster(){
$dungeon["monsters"][$floor] = array();
foreach($f as $monster){
$dungeon["monsters"][$floor][] = new Monster((string)$monster->name,
- intval($monster->level),
- intval($monster->hp),
+ intval($monster->level),
+ intval($monster->hp),
+ intval($monster->xp),
(string)$monster->icon);
}
}
diff --git a/inc/perso.inc b/inc/perso.inc
new file mode 100644
index 0000000..075f8ae
--- /dev/null
+++ b/inc/perso.inc
@@ -0,0 +1,17 @@
+<?php
+function sendPerso() {
+ if(!empty($_SESSION["perso"]))
+ return $_SESSION["perso"];
+ else return false;
+}
+
+function updatePerso(){
+ $hp = $_POST["hp"];
+ $xp = $_POST["xp"];
+ $lv = $_POST["lv"];
+ $_SESSION["perso"]["hp"] = $hp;
+ $_SESSION["perso"]["xp"] = $xp;
+ $_SESSION["perso"]["lv"] = $lv;
+}
+
+?>
diff --git a/index.xhtml b/index.xhtml
index ed3e7a6..7921cab 100644
--- a/index.xhtml
+++ b/index.xhtml
@@ -17,6 +17,7 @@
<script type="text/javascript" charset="utf-8" src="js/gui.js"></script>
<script type="text/javascript" charset="utf-8" src="js/dungeon.js"></script>
<script type="text/javascript" charset="utf-8" src="js/savegame.js"></script>
+ <script type="text/javascript" charset="utf-8" src="js/perso.js"></script>
</head>
<body onload="init()" onhashchange="changeTab()">
<div class="container-fluid">
@@ -24,6 +25,9 @@
<h1>CraftMine</h1>
</div>
<div class="row">
+ <span id="perso">HP : <span id="hp">5</span>/ LV : <span id="lv">1</span>/ exp : <span id="xp">0</span></span>
+</div>
+<div class="row">
<div class="col-md-4">
<div class="row">
<div class="col-md-10">
diff --git a/js/craftmine.js b/js/craftmine.js
index 9af9b9f..c7a396f 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -5,6 +5,7 @@ data = {
miners: 0,
level: 4,
hp: 5,
+ xp: 0,
icon : "H"
}
@@ -52,12 +53,20 @@ function withdrawMine() {
function initCraftMine() {
sendRequest("craftmine.php", "op=getCraftMine", function(ret) {
+ console.log(ret.perso);
data.gold = parseInt(ret.gold); // Server's response is a string
data.mine = 0; // Reset mine
+ if(ret.perso){
+ data.hp = ret.perso.hp;
+ data.xp = ret.perso.xp;
+ data.level = ret.perso.lv;
+ displayPerso(ret.perso.hp,ret.perso.xp,ret.perso.lv);
+ }
if(ret.shop) displayShop(ret.shop);
displayInventory(ret.inventory);
- if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true);
- else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true);
+ if(ret.dungeon == false){}//if we have left the donjon
+ else if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); //if we have reload just after buying the ticket
+ else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true);//if we have reload in the middle of the dungeon
data.miners = parseInt(ret.miners);
updateData("gold", "mine", "miners");
})
diff --git a/js/dungeon.js b/js/dungeon.js
index c6ce014..65d1081 100644
--- a/js/dungeon.js
+++ b/js/dungeon.js
@@ -50,11 +50,12 @@ function strike(ret,nb, f){
var mobLife = document.getElementById("lifeMob").innerHTML;
var persoLife = document.getElementById("lifePerso").innerHTML;
if(mobLife == 0){
- endBattle("perso",nb,f);
+ data.hp = persoLife;
+ endBattle("perso",nb,f,ret);
return;
}
else if(persoLife == 0){
- endBattle("mob",nb);
+ endBattle("mob",nb,f,ret);
return;
}
if(hitRate<50+10*lvDiff){
@@ -68,19 +69,32 @@ function strike(ret,nb, f){
battle(ret,nb,f);
}
-function endBattle(v,nb, f){
+function endBattle(v,nb, f, ret){
window.clearTimeout(timeout);
if(v=="mob")exitDungeon();//if you die in the dungeon, you are immediately sent out of the dungeon
- nb++;//go to the next mob in the same floor
- if(nb>=3){//floor changing
- nb=0;//reset the number of the mob
- f++;//increment the number of the floor
+ //To level up you have to obtain 2 xp to go to lv 3, 3 to go to lv 4, etc
+ //A mob level 2 , if defeated gives you 2 xp, ...etc
+ else{
+ data.xp += ret[nb].xp;
+ if(data.xp>=data.level){
+ data.xp-=data.level;
+ data.level++;
+ //need to send the xp to the server
+ sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){
+ displayPerso(data.hp,data.xp,data.level);
+ });
+ }
+ nb++;//go to the next mob in the same floor
+ if(nb>=3){//floor changing
+ nb=0;//reset the number of the mob
+ f++;//increment the number of the floor
+ }
+ var tmphtml = "Le " + v + " a gagné.";
+ tmphtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"launchDungeon("+nb+","+ f +",false)\">Next Battle</button>"
+ document.getElementById("tab4").innerHTML = tmphtml;
+ displayExit();
+ sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb);
}
- var tmphtml = "Le " + v + " a gagné.";
- tmphtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"launchDungeon("+nb+","+ f +",false)\">Next Battle</button>"
- document.getElementById("tab4").innerHTML = tmphtml;
- displayExit();
- sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb);
}
function displayExit(){
diff --git a/js/perso.js b/js/perso.js
new file mode 100644
index 0000000..365cf54
--- /dev/null
+++ b/js/perso.js
@@ -0,0 +1,5 @@
+function displayPerso(hp,xp,lv){
+ document.getElementById("hp").innerHTML = hp;
+ document.getElementById("lv").innerHTML = lv;
+ document.getElementById("xp").innerHTML = xp;
+}