Iam making a game, the error is that in the "d" loop (for...) the value "holeBalls" stays always the same.
for (d=holeNum;d<=holeBalls;d++)
{
document.getElementById('hole'+d).value++
}
}
what i want is that holeBalls here, gets the value of "'hole'+id" because now what happens is that (this is a kalah game) when you click on a hole with 4 holeBalls, then the next hole has 5 holeBalls right? When you click on it, the balls will only spread out in 4 pieces, when the purpose is to give the next 5 holes one piece, but in this code i made, one piece gets lost...
// variables
gameStarted = false;
gemDif = 4;
function getGemDif()
{
gemDif = 4
var MySelect = document.getElementById("dif");
gemDif = MySelect.options[MySelect.selectedIndex].value;
document.getElementById("gemsAmount").value = gemDif;
}
function start()
{
gameStarted = true;
n = 1;
for (n=1;n<=12;n++)
{
document.getElementById('hole'+n).value = gemDif;
document.getElementById('hole'+n).style.backgroundImage = 'url(img/hole_gem.png)';
}
}
function move(hole)
{
if (gameStarted == true)
{
changeSrc(hole)
holeID = hole.id
holeNum = holeID.replace(/hole/,'')
holeBalls = hole.value
hole.value = 0
holeNum++
holeBalls++
for (d=holeNum;d<=holeBalls;d++)
{
document.getElementById('hole'+d).value++
}
}
if(gameStarted == false)
{
alert('Select a difficulty and start the game!')
}
}
function changeSrc(clicked)
{
clicked.style.backgroundImage = 'url(img/hole_empty.png)';
}
IF YOU WISH, I CAN SEND YOU THE WHOLE WEBPAGE SO THAT YOU TEST IT AND UNDERSTAND IT BETTER