View file index.php

File size: 6.26Kb
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http:// www.w3.org/TR/html4/strict.dtd">
<html>
<!--скрипт разработал Slade-X, все вопросы в icq: 9020099-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/style.css">
<title>Очко (21)</title>
</head>
<body>
<?php
echo "<center>";
echo "<a href='rules.php'>Правила</a><br><br>";

if (!isset($username))
{ echo "Ваше имя:<br><br>";
echo "<form action='index.php' method='GET'>
<input type='text' name='username'><br><br>
<input type='submit' value='Начать игру'>
</form><br><br>";
echo "<a href='/'>На главную</a>"; }
elseif (isset($username) && !isset($_COOKIE["u$username"]) && !isset($add) && !isset($stop))
{ start(); }
elseif (isset($username) && isset($_COOKIE["u$username"]) && isset($add) && !isset($stop))
{ game(); }
elseif (isset($username) && isset($_COOKIE["u$username"]) && isset($stop))
{ bot(); }
elseif (isset($username))
{ start(); }


function start()
{
$username = $_GET['username'];
$starthand1 = rand(0, 8);
$starthand2 = rand(0, 8);
$starthand = "$starthand1 $starthand2";
$startbothand = rand(0, 8);
setcookie("u$username", $starthand);
setcookie("b$username", $startbothand);

$val = array("6", "7", "8", "9", "10", "В", "Д", "К", "Т");
echo "Карты противника: ".$val[$startbothand]."<br><br><br>";
echo "Ваши карты: ".$val[$starthand1]." ".$val[$starthand2]."<br><br>";

if ($starthand == "4 8" or $starthand == "8 4")
{ setcookie("u$username", "");
setcookie("b$username", "");
echo "Вы выиграли!<br><br>
<a href='index.php?username=$username'>Начать новую игру<br>
<a href='/'>На главную</a>"; }
elseif ($starthand == "9 9")
{
setcookie("u$username");
setcookie("b$username");
echo "Перебор<br><br>
<a href='index.php?username=$username'>Начать новую игру<br>
<a href='/'>На главную</a>";
}
else
{ echo "<a href='index.php?username=$username&add=yes'>Взять еще карту</a><br>";
echo "<a href='index.php?username=$username&stop=yes'>Хватит</a><br><br>";
echo "<a href='index.php?username=$username'>Начать новую игру<br>
<a href='/'>На главную</a>"; }
}


function game()
{
$username = $_GET['username'];
$bothand = $_COOKIE["b$username"];
$userhand = $_COOKIE["u$username"];
$security = strlen($userhand);
$add = $_GET["add"];




if ($security != @$_COOKIE["security"])
{ $addn = rand(0, 8);
$userhand = "$userhand $addn"; }


if ($add == 5 or $add == 7 or $add == 9)
{ $userhand = $_COOKIE["u$username"];
$addn = rand(0, 8);
$userhand = "$userhand $addn"; }

$level = strlen($userhand);
setcookie("security", $level);
setcookie("u$username", $userhand);
$userhandm = explode(" ", $userhand);
$val = array("6", "7", "8", "9", "10", "В", "Д", "К", "Т");
$val2 = array(6, 7, 8, 9, 10, 2, 3, 4, 11);
@$userhands = $val2[$userhandm[0]] + $val2[$userhandm[1]] + $val2[$userhandm[2]] + $val2[$userhandm[3]] + $val2[$userhandm[4]];

if ($level == 5)
{ echo "Карты противника: ".$val[$bothand]."<br><br><br>";
echo "Ваши карты: ".$val[$userhandm[0]]." ".$val[$userhandm[1]]." ".$val[$userhandm[2]]."<br><br>";
}
elseif ($level == 7)
{ echo "Карты противника: ".$val[$bothand]."<br><br><br>";
echo "Ваши карты: ".$val[$userhandm[0]]." ".$val[$userhandm[1]]." ".$val[$userhandm[2]]." ".$val[$userhandm[3]]."<br><br>"; }
elseif ($level == 9)
{ echo "Карты противника: ".$val[$bothand]."<br><br><br>";
echo "Ваши карты: ".$val[$userhandm[0]]." ".$val[$userhandm[1]]." ".$val[$userhandm[2]]." ".$val[$userhandm[3]]." ".$val[$userhandm[4]]."<br><br>"; }


if ($userhands == 21)
{ setcookie("u$username", "");
setcookie("b$username", "");
echo "Вы выиграли!<br><br>
<a href='index.php?username=$username'>Начать новую игру<br>
<a href='/'>На главную</a>"; }
elseif ($userhands > 21)
{ setcookie("u$username", "");
setcookie("b$username", "");
echo "Перебор<br><br>
<a href='index.php?username=$username'>Начать новую игру<br>
<a href='/'>На главную</a>"; }
elseif ($level != 9)
{ echo "<a href='index.php?username=$username&add=$level'>Взять еще карту </a><br>";
echo "<a href='index.php?username=$username&stop=yes'>Хватит</a><br><br>";
echo "<a href='index.php?username=$username'>Начать новую игру<br>
<a href='/'>На главную</a>"; }
else
{ echo "<a href='index.php?username=$username&stop=yes'>Хватит</a><br><br>";
echo "<a href='index.php?username=$username'>Начать новую игру<br>
<a href='/'>На главную</a>"; }

}


function bot()
{
$username = $_GET['username'];
$bothand = $_COOKIE["b$username"];
$userhand = $_COOKIE["u$username"];
$userhandm = explode(" ", $userhand);
$val = array("6", "7", "8", "9", "10", "В", "Д", "К", "Т");
$val2 = array(6, 7, 8, 9, 10, 2, 3, 4, 11);
@$userhands = $val2[$userhandm[0]] + $val2[$userhandm[1]] + $val2[$userhandm[2]] + $val2[$userhandm[3]] + $val2[$userhandm[4]];
$addb = rand(0, 8);
$bothands = $val2[$bothand] + $val2[$addb];
$bothand = "$bothand $addb";
while ($bothands <= $userhands)
{ $addb = rand(0, 8);
$bothands = $bothands + $val2[$addb];
$bothand = "$bothand $addb"; }
$bothandm = explode(" ", $bothand);
if ($bothands <= 21)
{ echo "Карты противника: ".$val[$bothandm[0]]." ".$val[$bothandm[1]]." ".@$val[$bothandm[2]]." ".@$val[$bothandm[3]]." ".@$val[$bothandm[4]]."<br><br><br>";
echo "Ваши карты: ".$val[$userhandm[0]]." ".$val[$userhandm[1]]." ".@$val[$userhandm[2]]." ".@$val[$userhandm[3]]." ".@$val[$userhandm[4]]."<br><br>"; 
echo "Вы проиграли!<br><br>"; }
else
{ echo "Карты противника: ".$val[$bothandm[0]]." ".$val[$bothandm[1]]." ".@$val[$bothandm[2]]." ".@$val[$bothandm[3]]." ".@$val[$bothandm[4]]."<br><br><br>";
echo "Ваши карты: ".$val[$userhandm[0]]." ".$val[$userhandm[1]]." ".@$val[$userhandm[2]]." ".@$val[$userhandm[3]]." ".@$val[$userhandm[4]]."<br><br>"; 
echo "Вы выиграли!<br><br>"; }

setcookie("u$username", "");
setcookie("b$username", "");
echo "<a href='index.php?username=$username'>Начать новую игру<br>
<a href='/'>На главную</a>";
}

echo "</center>";
?>
</body>
</html>