File size: 8.86Kb
<?php
ini_set('session.use_cookies',0);
ini_set('session.use_trans_sid',0);
ini_set('url_rewriter.tags','');
session_name('stw');
session_start();
require '../connect.php';
require '../header.php';
require '../result.php';
function getmicrotime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
$posts = $row['posts'];
$guposts = $row['gposts'];
if(!$_SESSION)
{
$_SESSION['round'] = 0;
$_SESSION['money'] = $posts;
$_SESSION['con'] = 0;
$_SESSION['histuser'] = '';
}
$ses = SID;
$ses = $ses.'&id='.$id.'&ps='.$ps.'&ref='.$ref;
if($_POST['mn'])
{$mn = intval($_POST['mn']);}
function cards_score($str){
if($str==1||$str==2||$str==3||$str==4)
{$num = 6;}
if($str==5||$str==6||$str==7||$str==8)
{$num = 7;}
if($str==9||$str==10||$str==11||$str==12)
{$num = 8;}
if($str==13||$str==14||$str==15||$str==16)
{$num = 9;}
if($str==17||$str==18||$str==19||$str==20)
{$num = 10;}
if($str==21||$str==22||$str==23||$str==24)
{$num = 2;}
if($str==25||$str==26||$str==27||$str==28)
{$num = 3;}
if($str==29||$str==30||$str==31||$str==32)
{$num = 4;}
if($str==33||$str==34||$str==35||$str==36)
{$num = 11;}
return $num;
}
if($posts<1000)
{
print '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="index" title="21">
<p align="center">
<small>
У Вас недостаточно постов для игры!<br/>
Необходимо не менее 1000 постов<br/>
<a href="../enter.php?id='.$id.'&ps='.$ps.'">Прихожая</a><br/>
</small>
</p></card></wml>';
mysql_close();
exit;
}
else
{
if($_SESSION['round']==0)
{
$max = $_SESSION['money'];
if($max==0)
{
session_destroy();
print '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="index" title="21">
<p align="center">
<small>
У Вас не достаточно постов для продолжения текущей игры!<br/>
<a href="out.php?'.$ses.'">Выйти</a><br/>
</small>
</p></card></wml>';
mysql_close();
exit;
}
$ru = rand(1,36);
if($_SESSION['histuser'])
{$ru = trim(str_replace('|','', $_SESSION['histuser']));}
$uscore=cards_score($ru);
$pstr = 'очков';
if($uscore==2||$uscore==3||$uscore==4)
{$pstr = 'очка';}
$maxlen=strlen($max);
print '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="index" title="21">
<p align="center">
<small>
У Вас '.$max.' постов<br/>
<strong>Ваши карты:</strong><br/>
<img src="cards/'.$ru.'.gif" alt=""/><br/>
'.$uscore.' '.$pstr.'<br/>
Ваша ставка(1-'.$max.'):<br/>
</small>
<input name="mn'.$ref.'" maxlength="'.$maxlen.'" format="*N" type="text"/><br/>
<small>
<anchor>Играть<go href="21.php?'.$ses.'" method="post">
<postfield name="mn" value="$(mn'.$ref.')"/>
</go></anchor><br/>
<a href="faq.php?'.$ses.'">Правила игры</a><br/>
<a href="out.php?'.$ses.'">Выход</a><br/>
</small>
</p></card></wml>';
$_SESSION['histuser']='|'.$ru;
$_SESSION['round']=1;
}
else
{
if($_SESSION['con']==0)
{
if($mn>$_SESSION['money']||$mn==''||!isset($mn)||$mn<1)
{
print '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="index" title="21">
<p align="center">
<small>';
if($mn==''||$mn<1)
{print 'Вы не указали ставку!';}
else
{print 'У Вас недостаточно постов для подобной ставки!';}
print '</small>
</p></card></wml>';
$_SESSION['round']=0;
mysql_close();
exit;
}
$_SESSION['con']=round($mn);
$_SESSION['money']=$_SESSION['money']-$_SESSION['con'];
}
$rate=$_SESSION['con']*2;
$stavka=$_SESSION['con'];
$histuser=explode('|',$_SESSION['histuser']);
if(!isset($_GET['end']))
{
do
{
$randgen=1;
$ru = rand(1,36);
for($i=1; $i<count($histuser); $i++)
{
if($ru==$histuser[$i])
{
$randgen=0;
break;
}
}
}
while($randgen==0);
$_SESSION['histuser']=$_SESSION['histuser'].'|'.$ru;
$countus = count($histuser);
$histuser[$countus] = $ru;
}
for($i=1; $i<count($histuser); $i++)
{$ustemp=cards_score($histuser[$i]); $uscore=$uscore+$ustemp;}
$udoublet=0;
if((count($histuser)==3)&&($uscore==22))
{
$tone=0;
$ttwo=0;
if($histuser[1]==33||$histuser[1]==34||$histuser[1]==35||$histuser[1]==36)
{$tone=1;}
if($histuser[2]==33||$histuser[2]==34||$histuser[2]==35||$histuser[2]==36)
{$ttwo=1;}
if($tone==1 && $ttwo==1)
{$udoublet=1;}
}
if($uscore>21&&$udoublet==0)
{$close=1;}
if($udoublet==1||$uscore==21||$uscore==20)
{$end=1;}
$max = $_SESSION['money'];
print '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="index" title="21">
<p align="center">
<small>
У Вас '.$max.' постов<br/>';
if(isset($close))
{print '<strong>Перебор!</strong><br/>';}
$win=0;
if(isset($_GET['end']))
{
$histbot[0]='';
$hist=$histuser;
for($i=1; $i<10;$i++)
{
do
{
$randgen=1;
$rb = rand(1,36);
for($i=1; $i<count($hist); $i++)
{
if($rb==$hist[$i])
{
$randgen=0;
break;
}
}
}
while($randgen==0);
$histbot[]=$rb;
$hist[]=$rb;
$btemp=cards_score($rb);
$bcore=$bcore+$btemp;
if($bcore==20)break;
if($bcore==21)break;
if($bcore==$uscore)break;
if($bcore>$uscore)break;
if($bcore>21)break;
}
print '<strong>Банкир открылся:</strong><br/>';
for($i=1;$i < count($histbot);$i++)
{print '<img src="cards/'.$histbot[$i].'.gif" alt="cards"/>';}
$pstr = 'очков';
if($bcore==2||$uscore==3||$bcore==4||$bcore==22||$bcore==23||$bcore==24)
{$pstr = 'очка';}
if($bcore==21)
{$pstr = '<strong>очко!</strong>';}
print '<br/>'.$bcore.' '.$pstr.'<br/>';
$bdoublet=0;
if((count($histbot)==3)&&($bcore==22))
{
$tone=0;
$ttwo=0;
if($histbot[1]==33||$histbot[1]==34||$histbot[1]==35||$histbot[1]==36)
{$tone=1;}
if($histbot[2]==33||$histbot[2]==34||$histbot[2]==35||$histbot[2]==36)
{$ttwo=1;}
if($tone==1&&$ttwo==1)
{$bdoublet=1;}
}
if($bcore>21&&$bdoublet==0)$win=1;
if($bcore<$uscore)$win=1;
if($udoublet==1)$win=1;
if($bdoublet==1)$win=0;
if($uscore==21)$win=1;
if($bcore==21)$win=0;
$close=1;
}
print '<strong>Ваши карты:</strong><br/>';
for($i=1; $i<count($histuser); $i++)
{print '<img src="cards/'.$histuser[$i].'.gif" alt="cards"/>';}
$pstr = 'очков';
if($uscore==2||$uscore==3||$uscore==4||$uscore==22||$uscore==23||$uscore==24)
{$pstr = 'очка';}
if($uscore==21)
{$pstr = '<strong>очко!</strong>';}
print '<br/>'.$uscore.' '.$pstr.'<br/>';
if(isset($close))
{
$_SESSION['round']=0;
$_SESSION['histuser']='';
if($win==0)
{
print '<strong>Вы проиграли</strong><br/>';
$f=fopen('lost.dat','a+');
flock($f,LOCK_EX);
$data=file('lost.dat');
$data[0]=trim($data[0])+1;
$stavka=$_SESSION['con'];
$data[1]=trim($data[1])+$_SESSION['con'];
ftruncate($f,0);
fwrite($f,"$data[0]\n");
fwrite($f,"$data[1]\n");
flock($f,LOCK_UN);
fclose($f);
mysql_query('UPDATE `antihack_users` SET posts=posts-'.$stavka.', gposts=gposts-'.$stavka.' WHERE id ='.$id);
$guposts=$row['gposts'];
$_SESSION['con']=0;
print 'Ваш проигрыш <strong>'.$stavka.'</strong> постов<br/>
Игровой баланс <strong>'.$guposts.'</strong> постов<br/>';
}
else
{
print '<strong>Вы выиграли! =)</strong><br/>';
$_SESSION['money']=$_SESSION['money']+$rate;
$f=fopen('win.dat','a+');
flock($f,LOCK_EX);
$data=file('win.dat');
$data[0]=trim($data[0])+1;
$data[1]=trim($data[1])+$_SESSION['con'];
ftruncate($f,0);
fwrite($f,"$data[0]\n");
fwrite($f,"$data[1]\n");
flock($f,LOCK_UN);
fclose($f);
mysql_query('UPDATE `antihack_users` SET posts=posts+'.$rate.', gposts=gposts+'.$rate.' WHERE id ='.$id);
$guposts=$row['gposts'];
$_SESSION['con']=0;
print 'Ваш выигрыш <strong>'.$rate.'</strong> постов<br/>
Игровой баланс <strong>'.$guposts.'</strong> постов<br/>';
}
print '<a href="21.php?'.$ses.'">Сыграть ещё</a><br/>';
}
else
{
print 'На кону '.$rate.' постов<br/>
<a href="21.php?'.$ses.'">Ещё</a>
<или>
<a href="21.php?end=1&'.$ses.'">Открыть</a><br/>';
}
print '<a href="out.php?'.$ses.'">Выход</a><br/>
</small>
</p></card></wml>';
mysql_close();
}
}
?>