<?php
require'fun.php';
function status_joc($cod_joc)
{
if(mb_strlen($cod_joc)==0)
return'-';
$board=str_split(mb_strtoupper($cod_joc));
if($board[0]=='X'&&$board[1]=='X'&&$board[2]=='X'||$board[3]=='X'&&$board[4]=='X'&&$board[5]=='X'||$board[6]=='X'&&$board[7]=='X'&&$board[8]=='X'||$board[0]=='X'&&$board[3]=='X'&&$board[6]=='X'||$board[1]=='X'&&$board[4]=='X'&&$board[7]=='X'||$board[2]=='X'&&$board[5]=='X'&&$board[8]=='X'||$board[0]=='X'&&$board[4]=='X'&&$board[8]=='X'||$board[2]=='X'&&$board[4]=='X'&&$board[6]=='X')
return'X';
elseif($board[0]=='0'&&$board[1]=='0'&&$board[2]=='0'||$board[3]=='0'&&$board[4]=='0'&&$board[5]=='0'||$board[6]=='0'&&$board[7]=='0'&&$board[8]=='0'||$board[0]=='0'&&$board[3]=='0'&&$board[6]=='0'||$board[1]=='0'&&$board[4]=='0'&&$board[7]=='0'||$board[2]=='0'&&$board[5]=='0'&&$board[8]=='0'||$board[0]=='0'&&$board[4]=='0'&&$board[8]=='0'||$board[2]=='0'&&$board[4]=='0'&&$board[6]=='0')
return'0';
elseif(mb_substr_count($cod_joc,'-')==0)
return;
else
return'-';
}
$numar_runde=3;
$miza=10;
$tieProc=50;
if(isset($_POST['renunta']))
$renunta=$_POST['renunta'];
else
$renunta=FALSE;
$statusText='';
require'f_conectare.php';
conectare('joaca X și 0','joaca-x-0');
$titlu='Joaca X și 0';
$back[1]='<a href="/jocuri">'.img('jocuri.gif',1).'Jocuri</a>';
$back[2]='<a href="/joaca-x-0">'.img('jocuri.gif',1).'X și 0</a>';
require'f_sus.php';
if($go=='invita')
{
$numar_runde=(isset($_POST['numar_runde'])?(is_numeric($_POST['numar_runde'])&&$_POST['numar_runde']>0?$_POST['numar_runde']:$numar_runde):$numar_runde);
$miza=(isset($_POST['miza'])?(is_numeric($_POST['miza'])&&$_POST['miza']>0?$_POST['miza']:$miza):$miza);
$lei_membru=$conn->query('SELECT`lei`FROM`membrii`WHERE`id`="'.$la.'"')->fetch_row()[0];
if($la==$de||$la==$id_robot||$la<1)
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].'Nu poți juca impotriva ta, impotriva robotului site-ului, sau impotriva unui ID mai mic de 0!';
elseif($conn->query('SELECT`lei`FROM`membrii`WHERE`id`="'.$de.'"')->fetch_row()[0]<$lei['x0'])
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].'Ai nevoie de <strong>'.$lei['x0'].' lei</strong> ca sa poți juca!';
elseif($lei_membru<$miza||$lei_membru<$lei['x0'])
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].nume($la).' nu are numărul de lei propus de tine!';
else
{
if(@$conn->query('SELECT`id`FROM`x_0`WHERE(`de`="'.$de.'"||`la`="'.$de.'")&&`cod`!=""')->num_rows==0)
{
if(@$conn->query('SELECT`id`FROM`x_0`WHERE(`de`="'.$la.'"||`la`="'.$la.'")&&(`cod`!=""||`ultimul`="'.$la.'")')->num_rows==0)
{
if(!$conn->query('INSERT INTO`x_0`SET`de`="'.$de.'",`la`="'.$la.'",`primul`="'.$de.'",`numar_runde`="'.$numar_runde.'",`miza`="'.$miza.'"'))
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].nume($la).' nu a putut primi invitatia!';
else
{
$conn->query('INSERT INTO`mesaje`SET`text`="Ti-am trimis o invitatie la jocul X și 0, te rog da click [url=/joaca-x-0]aici[/url][br/]Ai primit acest mesaj în mod automat!",`de`="'.$de.'",`la`="'.$la.'",`data`="'.$_SERVER['REQUEST_TIME'].'"');
echo$div[4].'<img src="'.$domenii_statice[1].'actiune_check.png" alt="" width="16" height="16" />Succes!'.$div[5].$div[6].'Invitatie trimisa, așteaptă să fie acceptata!';
}
}
else
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].nume($la).' joaca X și 0 cu un alt membru, și nu poate primi invitatia ta!';
}
else
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].'Ai primit invitatie de la altcineva!';
}
echo$div[0];
require'f_jos.php';
}
if(isset($_POST['renunta']))
{
$id_joc=$_POST['id_joc'];
$cod_joc=$_POST['cod_joc'];
$numar_runda=$_POST['numar_runda'];
$castigator=$_POST['castigator'];
if((mb_substr_count($cod_joc,'X')==0||mb_substr_count($cod_joc,'0')==0)&&$numar_runda==0)
{
if(!$conn->query('DELETE FROM`x_0`WHERE`id`="'.$id_joc.'"'))
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].'Nu se poate renunta la acest joc!';
}
else
{
if(@$conn->query('SELECT`id`FROM`x_0`WHERE`ultimul`="'.$de.'"')->num_rows==0)
{
if($conn->query('UPDATE`x_0`SET`ultimul`="'.$castigator.'"WHERE`id`="'.$id_joc.'"'))
$renunta=TRUE;
else
{
$renunta=FALSE;
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].'Nu se poate renunta la acest joc!';
}
}
}
echo$div[0];
require'f_jos.php';
}
echo$div[4].'Joaca X și 0'.$div[5];
$res=$conn->query('SELECT * FROM`x_0`WHERE`ultimul`="'.$de.'"');
if(@$res->num_rows==0)
$res=$conn->query('SELECT * FROM`x_0`WHERE(`de`="'.$de.'"||`la`="'.$de.'")&&`cod`!=""');
if(@$res->num_rows==0)
{
echo$div[10].'Invita membru'.$div[0];
$form[0]='/joaca-x-0/tip/invita" method="post';
$form[1]=0;
$form[2]=$div[1].'Nume sau identitate membru:<br /><input name="la" maxlength="33" />'.$div[0].$div[1].'Numar runde:<br /><input name="numar_runde" maxlength="2" value="'.$numar_runde.'" />'.$div[0].$div[1].'Miza:<br /><input name="miza" maxlength="3" value="'.$miza.'" />'.$div[0];
$form[3]='la::numar_runde::miza';
$form[4]='Invita';
require'f_form.php';
echo$div[1].'Victorii <strong>';
$res=$conn->query('SELECT`victorii`,`runde`FROM`x_0_jurnal`WHERE`de`="'.$de.'"');
if(@$res->num_rows>0)
{
$log=$res->fetch_row();
echo$log[0].'/'.$log[1];
}
else
echo'0/0';
echo'</strong>'.$div[0].$div[1].'Lei: <strong>'.$conn->query('SELECT`lei`FROM`membrii`WHERE`id`="'.$de.'"')->fetch_row()[0].'</strong>'.$div[0].$div[1].'<a href="/joaca-x-0"><img src="'.$domenii_statice[2].'reincarcare.gif" alt="" />Reîncarcă</a>'.$div[0].$div[1].'<a href="/top-x-0">'.img('topuri.gif',2).'Top X și 0</a>'.$div[0];
}
elseif(@$res->num_rows==1)
{
$game=$res->fetch_array();
$id_joc=$game['id'];
$fraier1=$game['de'];
$fraier2=$game['la'];
$primul_scor=$game['primul_scor'];
$al_doilea_scor=$game['al_doilea_scor'];
$primul=$game['primul'];
$miza=$game['miza'];
$numar_runda=$game['numar_runda'];
$numar_runde=$game['numar_runde'];
$cod_joc=mb_strtoupper($game['cod']);
$cod_temporar=mb_strtoupper($game['cod_temporar']);
$ultimul=$game['ultimul'];
if($de==$ultimul&&$cod_temporar!='')
$cod_joc=$cod_temporar;
$nX=mb_substr_count($cod_joc,'X');
$n0=mb_substr_count($cod_joc,'0');
if($nX==$n0)
$plTurn=$primul;
else
$plTurn=($primul==$fraier1?$fraier2:$fraier1);
$turn=($plTurn==$de?TRUE:FALSE);
if($cod_temporar=='')
$plMark=($de==$primul?'X':'0');
elseif($de==$ultimul)
$plMark=($de!=$primul?'X':'0');
else
$plMark=($de==$primul?'X':'0');
$status=status_joc($cod_joc);
if($turn==TRUE&&isset($_GET['pid'])&&is_numeric($_GET['pid'])&&$_GET['pid']>=0&&$_GET['pid']<=8)
{
if(mb_substr($cod_joc,$_GET['pid'],1)=='-'&&$status=='-')
{
$plTurn=($plTurn==$fraier1?$fraier2:$fraier1);
$joc_cod=substr_replace($cod_joc,$plMark,$_GET['pid'],1);
if($conn->query('UPDATE`x_0`SET`cod`="'.$joc_cod.'"WHERE`id`="'.$id_joc.'"'))
{
$turn=FALSE;
$cod_joc=$joc_cod;
$status=status_joc($cod_joc);
}
}
}
if($status!='-')
{
if($status=='X')
{
if($cod_temporar=='')
$castigator=$primul;
else
$castigator=($primul==$fraier1?$fraier2:$fraier1);
}
elseif($status=='0')
{
if($cod_temporar=='')
$castigator=($primul==$fraier1?$fraier2:$fraier1);
else
$castigator=$primul;
}
if($status=='')
{
$statusText='<img src="'.$domenii_statice[1].'X0/tie.gif" alt="" /><br /><strong>Egalitate!</strong>';
if($cod_temporar=='')
{
if($numar_runda<$numar_runde)
$numar_runda++;
}
}
else
{
$statusText=($castigator==$de?'<img src="'.$domenii_statice[1].'X0/won.gif" alt="" /><br /><strong>Ai castigat!</strong>':'<img src="'.$domenii_statice[2].'X0/lose.gif" alt="" /><br /><strong>Ai pierdut!</strong>');
if($cod_temporar=='')
{
$castigator==$fraier1?$primul_scor++:$al_doilea_scor++;
if($numar_runda<$numar_runde)
$numar_runda++;
}
}
if($numar_runda==$numar_runde)
{
if($primul_scor>$al_doilea_scor)
$castigator=$fraier1;
elseif($primul_scor<$al_doilea_scor)
$castigator=$fraier2;
else
$castigator=-1;
if($castigator==$de)
$statusText='<img src="'.$domenii_statice[1].'X0/won.gif" alt="" /><br /><strong>Ai câștigat '.$miza.' lei!</strong>';
elseif($castigator!=-1)
$statusText='<img src="'.$domenii_statice[2].'X0/lose.gif" alt="" /><br /><strong>Ai pierdut '.$miza.' lei!</strong>';
else
$statusText='<img src="'.$domenii_statice[1].'X0/tie.gif" alt="" /><br /><strong>Egalitate!<br />Ai pierdut '.($miza*$tieProc/100).' lei!</strong>';
if($cod_temporar=='')
{
$lei1=$conn->query('SELECT`lei`FROM`membrii`WHERE`id`="'.$fraier1.'"')->fetch_row()[0];
$lei2=$conn->query('SELECT`lei`FROM`membrii`WHERE`id`="'.$fraier2.'"')->fetch_row()[0];
if($castigator==$fraier1)
{
$lei1+=$miza;
$lei2-=$miza;
}
elseif($castigator==$fraier2)
{
$lei1-=$miza;
$lei2+=$miza;
}
else
{
$lei1-=$miza*$tieProc/100;
$lei2-=$miza*$tieProc/100;
}
$ultimul=($de==$fraier1?$fraier2:$fraier1);
$conn->query('UPDATE`x_0`SET`primul_scor`="'.$primul_scor.'",`al_doilea_scor`="'.$al_doilea_scor.'",`numar_runda`="'.$numar_runda.'",`cod`="",`cod_temporar`="'.$cod_joc.'",`ultimul`="'.$ultimul.'"WHERE`id`="'.$id_joc.'"');
$conn->query('UPDATE`membrii`SET`lei`="'.$lei1.'"WHERE`id`="'.$fraier1.'"');
$conn->query('UPDATE`membrii`SET`lei`="'.$lei2.'"WHERE`id`="'.$fraier2.'"');
$res=$conn->query('SELECT`id`,`victorii`,`runde`FROM`x_0_jurnal`WHERE`de`="'.$fraier1.'"');
if(@$res->num_rows==0)
$conn->query('INSERT INTO`x_0_jurnal`SET`de`="'.$fraier1.'",`victorii`="'.$primul_scor.'",`runde`="'.$numar_runda.'"');
else
{
$log=$res->fetch_row();
$id=$log[0];
$victorii=$log[1];
$runde=$log[2];
$runde+=$numar_runda;
$victorii+=$primul_scor;
$conn->query('UPDATE`x_0_jurnal`SET`victorii`="'.$victorii.'",`runde`="'.$runde.'"WHERE`id`="'.$id.'"');
}
$res=$conn->query('SELECT`id`,`victorii`,`runde`FROM`x_0_jurnal`WHERE`de`="'.$fraier2.'"');
if(@$res->num_rows==0)
$conn->query('INSERT INTO`x_0_jurnal`SET`de`="'.$fraier2.'",`victorii`="'.$al_doilea_scor.'",`runde`="'.$numar_runda.'"');
else
{
$log=$res->fetch_row();
$id=$log[0];
$victorii=$log[1];
$runde=$log[2];
$runde+=$numar_runda;
$victorii+=$al_doilea_scor;
$conn->query('UPDATE`x_0_jurnal`SET`victorii`="'.$victorii.'",`runde`="'.$runde.'"WHERE`id`="'.$id.'"');
}
}
elseif($ultimul==$de)
$conn->query('DELETE FROM`x_0`WHERE`id`="'.$id_joc.'"');
}
elseif($cod_temporar=='')
{
$primul=($primul==$fraier1?$fraier2:$fraier1);
$ultimul=($de==$fraier1?$fraier2:$fraier1);
$conn->query('UPDATE`x_0`SET`primul_scor`="'.$primul_scor.'",`al_doilea_scor`="'.$al_doilea_scor.'",`primul`="'.$primul.'",`numar_runda`="'.$numar_runda.'",`cod`="---------",`cod_temporar`="'.$cod_joc.'",`ultimul`="'.$ultimul.'"WHERE`id`="'.$id_joc.'"');
}
elseif($ultimul==$de)
$conn->query('UPDATE`x_0`SET`cod_temporar`="",`ultimul`="0"WHERE`id`="'.$id_joc.'"');
}
elseif($renunta)
{
$castigator=$ultimul;
$lei1=$conn->query('SELECT`lei`FROM`membrii`WHERE`id`="'.$fraier1.'"')->fetch_row()[0];
$lei2=$conn->query('SELECT`lei`FROM`membrii`WHERE`id`="'.$fraier2.'"')->fetch_row()[0];
if($castigator==$fraier1)
{
$lei1+=$miza;
$lei2-=$miza;
}
elseif($castigator==$fraier2)
{
$lei1-=$miza;
$lei2+=$miza;
}
$statusText='<img src="'.$domenii_statice[2].'X0/lose.gif" alt="" /><br /><strong>Ai pierdut '.$miza.' lei!</strong>';
$conn->query('UPDATE`x_0`SET`cod`="",`cod_temporar`=""WHERE`id`="'.$id_joc.'"');
$conn->query('UPDATE`membrii`SET`lei`="'.$lei1.'"WHERE`id`="'.$fraier1.'"');
$conn->query('UPDATE`membrii`SET`lei`="'.$lei2.'"WHERE`id`="'.$fraier2.'"');
$res=$conn->query('SELECT`id`,`victorii`,`runde`FROM`x_0_jurnal`WHERE`de`="'.$fraier1.'"');
if(@$res->num_rows==0)
$conn->query('INSERT INTO`x_0_jurnal`SET`de`="'.$fraier1.'",`victorii`="'.$primul_scor.'",`runde`="'.$numar_runda.'"');
else
{
$log=$res->fetch_row();
$id=$log[0];
$victorii=$log[1];
$runde=$log[2];
$runde+=$numar_runda;
$victorii+=$primul_scor;
$conn->query('UPDATE`x_0_jurnal`SET`victorii`="'.$victorii.'",`runde`="'.$runde.'"WHERE`id`="'.$id.'"');
}
$res=$conn->query('SELECT`id`,`victorii`,`runde`FROM`x_0_jurnal`WHERE`de`="'.$fraier2.'"');
if(@$res->num_rows==0)
$conn->query('INSERT INTO`x_0_jurnal`SET`de`="'.$fraier2.'",`victorii`="'.$al_doilea_scor.'",`runde`="'.$numar_runda.'"');
else
{
$log=$res->fetch_row();
$id=$log[0];
$victorii=$log[1];
$runde=$log[2];
$runde+=$numar_runda;
$victorii+=$al_doilea_scor;
$conn->query('UPDATE`x_0_jurnal`SET`victorii`="'.$victorii.'",`runde`="'.$runde.'"WHERE`id`="'.$id.'"');
}
}
elseif($de==$ultimul)
{
$conn->query('DELETE FROM`x_0`WHERE`id`="'.$id_joc.'"');
$statusText='<img src="'.$domenii_statice[1].'X0/won.gif" alt="" /><br /><strong>Ai câștigat '.$miza.' lei!</strong>';
}
if($status=='-'&&$numar_runda<$numar_runde&&!$renunta&&$de!=$ultimul)
echo$div[1].'<img src="'.($plTurn==$de?$domenii_statice[1].'on':$domenii_statice[2].'of').'l.gif" alt="'.($plTurn==$de?'+':'-').'" />'.$div[0];
if($statusText!='')
echo$div[10].$statusText.$div[0];
if($numar_runda<$numar_runde&&!$renunta)
{
$board=str_split(mb_strtoupper($cod_joc));
echo'<table>';
foreach($board AS$key=>$val)
{
if($key%3==0)
echo'<tr>';
$cheie=$key+1;
echo'<td>';
if($val=='X')
echo'<img src="'.($plMark=='X'?$domenii_statice[1].'X0/X':$domenii_statice[2].'X0/X1').'.gif" alt="'.($plMark=='X'?'X':'0').'" />';
elseif($val=='0')
echo'<img src="'.($plMark=='0'?$domenii_statice[1].'X0/0':$domenii_statice[2].'X0/01').'.gif" alt="'.($plMark=='0'?'X':'0').'" />';
elseif($val=='-'&&($turn==FALSE||$status!='-'))
echo'<img src="'.$domenii_statice[2].'X0/square.gif" alt="'.$cheie.'" />';
elseif($val=='-'&&$turn==TRUE)
echo'<a href="/joaca-x-0/id/'.$key.'"><img src="'.$domenii_statice[2].'X0/square.gif" alt="'.$cheie.'" /></a>';
echo'</td>';
if($key%3==2)
echo'</tr>';
}
echo'</table>';
}
require'f_profil.php';
echo$div[1].'<a href="/joaca-x-0"><img src="'.$domenii_statice[2].'reincarcare.gif" alt="" />Reîncarcă</a>'.$div[0].$div[1].profil($fraier1).'&nbsp;<strong>'.$primul_scor.'</strong>-<strong>'.$al_doilea_scor.'</strong>&nbsp;'.profil($fraier2).$div[0].$div[1].'Miza: <strong>'.$miza.'</strong>'.$div[0].$div[1].'Numar runde: <strong>'.$numar_runda.'/'.$numar_runde.'</strong>'.$div[0].$div[1].'Victorii: <strong>';
$res=$conn->query('SELECT`victorii`,`runde`FROM`x_0_jurnal`WHERE`de`="'.$de.'"');
if(@$res->num_rows>0)
{
$log=$res->fetch_row();
echo$log[0].'/'.$log[1];
}
else
echo'0/0';
echo'</strong>'.$div[0].$div[1].'Lei: <strong>'.$conn->query('SELECT`lei`FROM`membrii`WHERE`id`="'.$de.'"')->fetch_row()[0].'</strong>'.$div[0];
if($numar_runda<$numar_runde&&!$renunta&&$cod_joc!='')
{
$form[0]='/joaca-x-0" method="post';
$form[1]=0;
$form[2]='<input type="hidden" name="renunta" value="1" /><input type="hidden" name="id_joc" value="'.$id_joc.'" /><input type="hidden" name="cod_joc" value="'.$cod_joc.'" /><input type="hidden" name="numar_runda" value="'.$numar_runda.'" /><input type="hidden" name="castigator" value="'.($de==$fraier1?$fraier2:$fraier1).'" />';
$form[3]='renunta::id_joc::cod_joc::numar_runda::castigator';
$form[4]='Renunta';
require'f_form.php';
}
echo$div[1].'<a href="/top-x-0">'.img('topuri.gif',2).'Top X și 0</a>'.$div[0];
}
else
echo$div[4].'<img src="'.$domenii_statice[2].'actiune_delete.png" alt="" width="16" height="16" />Eroare!'.$div[5].$div[7].'A intervenit o mica eroare, încearcă mai târziu!'.$div[0];
require'f_jos.php';