Ciao a tutti,

sto cercando di creare un evento post-battaglia per un browser game.

Diciamo che la battaglia sia già stata svolta e che le perdite dell'ATT siano 21 e determino le truppe inviate grazie ad un valore in DB mysql.

Ho scritto questo codice:

Codice PHP:

            $att 
'10,20,30,0,0,0,0,0,0,0,0';
            
            
$explode_att explode(","$att);
            
            
$u_0 $explode_att[0];
            
$u_1 $explode_att[1];
            
$u_2 $explode_att[2];
            
$u_3 $explode_att[3];
            
$u_4 $explode_att[4];
            
$u_5 $explode_att[5];
            
$u_6 $explode_att[6];
            
$u_7 $explode_att[7];
            
$u_8 $explode_att[8];
            
$u_9 $explode_att[9];
            
            
$att_perdite 21;
            
            while ( 
$att_perdite != ) {
            
                
$k rand(1$att_perdite);
                
$i rand(09);
                
$r = empty(${'u_'.$i});
                
                if ( 
$r == FALSE ) {
                    
                        
                        echo 
"K: ".$k."

"
;
                        echo 
"I: ".$i."

"
;
                        echo 
"u_".$i." era ".${'u_'.$i}."

"
;
                        echo 
" -- si -- 

"
;
                        
$att_perdite $att_perdite $k;
                        ${
'u_'.$i} = ${'u_'.$i} - $k;
                        echo 
"u_".$i." è ".${'u_'.$i}."

"
;


                }
                
                
            
            } 
e funziona benissimo perché mi setta il nuovo valore di ogni $u_ . Adesso però arriva il problema perché va in loop, sto cercando di dichiarare che se le unità siano minori del valore di $k allora si deve sottrarre $att_perdite - $r.

Codice PHP:
            $att '10,20,30,0,0,0,0,0,0,0,0';
            
            
$explode_att explode(","$att);
            
            
$u_0 $explode_att[0];
            
$u_1 $explode_att[1];
            
$u_2 $explode_att[2];
            
$u_3 $explode_att[3];
            
$u_4 $explode_att[4];
            
$u_5 $explode_att[5];
            
$u_6 $explode_att[6];
            
$u_7 $explode_att[7];
            
$u_8 $explode_att[8];
            
$u_9 $explode_att[9];
            
            
$att_perdite 21;
            
            while ( 
$att_perdite != ) {
            
                
$k rand(1$att_perdite);
                
$i rand(09);
                
$r = empty(${'u_'.$i});
                
                if ( 
$r == FALSE ) {
                    
                    if ( 
$r <= $k ) {
                        
                        echo 
"1

"
;
                        echo 
"K: ".$k."

"
;
                        echo 
"I: ".$i."

"
;
                        echo 
"u_".$i." era ".${'u_'.$i}."

"
;
                        echo 
" -- si -- 

"
;
                        
$att_perdite $att_perdite $r;
                        ${
'u_'.$i} = ${'u_'.$i} - $r;
                        echo 
"u_".$i." è ".${'u_'.$i}."

"
;
                    
                    } else {
                        
                        echo 
"2

"
;
                        echo 
"K: ".$k."

"
;
                        echo 
"I: ".$i."

"
;
                        echo 
"u_".$i." era ".${'u_'.$i}."

"
;
                        echo 
" -- si -- 

"
;
                        
$att_perdite $att_perdite $k;
                        ${
'u_'.$i} = ${'u_'.$i} - $k;
                        echo 
"u_".$i." è ".${'u_'.$i}."

"
;
                    
                    }


                }
                
                
            
            } 
Chi sa perché va in loop? GRAZIE!