I recently became a developer for someone and so I am walking in cold on their code. The code is for a game on Facebook, and since I do not own the game, I cannot share everything about it but I will tell you what it is I am trying to do and what I have done thus far that is not working and what it is doing that it should not be. I can show you that code that I have added but I will not be able to show the entire page of code and I am sure you all can understand why. So, here it goes.
In this game, you pick 5 digits and then the computer generates 5 digits and compares them to the digits you picked. It awards based on how many digits you matched. That part is working fine. There was supposed to be an upgrade that you could "buy", for lack of a better word, that would take any incorrect digits and, based on the level of the upgrade you had "purchased", you would have a percent chance of converting those wrong digits to the right ones. Of course, the higher levels you bought, the higher percent chance you would change the digits over. What is happening is that it is changing all the incorrect digits over and that violates the laws of averages, so I am wondering what I am doing wrong here. Here is the code:
$torchPercent=$torchlevel*2; // $torchlevel is a variable from another page that is included once in this page.
function torchFire()
{
$torchWorks .=mt_rand(1,100)."--";
if($torchWorks <= $torchPercent) // The torch does change the number for the player
{
return true;
}
else{ return false;} // The torch does not change the number for the player
} // End of function
That is code at the top of the page. Here is the code that calls that function and actually does the changing of the digit and assigns the credit for the change.
if(torchFire)
{
$correct++;
$usrcorrect[$slot]=true;
$torch[$slot]=true;
$def[$slot]=$char[$x];
}
else{
$usrcorrect[$slot]=false;
$torch[$slot]=false;
$def[$slot]=$chars[$x];
}
This functionality is in the function where it is determined that the number is not a match and should check to see if the torch does change the number or not. Finally is the display of the numbers.
for($y=0;$y<5;$y++)
{
if($usrcorrect[$y]==true && $torch[$y]==false)
{
$output.="<span style='color:green'> ".$usernumber[$y]."</span>";
}
else if($usrcorrect[$y]==true && $torch[$y]==true)
{
$output.="<span style='color:#ff6600'> ".$usernumber[$y]."</span>";
}
else
{
$output.=" ".$usernumber[$y];
}
}
As far as I can tell, this part actually does work so I am assuming at this point that the problem is in the upper section where either the test is done or where the torchfire is generated.
Any help would be greatly appreciated and thank you just for taking a look.