Файл: social12/games/fruit.php
Строк: 116
<?php
require '../sid.php';
require '../config.php';
$link = connect_db();
list($user, $id, $ps) = check_login($link);
whorm(0, 'games');
include '../head.php';
echo $div_title . 'Фрутит' . $div_end . $div_left;
// случайные картинки
$rand_1 = mt_rand(1, 8);
$rand_2 = mt_rand(1, 8);
$rand_3 = mt_rand(1, 8);
$rand_4 = mt_rand(1, 8);
$rand_5 = mt_rand(1, 8);
$rand_6 = mt_rand(1, 8);
$rand_7 = mt_rand(1, 8);
$rand_8 = mt_rand(1, 8);
$rand_9 = mt_rand(1, 8);
// функция проверки строк на совпадения
function var_unique()
{
return count(array_unique(func_get_args())) === 1;
}
if (isset($_POST['go'])) {
if ($user['balls'] < 1) {
err('У вас должно быть не менее 1 бублика!');
} else {
// проверка строк на совпадения (горизонталь, диагональ)
if (var_unique($rand_1, $rand_2, $rand_3)) $win[] = 5;
if (var_unique($rand_4, $rand_5, $rand_6)) $win[] = 5;
if (var_unique($rand_7, $rand_8, $rand_9)) $win[] = 5;
if (var_unique($rand_1, $rand_5, $rand_9)) $win[] = 5;
if (var_unique($rand_3, $rand_5, $rand_7)) $win[] = 5;
if (count($win) > 1) {
echo '<span style="color:#00FF00;">+' . (5 * count($win)) . '</span> <img src="../ico/balls.png" alt=""/>' . $block;
mysql_query("UPDATE users SET balls = balls + '" . (5 * count($win)) . "' WHERE id = '$user[id]' LIMIT 1");
header('Localhost: ?');
} elseif (count($win) == 1) {
echo '<span style="color:#00FF00;">+5</span> <img src="../ico/balls.png" alt=""/>' . $block;
mysql_query("UPDATE users SET balls = balls + '5' WHERE id = '$user[id]' LIMIT 1");
header('Localhost: ?');
} else {
mysql_query("UPDATE users SET balls = balls - '1' WHERE id = '$user[id]' LIMIT 1");
header('Localhost: ?');
}
}
}
// подстветка совпавших строк
if (var_unique($rand_1, $rand_2, $rand_3)) $Col_1 = 'bgcolor="#FF0000"';
if (var_unique($rand_4, $rand_5, $rand_6)) $Col_2 = 'bgcolor="#FF0000"';
if (var_unique($rand_7, $rand_8, $rand_9)) $Col_3 = 'bgcolor="#FF0000"';
if (var_unique($rand_1, $rand_5, $rand_9)) $Col_4 = 'bgcolor="#FF0000"';
if (var_unique($rand_3, $rand_5, $rand_7)) $Col_5 = 'bgcolor="#FF0000"';
echo '<FORM method="POST" action="?">
<TABLE>
<TR>
<TD ' . $Col_1 . $Col_4 . '><img src="fruit/'.$rand_1.'.png" alt=""/></TD>
<TD ' . $Col_1 . '><img src="fruit/'.$rand_2.'.png" alt=""/></TD>
<TD ' . $Col_1 . $Col_5 . '><img src="fruit/'.$rand_3.'.png" alt=""/></TD>
</TR>
<TR>
<TD ' . $Col_2 . '><img src="fruit/'.$rand_4.'.png" alt=""/></TD>
<TD ' . $Col_2 . $Col_4 . $Col_5 . '><img src="fruit/'.$rand_5.'.png" alt=""/></TD>
<TD ' . $Col_2 . '><img src="fruit/'.$rand_6.'.png" alt=""/></TD>
</TR>
<TR>
<TD ' . $Col_3 . $Col_5 . '><img src="fruit/'.$rand_7.'.png" alt=""/></TD>
<TD ' . $Col_3 . '><img src="fruit/'.$rand_8.'.png" alt=""/></TD>
<TD ' . $Col_3 . $Col_4 . '><img src="fruit/'.$rand_9.'.png" alt=""/></TD>
</TR>
</TABLE>
<input type="submit" name="go" value="Крутить"/>
</FORM>' . $div_end;
include '../foot.php';
?>