DtrollMC

Tic Tac Toe

Oct 12th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title> PHP Tic Tac Toe</title>
  4. </head>
  5. <body>
  6. <?php
  7. //Variables
  8. //Boxes numbers in book-like order
  9.  
  10. //The user input
  11. $value = $_POST['value'];
  12.  
  13. //If the user hasn't hit submit, the boxes will be empty
  14. if(!isset($_POST['submit'])){
  15.     $box1 = '-';
  16.     $box2 = '-';
  17.     $box3 = '-';
  18.     $box4 = '-';
  19.     $box5 = '-';
  20.     $box6 = '-';
  21.     $box7 = '-';
  22.     $box8 = '-';
  23.     $box9 = '-';
  24. }else{
  25.     $box1 = $_POST['box1'];
  26.     $box2 = $_POST['box2'];
  27.     $box3 = $_POST['box3'];
  28.     $box4 = $_POST['box4'];
  29.     $box5 = $_POST['box5'];
  30.     $box6 = $_POST['box6'];
  31.     $box7 = $_POST['box7'];
  32.     $box8 = $_POST['box8'];
  33.     $box9 = $_POST['box9'];
  34.    
  35. }
  36.  
  37. //Read user input and act accordingly
  38. if(isset($_POST['submit'])){
  39.     if($value == 'box1'){
  40.         $box1 = 'X';
  41.     }
  42.     if($value == 'box2'){
  43.         $box2 = 'X';
  44.     }
  45.     if($value == 'box3'){
  46.         $box3 = 'X';
  47.     }
  48.     if($value == 'box4'){
  49.         $box4 = 'X';
  50.     }
  51.     if($value == 'box5'){
  52.         $box5 = 'X';
  53.     }
  54.     if($value == 'box6'){
  55.         $box6 = 'X';
  56.     }
  57.     if($value == 'box7'){
  58.         $box7 = 'X';
  59.     }
  60.     if($value == 'box8'){
  61.         $box8 = 'X';
  62.     }
  63.     if($value == 'box9'){
  64.         $box9 = 'X';
  65.     }
  66. }
  67.  
  68. echo '<table border="1px">';
  69. echo '<tr>';
  70. echo '<td>'.$box1.'</td>';
  71. echo '<td>'.$box2.'</td>';
  72. echo '<td>'.$box3.'</td>';
  73. echo '</tr>';
  74. echo '<tr>';
  75. echo '<td>'.$box4.'</td>';
  76. echo '<td>'.$box5.'</td>';
  77. echo '<td>'.$box6.'</td>';
  78. echo '</tr>';
  79. echo '<tr>';
  80. echo '<td>'.$box7.'</td>';
  81. echo '<td>'.$box8.'</td>';
  82. echo '<td>'.$box9.'</td>';
  83. echo '</tr>';
  84. echo '</table>';
  85. ?>
  86. <br>
  87. <form method='POST' action='<?php echo $_SERVER['PHP_SELF'];?>'>
  88.     <input type='text' name='value'>
  89.     <input type='hidden' value= "<?php echo $turn;?>" name='turn'>
  90.     <input type='hidden' value= "<?php echo $box1;?>" name='box1'>
  91.     <input type='hidden' value= "<?php echo $box2;?>" name='box2'>
  92.     <input type='hidden' value= "<?php echo $box3;?>" name='box3'>
  93.     <input type='hidden' value= "<?php echo $box4;?>" name='box4'>
  94.     <input type='hidden' value= "<?php echo $box5;?>" name='box5'>
  95.     <input type='hidden' value= "<?php echo $box6;?>" name='box6'>
  96.     <input type='hidden' value= "<?php echo $box7;?>" name='box7'>
  97.     <input type='hidden' value= "<?php echo $box8;?>" name='box8'>
  98.     <input type='hidden' value= "<?php echo $box9;?>" name='box9'>
  99.     <input type="submit" value="Turn" name="submit">
  100. </form>
  101. </body>
  102. </html>
Advertisement
Add Comment
Please, Sign In to add comment