aboutsummaryrefslogtreecommitdiffstats
path: root/inc/mine.inc
blob: d27804a87630cd0b9effe0d993f0dd7a0661dfbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
 * Manages the mine.
 *
 * @packageĀ inc\mine.inc
 * @author     Alexandre Renoux
 * @author     Pierre-Emmanuel Novac
 */

/**
 * Initializes the gold amount and miners count in the session.
 *
 * @return void
 */
function initCraftMine() {
	$_SESSION["mine"] = array("gold" => 0, "miners" => 0);
}

/**
 * Transfers all gold from the mine to the player's account.
 *
 * @return void
 */
function withdrawMine() {
	$amount = intval($_POST["amount"]);
	if($amount == 0) return;
	$_SESSION["mine"]["gold"] += $amount;
	echo json_encode($_SESSION["mine"]["gold"]);
}

/**
 * Returns the amount of gold currently owned by the player.
 *
 * @return int  amount of gold available
 */
function sendMine() {
	if(empty($_SESSION["mine"])) initCraftMine();
	$mine = $_SESSION["mine"];
	return $mine["gold"];
}


?>