aboutsummaryrefslogtreecommitdiffstats
path: root/js/craftmine.js~
blob: bc03d6c1080804c2849d62bcd340cc94f87d219a (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
44
45
46
47
48
49
50
51
datas = {
	gold: 0,
	mine: 0,
	miners: 1,
	level: 1
}

function sendRequest(url, params, callback) {
	var xhr = new XMLHttpRequest();
	xhr.open("POST", url);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.onreadystatechange = function() {
		if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") {
			callback(xhr);
		}
	}
	xhr.send(params);
}


function updateDatas(t) {
	document.getElementById(t).innerHTML = datas[t];
}

function withdrawMine() {
	sendRequest("craftmine.php", "op=withdrawMine", function() {
		datas.gold += parseInt(datas.mine);
		datas.mine = 0;
		updateDatas("gold");
		updateDatas("mine");
	})
}

function initCraftMine() {
	sendRequest("craftmine.php", "op=getCraftMine", function(xhr) {
		var ret = xhr.responseText;
		datas.gold = ret;
		updateDatas("gold");
	})
}


function updateMine() {
	datas.mine += (datas.mineurs+1);
	updateDatas("mine");
}

function init() {
	initCraftMine();
	window.setInterval(updateMine, 1000);
}