php savaş oyunu çalışmıyor

2 Cevap

Tamam, bu yüzden ben çözümleri oyun açısından basit olması gerektiğini biliyorum, bu kısmen çalışma oyunu var, ama bir çaylak şey için ben bir çaylak olarak, ben yanlış ne yapıyorum, yardım talep ediyorum, bu nedenle burada hiç basittir Bunu ben kurulum onay kutularını yol olduğunu düşünüyorum, ama diğer gözlere ihtiyacım var, teşekkür ederim.

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" />
<table border="1" align="center" />
<?php
$fire = $_REQUEST["fire"];
$variable = $_REQUEST["variable"];
$step = $_REQUEST["step"];
$i = $_REQUEST["i"];
$j = $_REQUEST["j"];

if(isset($_POST['$i$j']))
{ 
echo 'checked';
}

//first there will be script that randomly generate 5 ships for both users

$step = $_POST['step'];
//4 steps of the game
if ($step > 3) 
{
    $step = 1;
} 
else 
{
    $step += 1;
}//end if
//step 1, first player 
if ($step == 1) 
{
    echo "Player 1";
 // Loop through the alphabet from a to j and stop before k on this for loop
    for ($i = a; $i < k; $i++)
 {
 // Print out the table with the letters from a to j using the variable $i
     echo "<tr><td width='20' align='right'>$i</td>";
  // Loop through the numbers for $j using numbers from 1 to less than 11 which is 10;
       for ($j = 1; $j < 11; $j++)
    {

    echo "<td><input type='submit' value='fire' name='$i$j'></td>";
       } 
    // end for loop
     echo "</tr>";
    } 
 // end for loop
    echo "<tr><td></td>";

 for ($j = 1; $j < 11; $j++)
 {

     echo "<td>$j</td>";
    }
    echo "</tr></table>";
    //step 2 result of first player fire
} 

else if($step == 2)
 {

    echo "Result 1";
        for ($i = a; $i < k; $i++)
  {

     echo "<tr><td width='20' align='right'>$i</td>";
       for ($j = 1; $j < 11; $j++){
      //<input type="checkbox" name="state[]" value="NE">
         echo "<td><input type='checkbox' type='submit' checked='checked' name='$i$j'></td>";
       } // end for loop
     echo "</tr>";
    } // end for loop
    echo "<tr><td></td>";
    for ($j = 1; $j < 11; $j++){
     echo "<td>$j</td>";
    }
    echo "</tr></table><br><input type='submit' name='' value='Player 2 Turn'>";
    //step 3 second player fireing
} else if($step == 3) {
    echo "Player 2";
    for ($i = a; $i < k; $i++){
     echo "<tr><td width='20' align='right'>$i</td>";
       for ($j = 1; $j < 11; $j++){
         echo "<td><input type='submit' value='fire' name='$i$j'></td>";
       } // end for loop
     echo "</tr>";
    } // end for loop
    echo "<tr><td></td>";
    for ($j = 1; $j < 11; $j++){
     echo "<td>$j</td>";
    }
    echo "</tr></table>";
    //step 4 result of second player fire
} else {
    echo "Result 2 ";
    for ($i = a; $i < k; $i++){
     echo "<tr><td width='20' align='right'>$i</td>";
       for ($j = 1; $j < 11; $j++){
         echo "<td><input type='checkbox' checked='checked' disabled='disabled' name='$i$j'></td>";
       } // end for loop
     echo "</tr>";
    } // end for loop
    echo "<tr><td></td>";
    for ($j = 1; $j < 11; $j++){
     echo "<td>$j</td>";
    }
    echo "</tr></table><br><input type='submit' name='' value='Player 1 Turn'>";
}//end if
for ($j = 1; $j < 11; $j++){
       if ($checked){
         echo "<td><input type='checkbox' checked='checked' name='variable'></td>";
        } else {
         echo "<td><input type='checkbox' name='variable'></td>";
        }
       }  

?>

<input type="hidden" name="step" value="<?php echo "$step"; ?>"
</form>
</center>
</html>

2 Cevap

Yanlış görmek Bir kaç şey:

  • echo "<td><input type='checkbox' type='submit' checked='checked' name='$i$j'></td>"; iki tip özelliklere sahiptir.
  • <input type="hidden" name="step" value="<?php echo "$step"; ?>" giriş etiketi kapanmıyor.
  • Sizin masanız etiketi kapanış değil.

Bir online html validation service aracılığıyla sayfamızı çalıştırmayı deneyin veya sayfayı doğrulamak ve html hataları düzeltmek için firefox validation addon kullanın.

Bir diğer konu sizin kullanıcı tüm giriş doğrularken değil olmasıdır. yani. Lütfen $_REQUEST veri. Bu Cross-site scripting yol açabilir ve kullanıcılar için tehlikeli olabilir. Bu örnekte sadece önemsiz olmasına rağmen, kullanıcı giriş doğrulama tüm durumlarda içine almak için iyi bir uygulamadır.

Ben sizin kodu ile size yardımcı ve hata ayıklama, html ana php ayırmanız olabileceğini düşünüyorum.

Haklısınız Eğer bir sorununuz varsa nerede zor görmek için yapar html ortasında php büyük bloklar var. Bu html kodunu yankı ama html olarak yazmak ve gerektiğinde daha sonra değişkenler php düşmesi değil de daha kolay.

örneğin:

Bu tür dağınık

<?php
echo "Result 2 ";
    for ($i = a; $i < k; $i++){
     echo "<tr><td width='20' align='right'>$i</td>";
       for ($j = 1; $j < 11; $j++){
         echo "<td><input type='checkbox' checked='checked' disabled='disabled' name='$i$j'></td>";
       } // end for loop
     echo "</tr>";
    } // end for loop
    echo "<tr><td></td>";
    for ($j = 1; $j < 11; $j++){
     echo "<td>$j</td>";
    }
    echo "</tr></table><br><input type='submit' name='' value='Player 1 Turn'>";
 ?>

Bu biraz kıvrımlara ise.

<?php
echo "Result 2 ";
    for ($i = a; $i < k; $i++){
?>

<tr>
    <td width='20' align='right'><?php echo $i; ?></td>";

    <?php
       for ($j = 1; $j < 11; $j++){
    ?>

    <td><input type='checkbox' checked='checked' disabled='disabled' name='<?php echo $i$j; ?>' /></td>

    <?php
       } // end for loop
    ?>

</tr>

    <?php
    } // end for loop
    ?>

    <tr>
        <td></td>

        <?php
        for ($j = 1; $j < 11; $j++){
        ?>

        <td><?php echo $j; ?></td>

        <?php
        }
        ?>

    </tr>
</table>
<br />
<input type='submit' name='' value='Player 1 Turn' />

Bu daha kod gibi yapar, ama o satır aralığı aşağı daha fazla bulunuyor. Eğer for ifadeleri oldukça çok şey var gibi büyük bir yardımcı, ama gelmez etiketi Eğer daha iyi bir şans html hataları bulmak gerekir vurgulayarak ya da benzeri bir şey ile bir kodlama programı kullanıyorsanız az ve sizin php daha okunabilir hale yardımcı olabilir.

yankılamamasını html kodu da html tek veya çift tırnak kullanımı boşaltır.