function game_millionaire_OnHelpPeople($game, $id, &$millionaire, $query) { $textlib = textlib_get_instance(); game_millionaire_loadquestions($millionaire, $query, $aAnswer); if (($millionaire->state & 4) != 0) { game_millionaire_ShowGrid($game, $millionaire, $id, $query, $aAnswer, ''); return; } game_millionaire_setstate($millionaire, 4); $n = count($aAnswer); $sum = 0; $aPercent = array(); for ($i = 0; $i + 1 < $n; $i++) { $percent = mt_rand(0, 100 - $sum); $aPercent[$i] = $percent; $sum += $percent; } $aPercent[$n - 1] = 100 - $sum; if (mt_rand(1, 100) <= 80) { //with percent 80% sets in the correct answer the biggest percent $max_pos = 0; for ($i = 1; $i + 1 < $n; $i++) { if ($aPercent[$i] >= $aPercent[$max_pos]) { $max_pos = $i; } } $temp = $aPercent[$max_pos]; $aPercent[$max_pos] = $aPercent[$query->correct - 1]; $aPercent[$query->correct - 1] = $temp; } $info = '<br>' . get_string('millionaire_info_people', 'game') . ':<br>'; for ($i = 0; $i < $n; $i++) { $info .= "<br>" . $textlib->substr(get_string('millionaire_letters_answers', 'game'), $i, 1) . " : " . $aPercent[$i] . ' %'; } game_millionaire_ShowGrid($game, $millionaire, $id, $query, $aAnswer, $textlib->substr($info, 4)); }
function game_millionaire_onhelppeople($game, $id, &$millionaire, $query, $context) { game_millionaire_loadquestions($game, $millionaire, $query, $aanswer, $context); if (($millionaire->state & 4) != 0) { game_millionaire_showgrid($game, $millionaire, $id, $query, $aanswer, '', $context); return; } game_millionaire_setstate($millionaire, 4); $n = count($aanswer); $sum = 0; $apercent = array(); for ($i = 0; $i + 1 < $n; $i++) { $percent = mt_rand(0, 100 - $sum); $apercent[$i] = $percent; $sum += $percent; } $apercent[$n - 1] = 100 - $sum; if (mt_rand(1, 100) <= 80) { // With percent 80% sets in the correct answer the biggest percent. $maxpos = 0; for ($i = 1; $i + 1 < $n; $i++) { if ($apercent[$i] >= $apercent[$maxpos]) { $maxpos = $i; } $temp = $apercent[$maxpos]; $apercent[$maxpos] = $apercent[$query->correct - 1]; $apercent[$query->correct - 1] = $temp; } } $info = '<br>' . get_string('millionaire_info_people', 'game') . ':<br>'; for ($i = 0; $i < $n; $i++) { $info .= "<br>" . game_substr(get_string('lettersall', 'game'), $i, 1) . " : " . $apercent[$i] . ' %'; } game_millionaire_showgrid($game, $millionaire, $id, $query, $aanswer, game_substr($info, 4), $context); }