Ich hab angefangen ein Idlegame zu schreiben. Bin noch nicht sehr weit. Hab jetzt erst neu mit Javascript angefangen.
Habe jetzt einen Button der soll Coins abziehen und der variable button 1 hinzufügen. Nur der Button macht nichts und wenn ich die eine Variable definiert habe gehen auch meine timer nicht mehr.
PHP Code:
var coins = parseInt(document.getElementById('coins').innerHTML);
function coinsClick(number){
if(button != 0){
coins = coins + number;
} else {
coins = coins + number + button;
}
document.getElementById("coins").innerHTML = coins;
save();
};
var miner = parseInt(document.getElementById('miner').innerHTML);
function buyMiner(){
var minerCost = Math.floor(30 * Math.pow(1.3,miner)); //works out the cost of this miner
if(coins >= minerCost){ //checks that the player can afford the miner
miner = miner + 1; //increases number of miners
coins = coins - minerCost; //removes the coins spent
document.getElementById('miner').innerHTML = miner; //updates the number of miners for the user
document.getElementById('coins').innerHTML = coins; //updates the number of coins for the user
} else {
alert("You do not have enough coins.");
};
var nextCost = Math.floor(30 * Math.pow(1.3,miner)); //works out the cost of the next miner
document.getElementById('minerCost').innerHTML = nextCost; //updates the miner cost for the user
};
var button = paseInt(document.getElementById('button').innerHTML);
function buybutton(){
var buttonCost = Math.floor(30 * Math.pow(1.3,button)); //works out the cost of this button
if(coins >= buttonCost){ //checks that the player can afford the button
button = button + 1; //increases number of buttons
coins = coins - buttonCost; //removes the coins spent
document.getElementById('button').innerHTML = button; //updates the number of buttons for the user
document.getElementById('coins').innerHTML = coins; //updates the number of coins for the user
} else {
alert("You do not have enough coins.");
};
var nextbuttonCost = Math.floor(30 * Math.pow(1.3,button)); //works out the cost of the next button
document.getElementById('buttonCost').innerHTML = nextbuttonCost; //updates the button cost for the user
};
function save(){
$.ajax({url: "functions.php?coins="+ coins + "&miner=" + miner + "&nextminercost=" + (Math.floor(30 * Math.pow(1.3,button))).tostring() + "&button=" + button + "&nextbuttoncost=" + buttonCost , async: false})
setTimeout(function(){document.getElementById('saved').innerHTML = 'Game saved' }, 5000);
document.getElementById('saved').innerHTML = '';
};
window.setInterval(function(){
save();
coinsClick(miner);
}, 1000);
window.setInterval(function() { //SAVE INTO DB
save();
}, 10000);







