Javascript ile basit bir clicker oyunu yaptım. Ve oyuna "ekstra tıklama" denen bir şey ekledim. Fakat 5 tane buton icin ayrı ayrı kod yazmaktansa hepsini bir function() icine sığdırmayı istiyorum, daha optimize olması icin. Bunu nasıl yapabilirim?
Gerekli kodlar:
JS:
CODE lang="javascript" title="JavaScript"let clickCount = 0;
// tıklama sayısını kontrol eder
let clickBoost = 0;
// ekstra tıklamaları kontrol eder
document.getElementById("clickButton").onclick = function()
}
// "Click" tuşunun kodları
document.getElementById("boostButton1").onclick = function()
else
}
else
}
// "Buy 1 Click Boost" tuşunun kodları
document.getElementById("boostButton10").onclick = function () else
}
else
}
// "Buy 10 Click Boost" tuşunun kodları
document.getElementById("boostButton100").onclick = function () else
}
else
}
// "Buy 100 Click Boost" tuşunun kodları
document.getElementById("boostButton1000").onclick = function () else
}
else
}
// "Buy 1000 Click Boost" tuşunun kodları
document.getElementById("boostButton10000").onclic k = function () else
}
else
}
// "Buy 10000 Click Boost" tuşunun kodları/CODE
HTML:
HTML:Panoya kopyala
oyun.. heralde 0
Click Buy 1 Click Boost Buy 10 Click Boost Buy 100 Click Boost Buy 1000 Click Boost Buy 10000 Click Boost <
#clickCounter
#clickButton
#boostButton1
#boostButton10
#boostButton100
#boostButton1000
#boostButton10000
Not: Son kod CSS.